]>
diplodocus.org Git - nmh/blob - uip/conflict.c
3 * conflict.c -- check for conflicts in mail system
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
14 #include <h/aliasbr.h>
20 * maximum number of directories that can
21 * be specified using -search switch.
26 * Add space for group names, 100 at a time
30 static struct swit switches
[] = {
34 { "search directory", 0 },
42 static char *mail
= NULL
;
43 static char *dirs
[NDIRS
];
44 static FILE *out
= NULL
;
46 extern struct aka
*akahead
;
47 extern struct home
*homehead
;
52 void alias_files (int, char **);
53 void pwd_names (void);
54 void grp_names (void);
55 void grp_members (void);
57 void maildrops (void);
64 main (int argc
, char **argv
)
67 char *cp
, **argp
, **arguments
;
68 char buf
[BUFSIZ
], *akv
[50];
71 setlocale(LC_ALL
, "");
73 invo_name
= r1bindex (argv
[0], '/');
75 /* foil search of user profile/context */
76 if (context_foil (NULL
) == -1)
80 arguments
= getarguments (invo_name
, argc
, argv
, 0);
83 while ((cp
= *argp
++)) {
85 switch (smatch (++cp
, switches
)) {
87 ambigsw (cp
, switches
);
90 adios (NULL
, "-%s unknown", cp
);
93 snprintf (buf
, sizeof(buf
), "%s [switches] [aliasfiles ...]",
95 print_help (buf
, switches
, 0);
98 print_version(invo_name
);
102 if (!(cp
= *argp
++) || *cp
== '-')
103 adios (NULL
, "missing argument to %s", argp
[-2]);
105 adios (NULL
, "mail to one address only");
111 if (!(cp
= *argp
++) || *cp
== '-')
112 adios (NULL
, "missing argument to %s", argp
[-2]);
114 adios (NULL
, "more than %d directories", NDIRS
);
123 akv
[akp
++] = AliasFile
;
130 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 if (!(grps
= (char **) malloc((size_t) (maxgroups
* sizeof(*grps
)))))
193 adios (NULL
, "unable to allocate group name storage");
196 while ((gr
= getgrent ())) {
197 for (i
= 0; i
< numgroups
; i
++)
198 if (!strcmp (grps
[i
], gr
->gr_name
)) {
200 fprintf (out
, "duplicate group %s(gid=%d)\n",
201 gr
->gr_name
, (int) gr
->gr_gid
);
205 if (i
>= numgroups
) {
206 if (numgroups
>= maxgroups
) {
208 if (!(grps
= (char **) realloc(grps
,
209 (size_t) (maxgroups
* sizeof(*grps
)))))
210 adios (NULL
, "unable to reallocate group name storage");
212 grps
[numgroups
++] = getcpy (gr
->gr_name
);
217 for (i
= 0; i
< numgroups
; i
++)
221 if (!hit
&& out
&& !mail
)
222 fprintf (out
, "no duplicate groups\n");
229 register int hit
= 0;
230 register char **cp
, **dp
;
231 register struct group
*gr
;
232 register struct home
*hm
;
235 while ((gr
= getgrent ())) {
236 for (cp
= gr
->gr_mem
; *cp
; cp
++) {
237 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
238 if (!strcmp (*cp
, hm
->h_name
))
242 fprintf (out
, "group %s(gid=%d) has unknown member %s\n",
243 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
249 for (dp
= cp
+ 1; *dp
; dp
++)
250 if (strcmp (*cp
, *dp
) == 0) {
252 fprintf (out
, "group %s(gid=%d) has duplicate member %s\n",
253 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
260 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
261 if (hm
->h_ngrps
> NGROUPS_MAX
) {
263 fprintf (out
, "user %s is a member of %d groups (max %d)\n",
264 hm
->h_name
, hm
->h_ngrps
, NGROUPS_MAX
);
268 if (!hit
&& out
&& !mail
)
269 fprintf (out
, "all group members accounted for\n");
275 { /* -DRAND not implemented at most places */
276 register int hit
= 0;
277 register struct home
*hm
;
279 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
280 if (getgrgid (hm
->h_gid
) == NULL
) {
282 fprintf (out
, "user %s(uid=%d) has unknown group-id %d\n",
283 hm
->h_name
, (int) hm
->h_uid
, (int) hm
->h_gid
);
287 if (!hit
&& out
&& !mail
)
288 fprintf (out
, "all group-id users accounted for\n");
297 if (mmdfldir
&& *mmdfldir
)
299 if (uucpldir
&& *uucpldir
)
301 for (i
= 0; dirs
[i
]; i
++)
309 register int hit
= 0;
310 register struct dirent
*dp
;
311 register DIR *dd
= opendir (drop
);
315 fprintf (out
, "unable to open maildrop area %s\n", drop
);
319 while ((dp
= readdir (dd
)))
320 if (dp
->d_name
[0] != '.' && !check (dp
->d_name
)) {
323 "there is a maildrop for the unknown user %s in %s\n",
329 if (!hit
&& out
&& !mail
)
330 fprintf (out
, "all maildrops accounted for in %s\n", drop
);
337 register struct home
*hm
;
339 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
340 if (!strcmp (s
, hm
->h_name
))
354 if (pipe (pd
) == NOTOK
)
355 adios ("pipe", "unable to");
359 adios ("fork", "unable to");
367 if ((fd
= open ("/dev/null", O_WRONLY
)) != NOTOK
)
372 execlp (mailproc
, r1bindex (mailproc
, '/'),
373 mail
, "-subject", invo_name
, NULL
);
374 adios (mailproc
, "unable to exec ");
378 out
= fdopen (pd
[1], "w");
379 fprintf (out
, "%s: the following is suspicious\n\n",
387 * UCI specific stuff for conflict
390 /* taken from <grpldr.h> */
392 #define GLDRS "/admin/etc/GroupLeaders"
399 int setglent (), endglent ();
400 struct grpldr
*getglent (), *getglnam ();
403 /* taken from the getglent() routines */
407 static FILE *glp
= NULL
;
408 static char line
[BUFSIZ
+1];
409 static struct grpldr grpldr
;
410 static char *gl_ldr
[MAXGLS
+ 1];
415 glp
= fopen (GLDRS
, "r");
419 return (glp
!= NULL
);
432 struct grpldr
*getglent () {
436 if (glp
== NULL
&& !setglent ())
438 if ((cp
= fgets (line
, BUFSIZ
, glp
)) == NULL
)
442 grpldr
.gl_ldr
= q
= gl_ldr
;
445 while (*cp
&& !isspace (*cp
))
447 while (*cp
&& isspace (*cp
))
451 if (q
< gl_ldr
+ MAXGLS
)
461 struct grpldr
*getglnam (name
)
464 register struct grpldr
*gl
= NULL
;
467 while (gl
= getglent ())
468 if (strcmp (name
, gl
->gl_name
) == 0)
479 register struct grpldr
*gl
;
483 while (gl
= getglent ()) {
484 if (getgrnam (gl
->gl_name
) == NULL
) {
486 fprintf (out
, "unknown group %s in group leaders file\n",
490 for (gp
= 0; gldrs
[gp
]; gp
++)
491 if (strcmp (gldrs
[gp
], gl
->gl_name
) == 0) {
493 fprintf (out
, "duplicate group %s in group leaders file\n",
498 if (gldrs
[gp
] == NULL
)
500 gldrs
[gp
++] = getcpy (gl
->gl_name
);
505 fprintf (out
, "more than %d groups in group leaders file%s\n",
506 " (time to recompile)", NGRPS
- 1);
512 for (gp
= 0; gldrs
[gp
]; gp
++)
515 if (!hit
&& out
&& !mail
)
516 fprintf (out
, "all groups in group leaders file accounted for\n");
521 register int hit
= 0;
524 register struct grpldr
*gl
;
527 while (gl
= getglent ())
528 for (cp
= gl
->gl_ldr
; *cp
; cp
++) {
531 fprintf (out
, "group %s has unknown leader %s\n",
536 for (dp
= cp
+ 1; *dp
; dp
++)
537 if (strcmp (*cp
, *dp
) == 0) {
539 fprintf (out
, "group %s had duplicate leader %s\n",
546 if (!hit
&& out
&& !mail
)
547 fprintf (out
, "all group leaders accounted for\n");