9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.12.11.22.12.13; author jromine; state Exp;
19 date 92.12.10.23.57.12; author jromine; state Exp;
24 date 92.11.24.18.45.37; author jromine; state Exp;
29 date 92.05.19.21.14.18; author jromine; state Exp;
34 date 92.02.03.17.58.04; author jromine; state Exp;
39 date 92.02.03.16.37.17; author jromine; state Exp;
44 date 92.01.31.22.30.56; author jromine; state Exp;
49 date 92.01.31.22.30.44; author jromine; state Exp;
54 date 90.04.09.10.11.57; author sources; state Exp;
59 date 90.04.05.15.04.11; author sources; state Exp;
64 date 90.02.08.14.11.33; author sources; state Exp;
69 date 90.02.06.13.39.12; author sources; state Exp;
74 date 90.02.06.13.38.24; author sources; state Exp;
88 @/* getbbent.c - subroutines for accessing the BBoards file */
90 static char ident[] = "@@(#)$Id: getbbent.c,v 1.13 1992/12/11 22:12:13 jromine Exp jromine $";
97 #include "../h/strings.h"
98 #include <sys/types.h>
103 #endif /* MMDFONLY */
108 #include <sys/stat.h>
114 #endif /* not MMDFONLY */
119 #define MaxBBDist 100
122 #define NCOLON 9 /* currently 10 fields per entry */
129 #define ARCHIVE "archive"
130 #define CNTFILE ".cnt"
131 #define DSTFILE ".dist"
132 #define MAPFILE ".map"
136 static int BBuid = -1;
138 static unsigned int BBflags = SB_NULL;
140 static char BBName[BUFSIZ] = BBOARDS;
141 static char BBDir[BUFSIZ] = "";
142 static char BBData[BUFSIZ] = "";
144 static FILE *BBfile = NULL;
147 static struct bboard BB;
148 static struct bboard *bb = &BB;
150 static int BBload = 1;
152 static char BBFile[BUFSIZ];
153 static char BBArchive[BUFSIZ];
154 static char BBInfo[BUFSIZ];
155 static char BBMap[BUFSIZ];
156 static char *BBAkas[MaxBBAka];
157 static char *BBLeaders[MaxBBLdr];
158 static char *BBDists[MaxBBDist];
159 static char BBAddr[BUFSIZ];
160 static char BBRequest[BUFSIZ];
161 static char BBDate[BUFSIZ];
162 static char BBErrors[BUFSIZ];
166 #endif /* MMDFONLY */
168 static char *bbskip (), *getcpy ();
170 #if defined(__STDC__) && defined(SVR4)
173 #if defined(UNISTD) || defined(_AIX)
177 char *crypt (), *getpass ();
178 struct group *getgrnam ();
180 struct passwd *getpwnam (), *getpwuid ();
182 #endif /* !__STDC__ */
184 static int setpwaux(), getbbitem(), bblose();
185 static void BBread();
193 int setbbfile (file, f)
198 return setbbinfo (BBOARDS, file, f);
200 (void) strcpy (BBData, file);
210 int setbbinfo (user, file, f)
215 register struct passwd *pw;
217 if ((pw = getpwnam (user)) == NULL) {
218 (void) sprintf (BBErrors, "unknown user: %s", user);
222 return setpwinfo (pw, file, f);
226 int setpwinfo (pw, file, f)
227 register struct passwd *pw;
231 if (!setpwaux (pw, file))
242 static int setbbaux (name, file)
246 register struct passwd *pw;
248 if ((pw = getpwnam (name)) == NULL) {
249 (void) sprintf (BBErrors, "unknown user: %s", name);
253 return setpwaux (pw, file);
257 static int setpwaux (pw, file)
258 register struct passwd *pw;
261 (void) strcpy (BBName, pw -> pw_name);
262 BBuid = pw -> pw_uid;
263 (void) strcpy (BBDir, pw -> pw_dir);
264 (void) sprintf (BBData, "%s/%s",
265 *file != '/' ? BBDir : "",
266 *file != '/' ? file : file + 1);
278 if (BBfile == NULL) {
279 if (BBuid == -1 && !setbbaux (BBOARDS, BBDB))
282 if ((BBfile = fopen (BBData, "r")) == NULL) {
283 (void) sprintf (BBErrors, "unable to open: %s", BBData);
291 return (BBfile != NULL);
296 if (BBfile != NULL && !(BBflags & SB_STAY)) {
297 (void) fclose (BBfile);
308 if (BBfile == NULL) {
309 if (BBuid == -1 && !setbbaux (BBOARDS, BBDB))
312 if (stat (BBData, &st) == NOTOK) {
313 (void) sprintf (BBErrors, "unable to stat: %s", BBData);
318 if (fstat (fileno (BBfile), &st) == NOTOK) {
319 (void) sprintf (BBErrors, "unable to fstat: %s", BBData);
323 return ((long) st.st_mtime);
328 struct bboard *getbbent () {
336 static char line[BUFSIZ];
338 if (BBfile == NULL && !setbbent (SB_NULL))
342 if ((p = fgets (line, sizeof line, BBfile)) == NULL)
345 for (q = p, count = 0; *q != 0 && *q != NEWLINE; q++)
349 if (count != NCOLON) {
351 if (q = index (p, NEWLINE))
353 ll_log (logptr, LLOGTMP, "bad entry in %s: %s", BBData, p);
354 #endif /* MMDFONLY */
359 p = q = bbskip (p, COLON);
360 p = bb -> bb_file = bbskip (p, COLON);
361 bb -> bb_archive = bb -> bb_info = bb -> bb_map = "";
362 p = bb -> bb_passwd = bbskip (p, COLON);
363 p = r = bbskip (p, COLON);
364 p = bb -> bb_addr = bbskip (p, COLON);
365 p = bb -> bb_request = bbskip (p, COLON);
366 p = bb -> bb_relay = bbskip (p, COLON);
367 p = d = bbskip (p, COLON);
368 p = f = bbskip (p, COLON);
369 (void) bbskip (p, NEWLINE);
371 s = bb -> bb_aka = BBAkas;
374 q = bbskip (q, COMMA);
378 s = bb -> bb_leader = BBLeaders;
380 if (!(BBflags & SB_FAST)) {
388 r = bbskip (r, COMMA);
393 s = bb -> bb_dist = BBDists;
396 d = bbskip (d, COMMA);
401 (void) sscanf (f, "%o", &bb -> bb_flags);
403 bb -> bb_flags = BB_NULL;
404 bb -> bb_count = bb -> bb_maxima = 0;
405 bb -> bb_date = NULL;
406 bb -> bb_next = bb -> bb_link = bb -> bb_chain = NULL;
410 * Only do a BBread on bboards that the user has expressed an
411 * interest in, if we were called by bbc.
414 register char **ap, *cp;
420 for (bbp = 0; cp = bbs[bbp]; bbp++) {
421 if (!strcmp(bb->bb_name, cp)) {
425 for (ap = bb->bb_aka; *ap; ap++)
426 if (!strcmp(*ap, cp)) {
443 struct bboard *getbbnam (name)
446 register struct bboard *b = NULL;
448 if (!setbbent (SB_NULL))
451 while ((b = getbbent ()) && strcmp (name, b -> bb_name))
463 struct bboard *getbbaka (aka)
467 register struct bboard *b = NULL;
469 if (!setbbent (SB_NULL))
472 while ((b = getbbent ()) != NULL)
473 for (ap = b -> bb_aka; *ap; ap++)
474 if (strcmp (aka, *ap) == 0)
488 static void BBread ()
496 static char line[BUFSIZ];
497 register FILE * info;
499 if (BBflags & SB_FAST)
502 p = index (bb -> bb_request, '@@');
503 r = index (bb -> bb_addr, '@@');
506 if (*bb -> bb_request == '-')
507 if (p == NULL && r && *r == '@@')
508 (void) sprintf (BBRequest, "%s%s%s",
509 bb -> bb_name, bb -> bb_request, r);
511 (void) sprintf (BBRequest, "%s%s",
512 bb -> bb_name, bb -> bb_request);
514 if (p == NULL && r && *r == '@@' && *bb -> bb_request)
515 (void) sprintf (BBRequest, "%s%s", bb -> bb_request, r);
518 bb -> bb_request = BBRequest;
520 if (*bb -> bb_request == 0)
521 bb -> bb_request = *bb -> bb_addr ? bb -> bb_addr
522 : bb -> bb_leader[0];
524 if (*bb -> bb_addr == '@@') {
525 (void) sprintf (BBAddr, "%s%s", bb -> bb_name, bb -> bb_addr);
526 bb -> bb_addr = BBAddr;
529 if (*bb -> bb_addr == 0)
530 bb -> bb_addr = bb -> bb_name;
532 if (*bb -> bb_file == 0)
534 if (*bb -> bb_file != '/') {
535 (void) sprintf (BBFile, "%s/%s", BBDir, bb -> bb_file);
536 bb -> bb_file = BBFile;
539 if ((cp = rindex (bb -> bb_file, '/')) == NULL || *++cp == 0)
540 (void) strcpy (prf, ""), cp = bb -> bb_file;
542 (void) sprintf (prf, "%.*s", cp - bb -> bb_file, bb -> bb_file);
543 if ((dp = index (cp, '.')) == NULL)
544 dp = cp + strlen (cp);
546 (void) sprintf (BBArchive, "%s%s/%s", prf, ARCHIVE, cp);
547 bb -> bb_archive = BBArchive;
548 (void) sprintf (BBInfo, "%s.%.*s%s", prf, dp - cp, cp, CNTFILE);
549 bb -> bb_info = BBInfo;
550 (void) sprintf (BBMap, "%s.%.*s%s", prf, dp - cp, cp, MAPFILE);
551 bb -> bb_map = BBMap;
553 if ((info = fopen (bb -> bb_info, "r")) == NULL)
556 if (fgets (line, sizeof line, info) && (i = atoi (line)) > 0)
557 bb -> bb_maxima = (unsigned) i;
558 if (!feof (info) && fgets (line, sizeof line, info)) {
559 (void) strcpy (BBDate, line);
560 if (cp = index (BBDate, NEWLINE))
562 bb -> bb_date = BBDate;
565 (void) fclose (info);
571 register struct bboard *b;
578 static char username[10] = "";
579 register struct passwd *pw;
580 register struct group *gr;
584 if (BBuid == -1 && !setbbaux (BBOARDS, BBDB))
587 if (username[0] == 0) {
588 if ((pw = getpwuid (uid = getuid ())) == NULL)
591 (void) strcpy (username, pw -> pw_name);
600 if ((gr = getgrnam (++p)) == NULL)
602 if (gid == gr -> gr_gid)
606 if (strcmp (username, p) == 0)
610 if (strcmp (username, p) == 0)
619 register struct bboard *b;
624 if (*b -> bb_passwd == 0)
627 if (strcmp (b -> bb_passwd,
628 crypt (getpass ("Password: "), b -> bb_passwd)) == 0)
631 fprintf (stderr, "Sorry\n");
637 struct bboard *getbbcpy (bp)
638 register struct bboard *bp;
642 register struct bboard *b;
647 b = (struct bboard *) malloc ((unsigned) sizeof *b);
651 b -> bb_name = getcpy (bp -> bb_name);
652 b -> bb_file = getcpy (bp -> bb_file);
653 b -> bb_archive = getcpy (bp -> bb_archive);
654 b -> bb_info = getcpy (bp -> bb_info);
655 b -> bb_map = getcpy (bp -> bb_map);
656 b -> bb_passwd = getcpy (bp -> bb_passwd);
657 b -> bb_flags = bp -> bb_flags;
658 b -> bb_count = bp -> bb_count;
659 b -> bb_maxima = bp -> bb_maxima;
660 b -> bb_date = getcpy (bp -> bb_date);
661 b -> bb_addr = getcpy (bp -> bb_addr);
662 b -> bb_request = getcpy (bp -> bb_request);
663 b -> bb_relay = getcpy (bp -> bb_relay);
665 for (p = bp -> bb_aka; *p; p++)
668 q = (char **) calloc ((unsigned) (p - bp -> bb_aka + 1), sizeof *q);
671 for (p = bp -> bb_aka; *p; *q++ = getcpy (*p++))
675 for (p = bp -> bb_leader; *p; p++)
678 q = (char **) calloc ((unsigned) (p - bp -> bb_leader + 1), sizeof *q);
681 for (p = bp -> bb_leader; *p; *q++ = getcpy (*p++))
685 for (p = bp -> bb_dist; *p; p++)
688 q = (char **) calloc ((unsigned) (p - bp -> bb_dist + 1), sizeof *q);
691 for (p = bp -> bb_dist; *p; *q++ = getcpy (*p++))
695 b -> bb_next = bp -> bb_next;
696 b -> bb_link = bp -> bb_link;
697 b -> bb_chain = bp -> bb_chain;
704 int getbbdist (bb, action)
705 register struct bboard *bb;
706 register int (*action) ();
712 for (dp = bb -> bb_dist; *dp; dp++)
713 if (result = getbbitem (bb, *dp, action))
720 return (BBErrors[0] ? BBErrors : NULL);
725 static int getbbitem (bb, item, action)
726 register struct bboard *bb;
728 register int (*action) ();
750 if ((cp = rindex (bb -> bb_file, '/')) == NULL || *++cp == 0)
751 (void) strcpy (prf, ""), cp = bb -> bb_file;
753 (void) sprintf (prf, "%.*s", cp - bb -> bb_file, bb -> bb_file);
754 if ((dp = index (cp, '.')) == NULL)
755 dp = cp + strlen (cp);
756 (void) sprintf (file, "%s.%.*s%s", prf, dp - cp, cp, DSTFILE);
761 (void) sprintf (file, "%s/%s", BBDir, item);
766 if ((fp = fopen (hp, "r")) == NULL)
767 return bblose ("unable to read file %s", hp);
768 while (fgets (buffer, sizeof buffer, fp)) {
769 if (np = index (buffer, '\n'))
771 if (result = getbbitem (bb, buffer, action)) {
773 (void) bblose ("error with file %s, item %s", hp, buffer);
781 if (hp = rindex (item, '@@')) {
783 (void) strcpy (mbox, item);
784 (void) strcpy (host, hp);
788 (void) sprintf (mbox, "%s%s", DISTADR, bb -> bb_name);
789 (void) strcpy (host, item);
791 if (result = (*action) (mbox, host))
792 (void) bblose ("action (%s, %s) returned 0%o", mbox, host, result);
801 static int bblose (fmt, a, b, c)
807 if (BBErrors[0] == 0)
808 (void) sprintf (BBErrors, fmt, a, b, c);
815 void make_lower (s1, s2)
819 if (s1 == NULL || s2 == NULL)
823 *s1++ = isupper (*s2) ? tolower (*s2) : *s2;
829 static char *bbskip (p, c)
836 while (*p && *p != c)
845 static char *getcpy (s)
853 if (p = malloc ((unsigned) (strlen (s) + 1)))
854 (void) strcpy (p, s);
867 static char ident[] = "@@(#)$Id: getbbent.c,v 1.12 1992/12/10 23:57:12 jromine Exp jromine $";
889 @add #include <crypt.h>
894 static char ident[] = "@@(#)$Id: getbbent.c,v 1.11 1992/11/24 18:45:37 jromine Exp jromine $";
897 static int setpwaux(), BBread(), getbbitem(), bblose();
900 static int BBread () {
911 static char ident[] = "@@(#)$Id: getbbent.c,v 1.10 1992/05/19 21:14:18 jromine Exp jromine $";
923 static char ident[] = "@@(#)$Id: getbbent.c,v 1.9 1992/02/03 17:58:04 jromine Exp jromine $";
940 static char ident[] = "@@(#)$Id: getbbent.c,v 1.8 1992/02/03 16:37:17 jromine Exp jromine $";
953 static char ident[] = "@@(#)$Id: getbbent.c,v 1.7 1992/01/31 22:30:56 jromine Exp jromine $";
966 static char ident[] = "@@(#)$Id: getbbent.c,v 1.6 1992/01/31 22:30:44 jromine Exp jromine $";
979 static char ident[] = "@@(#)$Id: getbbent.c,v 1.5 1990/04/09 10:11:57 sources Exp jromine $";
982 for (q = p, count = 0; *q != NULL && *q != NEWLINE; q++)
1003 BBRequest[0] = NULL;
1006 if (*bb -> bb_request == NULL)
1009 if (*bb -> bb_addr == NULL)
1012 if (*bb -> bb_file == NULL)
1015 if ((cp = rindex (bb -> bb_file, '/')) == NULL || *++cp == NULL)
1021 if (username[0] == NULL) {
1024 if (*b -> bb_passwd == NULL)
1031 if ((cp = rindex (bb -> bb_file, '/')) == NULL || *++cp == NULL)
1040 if (BBErrors[0] == NULL)
1057 static char ident[] = "@@(#)$Id: getbbent.c,v 1.4 90/04/05 15:04:11 sources Exp Locker: sources $";
1071 static char ident[] = "@@(#)$Id:$";
1074 if (!(BBflags & SB_FAST))
1112 char *bbskip (), *getcpy ();