]>
diplodocus.org Git - nmh/blob - uip/conflict.c
3 * conflict.c -- check for conflicts in mail system
10 #include <h/aliasbr.h>
11 #include <zotnet/mts/mts.h>
16 * maximum number of directories that can
17 * be specified using -search switch.
22 * Add space for group names, 100 at a time
26 static struct swit switches
[] = {
30 { "search directory", 0 },
38 static char *mail
= NULL
;
39 static char *dirs
[NDIRS
];
40 static FILE *out
= NULL
;
42 extern struct aka
*akahead
;
43 extern struct home
*homehead
;
48 void alias_files (int, char **);
49 void pwd_names (void);
50 void grp_names (void);
51 void grp_members (void);
53 void maildrops (void);
60 main (int argc
, char **argv
)
63 char *cp
, **argp
, **arguments
;
64 char buf
[BUFSIZ
], *akv
[50];
67 setlocale(LC_ALL
, "");
69 invo_name
= r1bindex (argv
[0], '/');
71 /* foil search of user profile/context */
72 if (context_foil (NULL
) == -1)
76 arguments
= getarguments (invo_name
, argc
, argv
, 0);
79 while ((cp
= *argp
++)) {
81 switch (smatch (++cp
, switches
)) {
83 ambigsw (cp
, switches
);
86 adios (NULL
, "-%s unknown", cp
);
89 snprintf (buf
, sizeof(buf
), "%s [switches] [aliasfiles ...]",
91 print_help (buf
, switches
, 0);
94 print_version(invo_name
);
98 if (!(cp
= *argp
++) || *cp
== '-')
99 adios (NULL
, "missing argument to %s", argp
[-2]);
101 adios (NULL
, "mail to one address only");
107 if (!(cp
= *argp
++) || *cp
== '-')
108 adios (NULL
, "missing argument to %s", argp
[-2]);
110 adios (NULL
, "more than %d directories", NDIRS
);
119 akv
[akp
++] = AliasFile
;
126 alias_files (akp
, akv
);
142 alias_files (int akp
, char **akv
)
146 for (i
= 0; i
< akp
; i
++)
147 if ((err
= alias (akv
[i
])) != AK_OK
) {
149 fprintf (out
, "aliasing error in %s - %s\n", akv
[i
], akerror (err
));
153 fprintf (out
, "alias file %s is ok\n", akv
[i
]);
161 register struct home
*hm
, *lm
;
163 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
164 for (lm
= hm
->h_next
; lm
; lm
= lm
->h_next
)
165 if (strcmp (hm
->h_name
, lm
->h_name
) == 0) {
167 fprintf (out
, "duplicate user %s(uid=%d)\n",
168 lm
->h_name
, (int) lm
->h_uid
);
172 if (!hit
&& out
&& !mail
)
173 fprintf (out
, "no duplicate users\n");
180 int numgroups
, maxgroups
;
185 /* allocate space NGRPS at a time */
188 if (!(grps
= (char **) malloc((size_t) (maxgroups
* sizeof(*grps
)))))
189 adios (NULL
, "unable to allocate group name storage");
192 while ((gr
= getgrent ())) {
193 for (i
= 0; i
< numgroups
; i
++)
194 if (!strcmp (grps
[i
], gr
->gr_name
)) {
196 fprintf (out
, "duplicate group %s(gid=%d)\n",
197 gr
->gr_name
, (int) gr
->gr_gid
);
201 if (i
>= numgroups
) {
202 if (numgroups
>= maxgroups
) {
204 if (!(grps
= (char **) realloc(grps
,
205 (size_t) (maxgroups
* sizeof(*grps
)))))
206 adios (NULL
, "unable to reallocate group name storage");
208 grps
[numgroups
++] = getcpy (gr
->gr_name
);
213 for (i
= 0; i
< numgroups
; i
++)
217 if (!hit
&& out
&& !mail
)
218 fprintf (out
, "no duplicate groups\n");
225 register int hit
= 0;
226 register char **cp
, **dp
;
227 register struct group
*gr
;
228 register struct home
*hm
;
231 while ((gr
= getgrent ())) {
232 for (cp
= gr
->gr_mem
; *cp
; cp
++) {
233 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
234 if (!strcmp (*cp
, hm
->h_name
))
238 fprintf (out
, "group %s(gid=%d) has unknown member %s\n",
239 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
245 for (dp
= cp
+ 1; *dp
; dp
++)
246 if (strcmp (*cp
, *dp
) == 0) {
248 fprintf (out
, "group %s(gid=%d) has duplicate member %s\n",
249 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
256 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
257 if (hm
->h_ngrps
> NGROUPS_MAX
) {
259 fprintf (out
, "user %s is a member of %d groups (max %d)\n",
260 hm
->h_name
, hm
->h_ngrps
, NGROUPS_MAX
);
264 if (!hit
&& out
&& !mail
)
265 fprintf (out
, "all group members accounted for\n");
271 { /* -DRAND not implemented at most places */
272 register int hit
= 0;
273 register struct home
*hm
;
275 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
276 if (getgrgid (hm
->h_gid
) == NULL
) {
278 fprintf (out
, "user %s(uid=%d) has unknown group-id %d\n",
279 hm
->h_name
, (int) hm
->h_uid
, (int) hm
->h_gid
);
283 if (!hit
&& out
&& !mail
)
284 fprintf (out
, "all group-id users accounted for\n");
293 if (mmdfldir
&& *mmdfldir
)
295 if (uucpldir
&& *uucpldir
)
297 for (i
= 0; dirs
[i
]; i
++)
305 register int hit
= 0;
306 register struct dirent
*dp
;
307 register DIR *dd
= opendir (drop
);
311 fprintf (out
, "unable to open maildrop area %s\n", drop
);
315 while ((dp
= readdir (dd
)))
316 if (dp
->d_name
[0] != '.' && !check (dp
->d_name
)) {
319 "there is a maildrop for the unknown user %s in %s\n",
325 if (!hit
&& out
&& !mail
)
326 fprintf (out
, "all maildrops accounted for in %s\n", drop
);
333 register struct home
*hm
;
335 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
336 if (!strcmp (s
, hm
->h_name
))
350 if (pipe (pd
) == NOTOK
)
351 adios ("pipe", "unable to");
355 adios ("fork", "unable to");
363 if ((fd
= open ("/dev/null", O_WRONLY
)) != NOTOK
)
368 execlp (mailproc
, r1bindex (mailproc
, '/'),
369 mail
, "-subject", invo_name
, NULL
);
370 adios (mailproc
, "unable to exec ");
374 out
= fdopen (pd
[1], "w");
375 fprintf (out
, "%s: the following is suspicious\n\n",
383 * UCI specific stuff for conflict
386 /* taken from <grpldr.h> */
388 #define GLDRS "/admin/etc/GroupLeaders"
395 int setglent (), endglent ();
396 struct grpldr
*getglent (), *getglnam ();
399 /* taken from the getglent() routines */
403 static FILE *glp
= NULL
;
404 static char line
[BUFSIZ
+1];
405 static struct grpldr grpldr
;
406 static char *gl_ldr
[MAXGLS
+ 1];
411 glp
= fopen (GLDRS
, "r");
415 return (glp
!= NULL
);
428 struct grpldr
*getglent () {
432 if (glp
== NULL
&& !setglent ())
434 if ((cp
= fgets (line
, BUFSIZ
, glp
)) == NULL
)
438 grpldr
.gl_ldr
= q
= gl_ldr
;
441 while (*cp
&& !isspace (*cp
))
443 while (*cp
&& isspace (*cp
))
447 if (q
< gl_ldr
+ MAXGLS
)
457 struct grpldr
*getglnam (name
)
460 register struct grpldr
*gl
= NULL
;
463 while (gl
= getglent ())
464 if (strcmp (name
, gl
->gl_name
) == 0)
475 register struct grpldr
*gl
;
479 while (gl
= getglent ()) {
480 if (getgrnam (gl
->gl_name
) == NULL
) {
482 fprintf (out
, "unknown group %s in group leaders file\n",
486 for (gp
= 0; gldrs
[gp
]; gp
++)
487 if (strcmp (gldrs
[gp
], gl
->gl_name
) == 0) {
489 fprintf (out
, "duplicate group %s in group leaders file\n",
494 if (gldrs
[gp
] == NULL
)
496 gldrs
[gp
++] = getcpy (gl
->gl_name
);
501 fprintf (out
, "more than %d groups in group leaders file%s\n",
502 " (time to recompile)", NGRPS
- 1);
508 for (gp
= 0; gldrs
[gp
]; gp
++)
511 if (!hit
&& out
&& !mail
)
512 fprintf (out
, "all groups in group leaders file accounted for\n");
517 register int hit
= 0;
520 register struct grpldr
*gl
;
523 while (gl
= getglent ())
524 for (cp
= gl
->gl_ldr
; *cp
; cp
++) {
527 fprintf (out
, "group %s has unknown leader %s\n",
532 for (dp
= cp
+ 1; *dp
; dp
++)
533 if (strcmp (*cp
, *dp
) == 0) {
535 fprintf (out
, "group %s had duplicate leader %s\n",
542 if (!hit
&& out
&& !mail
)
543 fprintf (out
, "all group leaders accounted for\n");