Subject: calendar vs. NIS
To: tech-userlevel <tech-userlevel@netbsd.org>
From: Joerg Klemenz <joerg@gmx.net>
List: tech-userlevel
Date: 11/05/2002 09:55:34
hi
i like to use calendar(1) to remind me of things. Unfortunatly it does
not work well with NIS, as the man page of getpwent already suggests.
It mails you the same calendar many times.
I managed to put together a quick fix to stop the reminder service
from spamming me. The problem is that MAX_UID is far to large
(2.147.483.647?) for any "simple" data structure.
So I assume that no UID is larger than 32767. What is the right way to
handle this?
Use something other that getpwent? What?
TIA
--- calendar.c_org Tue Nov 5 09:32:36 2002
+++ calendar.c Tue Nov 5 09:32:36 2002
@@ -75,7 +75,7 @@
#endif
static unsigned short lookahead = 1, weekend = 2;
-static char *fname = "calendar", *datestr = NULL;
+static char *fname = ".calendar", *datestr = NULL; /* cal -> .cal (jk) */
static struct passwd *pw;
static int doall;
static char path[MAXPATHLEN + 1];
@@ -130,6 +130,10 @@
int ch;
const char *caldir;
+ uid_t uid_tmp[32767]; /* probably wrong */
+ uid_t i; /* MAX_UID is too big for an array... */
+ for ( i=0; i<32767; i++) uid_tmp[i]=0;
+
while ((ch = getopt(argc, argv, "-ad:f:l:w:")) != -1)
switch (ch) {
case '-': /* backward contemptible */
@@ -165,11 +169,18 @@
settime();
if (doall) {
while ((pw = getpwent()) != NULL) {
+
+ /* avoid double mail when using NIS w/ nsswitch
+ see man getpwent (jk) */
+
+ if (uid_tmp[pw->pw_uid]!=1) {
(void)setegid(pw->pw_gid);
(void)seteuid(pw->pw_uid);
if (!chdir(pw->pw_dir))
cal();
(void)seteuid(0);
+ }
+ uid_tmp[pw->pw_uid]=1;
}
} else if ((caldir = getenv("CALENDAR_DIR")) != NULL) {
if(!chdir(caldir))
joerg <joerg@gmx.net>