]>
diplodocus.org Git - nmh/blob - uip/conflict.c
3 * conflict.c -- check for conflicts in mail system
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
12 #include <h/aliasbr.h>
19 * maximum number of directories that can
20 * be specified using -search switch.
25 * Add space for group names, 100 at a time
29 static struct swit switches
[] = {
33 { "search directory", 0 },
41 static char *mail
= NULL
;
42 static char *dirs
[NDIRS
];
43 static FILE *out
= NULL
;
45 extern struct aka
*akahead
;
46 extern struct home
*homehead
;
51 void alias_files (int, char **);
52 void pwd_names (void);
53 void grp_names (void);
54 void grp_members (void);
56 void maildrops (void);
63 main (int argc
, char **argv
)
66 char *cp
, **argp
, **arguments
;
67 char buf
[BUFSIZ
], *akv
[50];
70 setlocale(LC_ALL
, "");
72 invo_name
= r1bindex (argv
[0], '/');
74 /* foil search of user profile/context */
75 if (context_foil (NULL
) == -1)
79 arguments
= getarguments (invo_name
, argc
, argv
, 0);
82 while ((cp
= *argp
++)) {
84 switch (smatch (++cp
, switches
)) {
86 ambigsw (cp
, switches
);
89 adios (NULL
, "-%s unknown", cp
);
92 snprintf (buf
, sizeof(buf
), "%s [switches] [aliasfiles ...]",
94 print_help (buf
, switches
, 0);
97 print_version(invo_name
);
101 if (!(cp
= *argp
++) || *cp
== '-')
102 adios (NULL
, "missing argument to %s", argp
[-2]);
104 adios (NULL
, "mail to one address only");
110 if (!(cp
= *argp
++) || *cp
== '-')
111 adios (NULL
, "missing argument to %s", argp
[-2]);
113 adios (NULL
, "more than %d directories", NDIRS
);
122 akv
[akp
++] = AliasFile
;
129 alias_files (akp
, akv
);
146 alias_files (int akp
, char **akv
)
150 for (i
= 0; i
< akp
; i
++)
151 if ((err
= alias (akv
[i
])) != AK_OK
) {
153 fprintf (out
, "aliasing error in %s - %s\n", akv
[i
], akerror (err
));
157 fprintf (out
, "alias file %s is ok\n", akv
[i
]);
165 register struct home
*hm
, *lm
;
167 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
168 for (lm
= hm
->h_next
; lm
; lm
= lm
->h_next
)
169 if (strcmp (hm
->h_name
, lm
->h_name
) == 0) {
171 fprintf (out
, "duplicate user %s(uid=%d)\n",
172 lm
->h_name
, (int) lm
->h_uid
);
176 if (!hit
&& out
&& !mail
)
177 fprintf (out
, "no duplicate users\n");
184 int numgroups
, maxgroups
;
189 /* allocate space NGRPS at a time */
192 grps
= (char **) mh_xmalloc((size_t) (maxgroups
* sizeof(*grps
)));
195 while ((gr
= getgrent ())) {
196 for (i
= 0; i
< numgroups
; i
++)
197 if (!strcmp (grps
[i
], gr
->gr_name
)) {
199 fprintf (out
, "duplicate group %s(gid=%d)\n",
200 gr
->gr_name
, (int) gr
->gr_gid
);
204 if (i
>= numgroups
) {
205 if (numgroups
>= maxgroups
) {
207 grps
= (char **) mh_xrealloc(grps
,
208 (size_t) (maxgroups
* sizeof(*grps
)));
210 grps
[numgroups
++] = getcpy (gr
->gr_name
);
215 for (i
= 0; i
< numgroups
; i
++)
219 if (!hit
&& out
&& !mail
)
220 fprintf (out
, "no duplicate groups\n");
227 register int hit
= 0;
228 register char **cp
, **dp
;
229 register struct group
*gr
;
230 register struct home
*hm
;
233 while ((gr
= getgrent ())) {
234 for (cp
= gr
->gr_mem
; *cp
; cp
++) {
235 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
236 if (!strcmp (*cp
, hm
->h_name
))
240 fprintf (out
, "group %s(gid=%d) has unknown member %s\n",
241 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
247 for (dp
= cp
+ 1; *dp
; dp
++)
248 if (strcmp (*cp
, *dp
) == 0) {
250 fprintf (out
, "group %s(gid=%d) has duplicate member %s\n",
251 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
258 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
259 if (hm
->h_ngrps
> NGROUPS_MAX
) {
261 fprintf (out
, "user %s is a member of %d groups (max %d)\n",
262 hm
->h_name
, hm
->h_ngrps
, NGROUPS_MAX
);
266 if (!hit
&& out
&& !mail
)
267 fprintf (out
, "all group members accounted for\n");
273 { /* -DRAND not implemented at most places */
274 register int hit
= 0;
275 register struct home
*hm
;
277 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
278 if (getgrgid (hm
->h_gid
) == NULL
) {
280 fprintf (out
, "user %s(uid=%d) has unknown group-id %d\n",
281 hm
->h_name
, (int) hm
->h_uid
, (int) hm
->h_gid
);
285 if (!hit
&& out
&& !mail
)
286 fprintf (out
, "all group-id users accounted for\n");
295 if (mmdfldir
&& *mmdfldir
)
297 if (uucpldir
&& *uucpldir
)
299 for (i
= 0; dirs
[i
]; i
++)
307 register int hit
= 0;
308 register struct dirent
*dp
;
309 register DIR *dd
= opendir (drop
);
313 fprintf (out
, "unable to open maildrop area %s\n", drop
);
317 while ((dp
= readdir (dd
)))
318 if (dp
->d_name
[0] != '.' && !check (dp
->d_name
)) {
321 "there is a maildrop for the unknown user %s in %s\n",
327 if (!hit
&& out
&& !mail
)
328 fprintf (out
, "all maildrops accounted for in %s\n", drop
);
335 register struct home
*hm
;
337 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
338 if (!strcmp (s
, hm
->h_name
))
352 if (pipe (pd
) == NOTOK
)
353 adios ("pipe", "unable to");
357 adios ("fork", "unable to");
365 if ((fd
= open ("/dev/null", O_WRONLY
)) != NOTOK
)
370 execlp (mailproc
, r1bindex (mailproc
, '/'),
371 mail
, "-subject", invo_name
, NULL
);
372 adios (mailproc
, "unable to exec ");
376 out
= fdopen (pd
[1], "w");
377 fprintf (out
, "%s: the following is suspicious\n\n",
385 * UCI specific stuff for conflict
388 /* taken from <grpldr.h> */
390 #define GLDRS "/admin/etc/GroupLeaders"
397 int setglent (), endglent ();
398 struct grpldr
*getglent (), *getglnam ();
401 /* taken from the getglent() routines */
405 static FILE *glp
= NULL
;
406 static char line
[BUFSIZ
+1];
407 static struct grpldr grpldr
;
408 static char *gl_ldr
[MAXGLS
+ 1];
413 glp
= fopen (GLDRS
, "r");
417 return (glp
!= NULL
);
430 struct grpldr
*getglent () {
434 if (glp
== NULL
&& !setglent ())
436 if ((cp
= fgets (line
, BUFSIZ
, glp
)) == NULL
)
440 grpldr
.gl_ldr
= q
= gl_ldr
;
443 while (*cp
&& !isspace (*cp
))
445 while (*cp
&& isspace (*cp
))
449 if (q
< gl_ldr
+ MAXGLS
)
459 struct grpldr
*getglnam (name
)
462 register struct grpldr
*gl
= NULL
;
465 while (gl
= getglent ())
466 if (strcmp (name
, gl
->gl_name
) == 0)
477 register struct grpldr
*gl
;
481 while (gl
= getglent ()) {
482 if (getgrnam (gl
->gl_name
) == NULL
) {
484 fprintf (out
, "unknown group %s in group leaders file\n",
488 for (gp
= 0; gldrs
[gp
]; gp
++)
489 if (strcmp (gldrs
[gp
], gl
->gl_name
) == 0) {
491 fprintf (out
, "duplicate group %s in group leaders file\n",
496 if (gldrs
[gp
] == NULL
)
498 gldrs
[gp
++] = getcpy (gl
->gl_name
);
503 fprintf (out
, "more than %d groups in group leaders file%s\n",
504 " (time to recompile)", NGRPS
- 1);
510 for (gp
= 0; gldrs
[gp
]; gp
++)
513 if (!hit
&& out
&& !mail
)
514 fprintf (out
, "all groups in group leaders file accounted for\n");
519 register int hit
= 0;
522 register struct grpldr
*gl
;
525 while (gl
= getglent ())
526 for (cp
= gl
->gl_ldr
; *cp
; cp
++) {
529 fprintf (out
, "group %s has unknown leader %s\n",
534 for (dp
= cp
+ 1; *dp
; dp
++)
535 if (strcmp (*cp
, *dp
) == 0) {
537 fprintf (out
, "group %s had duplicate leader %s\n",
544 if (!hit
&& out
&& !mail
)
545 fprintf (out
, "all group leaders accounted for\n");