]>
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 #define CONFLICT_SWITCHES \
30 X("mail name", 0, MAILSW) \
31 X("search directory", 0, SERCHSW) \
32 X("version", 0, VERSIONSW) \
33 X("help", 0, HELPSW) \
35 #define X(sw, minchars, id) id,
36 DEFINE_SWITCH_ENUM(CONFLICT
);
39 #define X(sw, minchars, id) { sw, minchars, id },
40 DEFINE_SWITCH_ARRAY(CONFLICT
, switches
);
43 static char *mail
= NULL
;
44 static char *dirs
[NDIRS
];
45 static FILE *out
= NULL
;
47 extern struct aka
*akahead
;
48 extern struct home
*homehead
;
53 void alias_files (int, char **);
54 void pwd_names (void);
55 void grp_names (void);
56 void grp_members (void);
58 void maildrops (void);
65 main (int argc
, char **argv
)
68 char *cp
, **argp
, **arguments
;
69 char buf
[BUFSIZ
], *akv
[50];
71 if (nmh_init(argv
[0], 0 /* use context_foil() */)) { return 1; }
74 arguments
= getarguments (invo_name
, argc
, argv
, 0);
77 while ((cp
= *argp
++)) {
79 switch (smatch (++cp
, switches
)) {
81 ambigsw (cp
, switches
);
84 adios (NULL
, "-%s unknown", cp
);
87 snprintf (buf
, sizeof(buf
), "%s [switches] [aliasfiles ...]",
89 print_help (buf
, switches
, 0);
92 print_version(invo_name
);
96 if (!(cp
= *argp
++) || *cp
== '-')
97 adios (NULL
, "missing argument to %s", argp
[-2]);
99 adios (NULL
, "mail to one address only");
105 if (!(cp
= *argp
++) || *cp
== '-')
106 adios (NULL
, "missing argument to %s", argp
[-2]);
108 adios (NULL
, "more than %d directories", NDIRS
);
117 akv
[akp
++] = AliasFile
;
124 alias_files (akp
, akv
);
137 alias_files (int akp
, char **akv
)
141 for (i
= 0; i
< akp
; i
++)
142 if ((err
= alias (akv
[i
])) != AK_OK
) {
144 fprintf (out
, "aliasing error in %s - %s\n", akv
[i
], akerror (err
));
148 fprintf (out
, "alias file %s is ok\n", akv
[i
]);
156 register struct home
*hm
, *lm
;
158 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
159 for (lm
= hm
->h_next
; lm
; lm
= lm
->h_next
)
160 if (strcmp (hm
->h_name
, lm
->h_name
) == 0) {
162 fprintf (out
, "duplicate user %s(uid=%d)\n",
163 lm
->h_name
, (int) lm
->h_uid
);
167 if (!hit
&& out
&& !mail
)
168 fprintf (out
, "no duplicate users\n");
175 int numgroups
, maxgroups
;
180 /* allocate space NGRPS at a time */
183 grps
= (char **) mh_xmalloc((size_t) (maxgroups
* sizeof(*grps
)));
186 while ((gr
= getgrent ())) {
187 for (i
= 0; i
< numgroups
; i
++)
188 if (!strcmp (grps
[i
], gr
->gr_name
)) {
190 fprintf (out
, "duplicate group %s(gid=%d)\n",
191 gr
->gr_name
, (int) gr
->gr_gid
);
195 if (i
>= numgroups
) {
196 if (numgroups
>= maxgroups
) {
198 grps
= (char **) mh_xrealloc(grps
,
199 (size_t) (maxgroups
* sizeof(*grps
)));
201 grps
[numgroups
++] = getcpy (gr
->gr_name
);
206 for (i
= 0; i
< numgroups
; i
++)
210 if (!hit
&& out
&& !mail
)
211 fprintf (out
, "no duplicate groups\n");
218 register int hit
= 0;
219 register char **cp
, **dp
;
220 register struct group
*gr
;
221 register struct home
*hm
;
224 while ((gr
= getgrent ())) {
225 for (cp
= gr
->gr_mem
; *cp
; cp
++) {
226 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
227 if (!strcmp (*cp
, hm
->h_name
))
231 fprintf (out
, "group %s(gid=%d) has unknown member %s\n",
232 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
238 for (dp
= cp
+ 1; *dp
; dp
++)
239 if (strcmp (*cp
, *dp
) == 0) {
241 fprintf (out
, "group %s(gid=%d) has duplicate member %s\n",
242 gr
->gr_name
, (int) gr
->gr_gid
, *cp
);
249 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
250 if (hm
->h_ngrps
> NGROUPS_MAX
) {
252 fprintf (out
, "user %s is a member of %d groups (max %d)\n",
253 hm
->h_name
, hm
->h_ngrps
, NGROUPS_MAX
);
257 if (!hit
&& out
&& !mail
)
258 fprintf (out
, "all group members accounted for\n");
264 { /* -DRAND not implemented at most places */
265 register int hit
= 0;
266 register struct home
*hm
;
268 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
269 if (getgrgid (hm
->h_gid
) == NULL
) {
271 fprintf (out
, "user %s(uid=%d) has unknown group-id %d\n",
272 hm
->h_name
, (int) hm
->h_uid
, (int) hm
->h_gid
);
276 if (!hit
&& out
&& !mail
)
277 fprintf (out
, "all group-id users accounted for\n");
286 if (mmdfldir
&& *mmdfldir
)
288 if (uucpldir
&& *uucpldir
)
290 for (i
= 0; dirs
[i
]; i
++)
298 register int hit
= 0;
299 register struct dirent
*dp
;
300 register DIR *dd
= opendir (drop
);
304 fprintf (out
, "unable to open maildrop area %s\n", drop
);
308 while ((dp
= readdir (dd
)))
309 if (dp
->d_name
[0] != '.' && !check (dp
->d_name
)) {
312 "there is a maildrop for the unknown user %s in %s\n",
318 if (!hit
&& out
&& !mail
)
319 fprintf (out
, "all maildrops accounted for in %s\n", drop
);
326 register struct home
*hm
;
328 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
329 if (!strcmp (s
, hm
->h_name
))
343 if (pipe (pd
) == NOTOK
)
344 adios ("pipe", "unable to");
348 adios ("fork", "unable to");
356 if ((fd
= open ("/dev/null", O_WRONLY
)) != NOTOK
)
361 execlp (mailproc
, r1bindex (mailproc
, '/'),
362 mail
, "-subject", invo_name
, (void *) NULL
);
363 adios (mailproc
, "unable to exec ");
367 out
= fdopen (pd
[1], "w");
368 fprintf (out
, "%s: the following is suspicious\n\n",