]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/support/pop/mmdfII/pop/getbbent.c
1 /* getbbent.c - subroutines for accessing the BBoards file */
7 #include "../h/strings.h"
32 #define NCOLON 9 /* currently 10 fields per entry */
39 #define ARCHIVE "archive"
40 #define CNTFILE ".cnt"
41 #define DSTFILE ".dist"
42 #define MAPFILE ".map"
46 static int BBuid
= -1;
48 static unsigned int BBflags
= SB_NULL
;
50 static char BBName
[BUFSIZ
] = BBOARDS
;
51 static char BBDir
[BUFSIZ
] = "";
52 static char BBData
[BUFSIZ
] = "";
54 static FILE *BBfile
= NULL
;
57 static struct bboard BB
;
58 static struct bboard
*bb
= &BB
;
60 static int BBload
= 1;
62 static char BBFile
[BUFSIZ
];
63 static char BBArchive
[BUFSIZ
];
64 static char BBInfo
[BUFSIZ
];
65 static char BBMap
[BUFSIZ
];
66 static char *BBAkas
[MaxBBAka
];
67 static char *BBLeaders
[MaxBBLdr
];
68 static char *BBDists
[MaxBBDist
];
69 static char BBAddr
[BUFSIZ
];
70 static char BBRequest
[BUFSIZ
];
71 static char BBDate
[BUFSIZ
];
72 static char BBErrors
[BUFSIZ
];
78 char *bbskip (), *getcpy ();
80 char *crypt (), *getpass ();
81 struct group
*getgrnam ();
82 struct passwd
*getpwnam (), *getpwuid ();
86 int setbbfile (file
, f
)
91 return setbbinfo (BBOARDS
, file
, f
);
93 (void) strcpy (BBData
, file
);
103 int setbbinfo (user
, file
, f
)
108 register struct passwd
*pw
;
110 if ((pw
= getpwnam (user
)) == NULL
) {
111 (void) sprintf (BBErrors
, "unknown user: %s", user
);
115 return setpwinfo (pw
, file
, f
);
119 int setpwinfo (pw
, file
, f
)
120 register struct passwd
*pw
;
124 if (!setpwaux (pw
, file
))
135 static int setbbaux (name
, file
)
139 register struct passwd
*pw
;
141 if ((pw
= getpwnam (name
)) == NULL
) {
142 (void) sprintf (BBErrors
, "unknown user: %s", name
);
146 return setpwaux (pw
, file
);
150 static int setpwaux (pw
, file
)
151 register struct passwd
*pw
;
154 (void) strcpy (BBName
, pw
-> pw_name
);
155 BBuid
= pw
-> pw_uid
;
156 (void) strcpy (BBDir
, pw
-> pw_dir
);
157 (void) sprintf (BBData
, "%s/%s",
158 *file
!= '/' ? BBDir
: "",
159 *file
!= '/' ? file
: file
+ 1);
171 if (BBfile
== NULL
) {
172 if (BBuid
== -1 && !setbbaux (BBOARDS
, BBDB
))
175 if ((BBfile
= fopen (BBData
, "r")) == NULL
) {
176 (void) sprintf (BBErrors
, "unable to open: %s", BBData
);
184 return (BBfile
!= NULL
);
189 if (BBfile
!= NULL
&& !(BBflags
& SB_STAY
)) {
190 (void) fclose (BBfile
);
201 if (BBfile
== NULL
) {
202 if (BBuid
== -1 && !setbbaux (BBOARDS
, BBDB
))
205 if (stat (BBData
, &st
) == NOTOK
) {
206 (void) sprintf (BBErrors
, "unable to stat: %s", BBData
);
211 if (fstat (fileno (BBfile
), &st
) == NOTOK
) {
212 (void) sprintf (BBErrors
, "unable to fstat: %s", BBData
);
216 return ((long) st
.st_mtime
);
221 struct bboard
*getbbent () {
229 static char line
[BUFSIZ
];
231 if (BBfile
== NULL
&& !setbbent (SB_NULL
))
235 if ((p
= fgets (line
, sizeof line
, BBfile
)) == NULL
)
238 for (q
= p
, count
= 0; *q
!= NULL
&& *q
!= NEWLINE
; q
++)
242 if (count
!= NCOLON
) {
244 if (q
= index (p
, NEWLINE
))
246 ll_log (logptr
, LLOGTMP
, "bad entry in %s: %s", BBData
, p
);
252 p
= q
= bbskip (p
, COLON
);
253 p
= bb
-> bb_file
= bbskip (p
, COLON
);
254 bb
-> bb_archive
= bb
-> bb_info
= bb
-> bb_map
= "";
255 p
= bb
-> bb_passwd
= bbskip (p
, COLON
);
256 p
= r
= bbskip (p
, COLON
);
257 p
= bb
-> bb_addr
= bbskip (p
, COLON
);
258 p
= bb
-> bb_request
= bbskip (p
, COLON
);
259 p
= bb
-> bb_relay
= bbskip (p
, COLON
);
260 p
= d
= bbskip (p
, COLON
);
261 p
= f
= bbskip (p
, COLON
);
262 (void) bbskip (p
, NEWLINE
);
264 s
= bb
-> bb_aka
= BBAkas
;
267 q
= bbskip (q
, COMMA
);
271 s
= bb
-> bb_leader
= BBLeaders
;
273 if (!(BBflags
& SB_FAST
))
279 r
= bbskip (r
, COMMA
);
283 s
= bb
-> bb_dist
= BBDists
;
286 d
= bbskip (d
, COMMA
);
291 (void) sscanf (f
, "%o", &bb
-> bb_flags
);
293 bb
-> bb_flags
= BB_NULL
;
294 bb
-> bb_count
= bb
-> bb_maxima
= 0;
295 bb
-> bb_date
= NULL
;
296 bb
-> bb_next
= bb
-> bb_link
= bb
-> bb_chain
= NULL
;
306 struct bboard
*getbbnam (name
)
309 register struct bboard
*b
= NULL
;
311 if (!setbbent (SB_NULL
))
314 while ((b
= getbbent ()) && strcmp (name
, b
-> bb_name
))
326 struct bboard
*getbbaka (aka
)
330 register struct bboard
*b
= NULL
;
332 if (!setbbent (SB_NULL
))
335 while ((b
= getbbent ()) != NULL
)
336 for (ap
= b
-> bb_aka
; *ap
; ap
++)
337 if (strcmp (aka
, *ap
) == 0)
351 static int BBread () {
358 static char line
[BUFSIZ
];
359 register FILE * info
;
361 if (BBflags
& SB_FAST
)
364 p
= index (bb
-> bb_request
, '@');
365 r
= index (bb
-> bb_addr
, '@');
368 if (*bb
-> bb_request
== '-')
369 if (p
== NULL
&& r
&& *r
== '@')
370 (void) sprintf (BBRequest
, "%s%s%s",
371 bb
-> bb_name
, bb
-> bb_request
, r
);
373 (void) sprintf (BBRequest
, "%s%s",
374 bb
-> bb_name
, bb
-> bb_request
);
376 if (p
== NULL
&& r
&& *r
== '@' && *bb
-> bb_request
)
377 (void) sprintf (BBRequest
, "%s%s", bb
-> bb_request
, r
);
380 bb
-> bb_request
= BBRequest
;
382 if (*bb
-> bb_request
== NULL
)
383 bb
-> bb_request
= *bb
-> bb_addr
? bb
-> bb_addr
384 : bb
-> bb_leader
[0];
386 if (*bb
-> bb_addr
== '@') {
387 (void) sprintf (BBAddr
, "%s%s", bb
-> bb_name
, bb
-> bb_addr
);
388 bb
-> bb_addr
= BBAddr
;
391 if (*bb
-> bb_addr
== NULL
)
392 bb
-> bb_addr
= bb
-> bb_name
;
394 if (*bb
-> bb_file
== NULL
)
396 if (*bb
-> bb_file
!= '/') {
397 (void) sprintf (BBFile
, "%s/%s", BBDir
, bb
-> bb_file
);
398 bb
-> bb_file
= BBFile
;
401 if ((cp
= rindex (bb
-> bb_file
, '/')) == NULL
|| *++cp
== NULL
)
402 (void) strcpy (prf
, ""), cp
= bb
-> bb_file
;
404 (void) sprintf (prf
, "%.*s", cp
- bb
-> bb_file
, bb
-> bb_file
);
405 if ((dp
= index (cp
, '.')) == NULL
)
406 dp
= cp
+ strlen (cp
);
408 (void) sprintf (BBArchive
, "%s%s/%s", prf
, ARCHIVE
, cp
);
409 bb
-> bb_archive
= BBArchive
;
410 (void) sprintf (BBInfo
, "%s.%.*s%s", prf
, dp
- cp
, cp
, CNTFILE
);
411 bb
-> bb_info
= BBInfo
;
412 (void) sprintf (BBMap
, "%s.%.*s%s", prf
, dp
- cp
, cp
, MAPFILE
);
413 bb
-> bb_map
= BBMap
;
415 if ((info
= fopen (bb
-> bb_info
, "r")) == NULL
)
418 if (fgets (line
, sizeof line
, info
) && (i
= atoi (line
)) > 0)
419 bb
-> bb_maxima
= (unsigned) i
;
420 if (!feof (info
) && fgets (line
, sizeof line
, info
)) {
421 (void) strcpy (BBDate
, line
);
422 if (cp
= index (BBDate
, NEWLINE
))
424 bb
-> bb_date
= BBDate
;
427 (void) fclose (info
);
433 register struct bboard
*b
;
440 static char username
[10] = "";
441 register struct passwd
*pw
;
442 register struct group
*gr
;
446 if (BBuid
== -1 && !setbbaux (BBOARDS
, BBDB
))
449 if (username
[0] == NULL
) {
450 if ((pw
= getpwuid (uid
= getuid ())) == NULL
)
453 (void) strcpy (username
, pw
-> pw_name
);
462 if ((gr
= getgrnam (++p
)) == NULL
)
464 if (gid
== gr
-> gr_gid
)
468 if (strcmp (username
, p
) == 0)
472 if (strcmp (username
, p
) == 0)
481 register struct bboard
*b
;
486 if (*b
-> bb_passwd
== NULL
)
489 if (strcmp (b
-> bb_passwd
,
490 crypt (getpass ("Password: "), b
-> bb_passwd
)) == 0)
493 fprintf (stderr
, "Sorry\n");
499 struct bboard
*getbbcpy (bp
)
500 register struct bboard
*bp
;
504 register struct bboard
*b
;
509 b
= (struct bboard
*) malloc ((unsigned) sizeof *b
);
513 b
-> bb_name
= getcpy (bp
-> bb_name
);
514 b
-> bb_file
= getcpy (bp
-> bb_file
);
515 b
-> bb_archive
= getcpy (bp
-> bb_archive
);
516 b
-> bb_info
= getcpy (bp
-> bb_info
);
517 b
-> bb_map
= getcpy (bp
-> bb_map
);
518 b
-> bb_passwd
= getcpy (bp
-> bb_passwd
);
519 b
-> bb_flags
= bp
-> bb_flags
;
520 b
-> bb_count
= bp
-> bb_count
;
521 b
-> bb_maxima
= bp
-> bb_maxima
;
522 b
-> bb_date
= getcpy (bp
-> bb_date
);
523 b
-> bb_addr
= getcpy (bp
-> bb_addr
);
524 b
-> bb_request
= getcpy (bp
-> bb_request
);
525 b
-> bb_relay
= getcpy (bp
-> bb_relay
);
527 for (p
= bp
-> bb_aka
; *p
; p
++)
530 q
= (char **) calloc ((unsigned) (p
- bp
-> bb_aka
+ 1), sizeof *q
);
533 for (p
= bp
-> bb_aka
; *p
; *q
++ = getcpy (*p
++))
537 for (p
= bp
-> bb_leader
; *p
; p
++)
540 q
= (char **) calloc ((unsigned) (p
- bp
-> bb_leader
+ 1), sizeof *q
);
543 for (p
= bp
-> bb_leader
; *p
; *q
++ = getcpy (*p
++))
547 for (p
= bp
-> bb_dist
; *p
; p
++)
550 q
= (char **) calloc ((unsigned) (p
- bp
-> bb_dist
+ 1), sizeof *q
);
553 for (p
= bp
-> bb_dist
; *p
; *q
++ = getcpy (*p
++))
557 b
-> bb_next
= bp
-> bb_next
;
558 b
-> bb_link
= bp
-> bb_link
;
559 b
-> bb_chain
= bp
-> bb_chain
;
566 int getbbdist (bb
, action
)
567 register struct bboard
*bb
;
568 register int (*action
) ();
574 for (dp
= bb
-> bb_dist
; *dp
; dp
++)
575 if (result
= getbbitem (bb
, *dp
, action
))
582 return (BBErrors
[0] ? BBErrors
: NULL
);
587 static int getbbitem (bb
, item
, action
)
588 register struct bboard
*bb
;
590 register int (*action
) ();
612 if ((cp
= rindex (bb
-> bb_file
, '/')) == NULL
|| *++cp
== NULL
)
613 (void) strcpy (prf
, ""), cp
= bb
-> bb_file
;
615 (void) sprintf (prf
, "%.*s", cp
- bb
-> bb_file
, bb
-> bb_file
);
616 if ((dp
= index (cp
, '.')) == NULL
)
617 dp
= cp
+ strlen (cp
);
618 (void) sprintf (file
, "%s.%.*s%s", prf
, dp
- cp
, cp
, DSTFILE
);
623 (void) sprintf (file
, "%s/%s", BBDir
, item
);
628 if ((fp
= fopen (hp
, "r")) == NULL
)
629 return bblose ("unable to read file %s", hp
);
630 while (fgets (buffer
, sizeof buffer
, fp
)) {
631 if (np
= index (buffer
, '\n'))
633 if (result
= getbbitem (bb
, buffer
, action
)) {
635 (void) bblose ("error with file %s, item %s", hp
, buffer
);
643 if (hp
= rindex (item
, '@')) {
645 (void) strcpy (mbox
, item
);
646 (void) strcpy (host
, hp
);
650 (void) sprintf (mbox
, "%s%s", DISTADR
, bb
-> bb_name
);
651 (void) strcpy (host
, item
);
653 if (result
= (*action
) (mbox
, host
))
654 (void) bblose ("action (%s, %s) returned 0%o", mbox
, host
, result
);
663 static int bblose (fmt
, a
, b
, c
)
669 if (BBErrors
[0] == NULL
)
670 (void) sprintf (BBErrors
, fmt
, a
, b
, c
);
677 void make_lower (s1
, s2
)
681 if (s1
== NULL
|| s2
== NULL
)
685 *s1
++ = isupper (*s2
) ? tolower (*s2
) : *s2
;
691 static char *bbskip (p
, c
)
698 while (*p
&& *p
!= c
)
707 static char *getcpy (s
)
715 if (p
= malloc ((unsigned) (strlen (s
) + 1)))
716 (void) strcpy (p
, s
);