]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/zotnet/bboards/getbbent.c
1 /* getbbent.c - subroutines for accessing the BBoards file */
3 static char ident
[] = "@(#)$Id: getbbent.c,v 1.14 1992/12/15 00:20:22 jromine Exp $";
10 #include "../h/strings.h"
11 #include <sys/types.h>
27 #endif /* not MMDFONLY */
35 #define NCOLON 9 /* currently 10 fields per entry */
42 #define ARCHIVE "archive"
43 #define CNTFILE ".cnt"
44 #define DSTFILE ".dist"
45 #define MAPFILE ".map"
49 static int BBuid
= -1;
51 static unsigned int BBflags
= SB_NULL
;
53 static char BBName
[BUFSIZ
] = BBOARDS
;
54 static char BBDir
[BUFSIZ
] = "";
55 static char BBData
[BUFSIZ
] = "";
57 static FILE *BBfile
= NULL
;
60 static struct bboard BB
;
61 static struct bboard
*bb
= &BB
;
63 static int BBload
= 1;
65 static char BBFile
[BUFSIZ
];
66 static char BBArchive
[BUFSIZ
];
67 static char BBInfo
[BUFSIZ
];
68 static char BBMap
[BUFSIZ
];
69 static char *BBAkas
[MaxBBAka
];
70 static char *BBLeaders
[MaxBBLdr
];
71 static char *BBDists
[MaxBBDist
];
72 static char BBAddr
[BUFSIZ
];
73 static char BBRequest
[BUFSIZ
];
74 static char BBDate
[BUFSIZ
];
75 static char BBErrors
[BUFSIZ
];
81 static char *bbskip (), *getcpy ();
83 #if defined(__STDC__) && defined(SVR4)
86 #if defined(UNISTD) || defined(_AIX)
90 char *crypt (), *getpass ();
91 struct group
*getgrnam ();
93 struct passwd
*getpwnam (), *getpwuid ();
95 #endif /* !__STDC__ */
97 static int setpwaux(), getbbitem(), bblose();
106 int setbbfile (file
, f
)
111 return setbbinfo (BBOARDS
, file
, f
);
113 (void) strcpy (BBData
, file
);
123 int setbbinfo (user
, file
, f
)
128 register struct passwd
*pw
;
130 if ((pw
= getpwnam (user
)) == NULL
) {
131 (void) sprintf (BBErrors
, "unknown user: %s", user
);
135 return setpwinfo (pw
, file
, f
);
139 int setpwinfo (pw
, file
, f
)
140 register struct passwd
*pw
;
144 if (!setpwaux (pw
, file
))
155 static int setbbaux (name
, file
)
159 register struct passwd
*pw
;
161 if ((pw
= getpwnam (name
)) == NULL
) {
162 (void) sprintf (BBErrors
, "unknown user: %s", name
);
166 return setpwaux (pw
, file
);
170 static int setpwaux (pw
, file
)
171 register struct passwd
*pw
;
174 (void) strcpy (BBName
, pw
-> pw_name
);
175 BBuid
= pw
-> pw_uid
;
176 (void) strcpy (BBDir
, pw
-> pw_dir
);
177 (void) sprintf (BBData
, "%s/%s",
178 *file
!= '/' ? BBDir
: "",
179 *file
!= '/' ? file
: file
+ 1);
191 if (BBfile
== NULL
) {
192 if (BBuid
== -1 && !setbbaux (BBOARDS
, BBDB
))
195 if ((BBfile
= fopen (BBData
, "r")) == NULL
) {
196 (void) sprintf (BBErrors
, "unable to open: %s", BBData
);
204 return (BBfile
!= NULL
);
209 if (BBfile
!= NULL
&& !(BBflags
& SB_STAY
)) {
210 (void) fclose (BBfile
);
221 if (BBfile
== NULL
) {
222 if (BBuid
== -1 && !setbbaux (BBOARDS
, BBDB
))
225 if (stat (BBData
, &st
) == NOTOK
) {
226 (void) sprintf (BBErrors
, "unable to stat: %s", BBData
);
231 if (fstat (fileno (BBfile
), &st
) == NOTOK
) {
232 (void) sprintf (BBErrors
, "unable to fstat: %s", BBData
);
236 return ((long) st
.st_mtime
);
241 struct bboard
*getbbent () {
249 static char line
[BUFSIZ
];
251 if (BBfile
== NULL
&& !setbbent (SB_NULL
))
255 if ((p
= fgets (line
, sizeof line
, BBfile
)) == NULL
)
258 for (q
= p
, count
= 0; *q
!= 0 && *q
!= NEWLINE
; q
++)
262 if (count
!= NCOLON
) {
264 if (q
= index (p
, NEWLINE
))
266 ll_log (logptr
, LLOGTMP
, "bad entry in %s: %s", BBData
, p
);
267 #endif /* MMDFONLY */
272 p
= q
= bbskip (p
, COLON
);
273 p
= bb
-> bb_file
= bbskip (p
, COLON
);
274 bb
-> bb_archive
= bb
-> bb_info
= bb
-> bb_map
= "";
275 p
= bb
-> bb_passwd
= bbskip (p
, COLON
);
276 p
= r
= bbskip (p
, COLON
);
277 p
= bb
-> bb_addr
= bbskip (p
, COLON
);
278 p
= bb
-> bb_request
= bbskip (p
, COLON
);
279 p
= bb
-> bb_relay
= bbskip (p
, COLON
);
280 p
= d
= bbskip (p
, COLON
);
281 p
= f
= bbskip (p
, COLON
);
282 (void) bbskip (p
, NEWLINE
);
284 s
= bb
-> bb_aka
= BBAkas
;
287 q
= bbskip (q
, COMMA
);
291 s
= bb
-> bb_leader
= BBLeaders
;
293 if (!(BBflags
& SB_FAST
)) {
301 r
= bbskip (r
, COMMA
);
306 s
= bb
-> bb_dist
= BBDists
;
309 d
= bbskip (d
, COMMA
);
314 (void) sscanf (f
, "%o", &bb
-> bb_flags
);
316 bb
-> bb_flags
= BB_NULL
;
317 bb
-> bb_count
= bb
-> bb_maxima
= 0;
318 bb
-> bb_date
= NULL
;
319 bb
-> bb_next
= bb
-> bb_link
= bb
-> bb_chain
= NULL
;
323 * Only do a BBread on bboards that the user has expressed an
324 * interest in, if we were called by bbc.
327 register char **ap
, *cp
;
333 for (bbp
= 0; cp
= bbs
[bbp
]; bbp
++) {
334 if (!strcmp(bb
->bb_name
, cp
)) {
338 for (ap
= bb
->bb_aka
; *ap
; ap
++)
339 if (!strcmp(*ap
, cp
)) {
356 struct bboard
*getbbnam (name
)
359 register struct bboard
*b
= NULL
;
361 if (!setbbent (SB_NULL
))
364 while ((b
= getbbent ()) && strcmp (name
, b
-> bb_name
))
376 struct bboard
*getbbaka (aka
)
380 register struct bboard
*b
= NULL
;
382 if (!setbbent (SB_NULL
))
385 while ((b
= getbbent ()) != NULL
)
386 for (ap
= b
-> bb_aka
; *ap
; ap
++)
387 if (strcmp (aka
, *ap
) == 0)
401 static void BBread ()
409 static char line
[BUFSIZ
];
410 register FILE * info
;
412 if (BBflags
& SB_FAST
)
415 p
= index (bb
-> bb_request
, '@');
416 r
= index (bb
-> bb_addr
, '@');
419 if (*bb
-> bb_request
== '-')
420 if (p
== NULL
&& r
&& *r
== '@')
421 (void) sprintf (BBRequest
, "%s%s%s",
422 bb
-> bb_name
, bb
-> bb_request
, r
);
424 (void) sprintf (BBRequest
, "%s%s",
425 bb
-> bb_name
, bb
-> bb_request
);
427 if (p
== NULL
&& r
&& *r
== '@' && *bb
-> bb_request
)
428 (void) sprintf (BBRequest
, "%s%s", bb
-> bb_request
, r
);
431 bb
-> bb_request
= BBRequest
;
433 if (*bb
-> bb_request
== 0)
434 bb
-> bb_request
= *bb
-> bb_addr
? bb
-> bb_addr
435 : bb
-> bb_leader
[0];
437 if (*bb
-> bb_addr
== '@') {
438 (void) sprintf (BBAddr
, "%s%s", bb
-> bb_name
, bb
-> bb_addr
);
439 bb
-> bb_addr
= BBAddr
;
442 if (*bb
-> bb_addr
== 0)
443 bb
-> bb_addr
= bb
-> bb_name
;
445 if (*bb
-> bb_file
== 0)
447 if (*bb
-> bb_file
!= '/') {
448 (void) sprintf (BBFile
, "%s/%s", BBDir
, bb
-> bb_file
);
449 bb
-> bb_file
= BBFile
;
452 if ((cp
= rindex (bb
-> bb_file
, '/')) == NULL
|| *++cp
== 0)
453 (void) strcpy (prf
, ""), cp
= bb
-> bb_file
;
455 (void) sprintf (prf
, "%.*s", cp
- bb
-> bb_file
, bb
-> bb_file
);
456 if ((dp
= index (cp
, '.')) == NULL
)
457 dp
= cp
+ strlen (cp
);
459 (void) sprintf (BBArchive
, "%s%s/%s", prf
, ARCHIVE
, cp
);
460 bb
-> bb_archive
= BBArchive
;
461 (void) sprintf (BBInfo
, "%s.%.*s%s", prf
, dp
- cp
, cp
, CNTFILE
);
462 bb
-> bb_info
= BBInfo
;
463 (void) sprintf (BBMap
, "%s.%.*s%s", prf
, dp
- cp
, cp
, MAPFILE
);
464 bb
-> bb_map
= BBMap
;
466 if ((info
= fopen (bb
-> bb_info
, "r")) == NULL
)
469 if (fgets (line
, sizeof line
, info
) && (i
= atoi (line
)) > 0)
470 bb
-> bb_maxima
= (unsigned) i
;
471 if (!feof (info
) && fgets (line
, sizeof line
, info
)) {
472 (void) strcpy (BBDate
, line
);
473 if (cp
= index (BBDate
, NEWLINE
))
475 bb
-> bb_date
= BBDate
;
478 (void) fclose (info
);
484 register struct bboard
*b
;
491 static char username
[10] = "";
492 register struct passwd
*pw
;
493 register struct group
*gr
;
497 if (BBuid
== -1 && !setbbaux (BBOARDS
, BBDB
))
500 if (username
[0] == 0) {
501 if ((pw
= getpwuid (uid
= getuid ())) == NULL
)
504 (void) strcpy (username
, pw
-> pw_name
);
513 if ((gr
= getgrnam (++p
)) == NULL
)
515 if (gid
== gr
-> gr_gid
)
519 if (strcmp (username
, p
) == 0)
523 if (strcmp (username
, p
) == 0)
532 register struct bboard
*b
;
537 if (*b
-> bb_passwd
== 0)
540 if (strcmp (b
-> bb_passwd
,
541 crypt (getpass ("Password: "), b
-> bb_passwd
)) == 0)
544 fprintf (stderr
, "Sorry\n");
550 struct bboard
*getbbcpy (bp
)
551 register struct bboard
*bp
;
555 register struct bboard
*b
;
560 b
= (struct bboard
*) malloc ((unsigned) sizeof *b
);
564 b
-> bb_name
= getcpy (bp
-> bb_name
);
565 b
-> bb_file
= getcpy (bp
-> bb_file
);
566 b
-> bb_archive
= getcpy (bp
-> bb_archive
);
567 b
-> bb_info
= getcpy (bp
-> bb_info
);
568 b
-> bb_map
= getcpy (bp
-> bb_map
);
569 b
-> bb_passwd
= getcpy (bp
-> bb_passwd
);
570 b
-> bb_flags
= bp
-> bb_flags
;
571 b
-> bb_count
= bp
-> bb_count
;
572 b
-> bb_maxima
= bp
-> bb_maxima
;
573 b
-> bb_date
= getcpy (bp
-> bb_date
);
574 b
-> bb_addr
= getcpy (bp
-> bb_addr
);
575 b
-> bb_request
= getcpy (bp
-> bb_request
);
576 b
-> bb_relay
= getcpy (bp
-> bb_relay
);
578 for (p
= bp
-> bb_aka
; *p
; p
++)
581 q
= (char **) calloc ((unsigned) (p
- bp
-> bb_aka
+ 1), sizeof *q
);
584 for (p
= bp
-> bb_aka
; *p
; *q
++ = getcpy (*p
++))
588 for (p
= bp
-> bb_leader
; *p
; p
++)
591 q
= (char **) calloc ((unsigned) (p
- bp
-> bb_leader
+ 1), sizeof *q
);
594 for (p
= bp
-> bb_leader
; *p
; *q
++ = getcpy (*p
++))
598 for (p
= bp
-> bb_dist
; *p
; p
++)
601 q
= (char **) calloc ((unsigned) (p
- bp
-> bb_dist
+ 1), sizeof *q
);
604 for (p
= bp
-> bb_dist
; *p
; *q
++ = getcpy (*p
++))
608 b
-> bb_next
= bp
-> bb_next
;
609 b
-> bb_link
= bp
-> bb_link
;
610 b
-> bb_chain
= bp
-> bb_chain
;
617 int getbbdist (bb
, action
)
618 register struct bboard
*bb
;
619 register int (*action
) ();
625 for (dp
= bb
-> bb_dist
; *dp
; dp
++)
626 if (result
= getbbitem (bb
, *dp
, action
))
633 return (BBErrors
[0] ? BBErrors
: NULL
);
638 static int getbbitem (bb
, item
, action
)
639 register struct bboard
*bb
;
641 register int (*action
) ();
663 if ((cp
= rindex (bb
-> bb_file
, '/')) == NULL
|| *++cp
== 0)
664 (void) strcpy (prf
, ""), cp
= bb
-> bb_file
;
666 (void) sprintf (prf
, "%.*s", cp
- bb
-> bb_file
, bb
-> bb_file
);
667 if ((dp
= index (cp
, '.')) == NULL
)
668 dp
= cp
+ strlen (cp
);
669 (void) sprintf (file
, "%s.%.*s%s", prf
, dp
- cp
, cp
, DSTFILE
);
674 (void) sprintf (file
, "%s/%s", BBDir
, item
);
679 if ((fp
= fopen (hp
, "r")) == NULL
)
680 return bblose ("unable to read file %s", hp
);
681 while (fgets (buffer
, sizeof buffer
, fp
)) {
682 if (np
= index (buffer
, '\n'))
684 if (result
= getbbitem (bb
, buffer
, action
)) {
686 (void) bblose ("error with file %s, item %s", hp
, buffer
);
694 if (hp
= rindex (item
, '@')) {
696 (void) strcpy (mbox
, item
);
697 (void) strcpy (host
, hp
);
701 (void) sprintf (mbox
, "%s%s", DISTADR
, bb
-> bb_name
);
702 (void) strcpy (host
, item
);
704 if (result
= (*action
) (mbox
, host
))
705 (void) bblose ("action (%s, %s) returned 0%o", mbox
, host
, result
);
714 static int bblose (fmt
, a
, b
, c
)
720 if (BBErrors
[0] == 0)
721 (void) sprintf (BBErrors
, fmt
, a
, b
, c
);
728 void make_lower (s1
, s2
)
732 if (s1
== NULL
|| s2
== NULL
)
736 *s1
++ = isupper (*s2
) ? tolower (*s2
) : *s2
;
742 static char *bbskip (p
, c
)
749 while (*p
&& *p
!= c
)
758 static char *getcpy (s
)
766 if (p
= malloc ((unsigned) (strlen (s
) + 1)))
767 (void) strcpy (p
, s
);