]>
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
);
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 grps
= (char **) mh_xmalloc((size_t) (maxgroups
* sizeof(*grps
)));
191 while ((gr
= getgrent ())) {
192 for (i
= 0; i
< numgroups
; i
++)
193 if (!strcmp (grps
[i
], gr
->gr_name
)) {
195 fprintf (out
, "duplicate group %s(gid=%d)\n",
196 gr
->gr_name
, (int) gr
->gr_gid
);
200 if (i
>= numgroups
) {
201 if (numgroups
>= maxgroups
) {
203 grps
= (char **) mh_xrealloc(grps
,
204 (size_t) (maxgroups
* sizeof(*grps
)));
206 grps
[numgroups
++] = getcpy (gr
->gr_name
);
211 for (i
= 0; i
< numgroups
; i
++)
215 if (!hit
&& out
&& !mail
)
216 fprintf (out
, "no duplicate groups\n");
223 register int hit
= 0;
224 register char **cp
, **dp
;
225 register struct group
*gr
;
226 register struct home
*hm
;
229 while ((gr
= getgrent ())) {
230 for (cp
= gr
->gr_mem
; *cp
; cp
++) {
231 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
232 if (!strcmp (*cp
, hm
->h_name
))
236 fprintf (out
, "group %s(gid=%d) has unknown member %s\n",
237 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
243 for (dp
= cp
+ 1; *dp
; dp
++)
244 if (strcmp (*cp
, *dp
) == 0) {
246 fprintf (out
, "group %s(gid=%d) has duplicate member %s\n",
247 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
254 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
255 if (hm
->h_ngrps
> NGROUPS_MAX
) {
257 fprintf (out
, "user %s is a member of %d groups (max %d)\n",
258 hm
->h_name
, hm
->h_ngrps
, NGROUPS_MAX
);
262 if (!hit
&& out
&& !mail
)
263 fprintf (out
, "all group members accounted for\n");
269 { /* -DRAND not implemented at most places */
270 register int hit
= 0;
271 register struct home
*hm
;
273 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
274 if (getgrgid (hm
->h_gid
) == NULL
) {
276 fprintf (out
, "user %s(uid=%d) has unknown group-id %d\n",
277 hm
->h_name
, (int) hm
->h_uid
, (int) hm
->h_gid
);
281 if (!hit
&& out
&& !mail
)
282 fprintf (out
, "all group-id users accounted for\n");
291 if (mmdfldir
&& *mmdfldir
)
293 if (uucpldir
&& *uucpldir
)
295 for (i
= 0; dirs
[i
]; i
++)
303 register int hit
= 0;
304 register struct dirent
*dp
;
305 register DIR *dd
= opendir (drop
);
309 fprintf (out
, "unable to open maildrop area %s\n", drop
);
313 while ((dp
= readdir (dd
)))
314 if (dp
->d_name
[0] != '.' && !check (dp
->d_name
)) {
317 "there is a maildrop for the unknown user %s in %s\n",
323 if (!hit
&& out
&& !mail
)
324 fprintf (out
, "all maildrops accounted for in %s\n", drop
);
331 register struct home
*hm
;
333 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
334 if (!strcmp (s
, hm
->h_name
))
348 if (pipe (pd
) == NOTOK
)
349 adios ("pipe", "unable to");
353 adios ("fork", "unable to");
361 if ((fd
= open ("/dev/null", O_WRONLY
)) != NOTOK
)
366 execlp (mailproc
, r1bindex (mailproc
, '/'),
367 mail
, "-subject", invo_name
, NULL
);
368 adios (mailproc
, "unable to exec ");
372 out
= fdopen (pd
[1], "w");
373 fprintf (out
, "%s: the following is suspicious\n\n",