]>
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];
72 setlocale(LC_ALL
, "");
74 invo_name
= r1bindex (argv
[0], '/');
76 /* foil search of user profile/context */
77 if (context_foil (NULL
) == -1)
81 arguments
= getarguments (invo_name
, argc
, argv
, 0);
84 while ((cp
= *argp
++)) {
86 switch (smatch (++cp
, switches
)) {
88 ambigsw (cp
, switches
);
91 adios (NULL
, "-%s unknown", cp
);
94 snprintf (buf
, sizeof(buf
), "%s [switches] [aliasfiles ...]",
96 print_help (buf
, switches
, 0);
99 print_version(invo_name
);
103 if (!(cp
= *argp
++) || *cp
== '-')
104 adios (NULL
, "missing argument to %s", argp
[-2]);
106 adios (NULL
, "mail to one address only");
112 if (!(cp
= *argp
++) || *cp
== '-')
113 adios (NULL
, "missing argument to %s", argp
[-2]);
115 adios (NULL
, "more than %d directories", NDIRS
);
124 akv
[akp
++] = AliasFile
;
131 alias_files (akp
, akv
);
144 alias_files (int akp
, char **akv
)
148 for (i
= 0; i
< akp
; i
++)
149 if ((err
= alias (akv
[i
])) != AK_OK
) {
151 fprintf (out
, "aliasing error in %s - %s\n", akv
[i
], akerror (err
));
155 fprintf (out
, "alias file %s is ok\n", akv
[i
]);
163 register struct home
*hm
, *lm
;
165 for (hm
= homehead
; hm
; hm
= hm
->h_next
)
166 for (lm
= hm
->h_next
; lm
; lm
= lm
->h_next
)
167 if (strcmp (hm
->h_name
, lm
->h_name
) == 0) {
169 fprintf (out
, "duplicate user %s(uid=%d)\n",
170 lm
->h_name
, (int) lm
->h_uid
);
174 if (!hit
&& out
&& !mail
)
175 fprintf (out
, "no duplicate users\n");
182 int numgroups
, maxgroups
;
187 /* allocate space NGRPS at a time */
190 grps
= (char **) mh_xmalloc((size_t) (maxgroups
* sizeof(*grps
)));
193 while ((gr
= getgrent ())) {
194 for (i
= 0; i
< numgroups
; i
++)
195 if (!strcmp (grps
[i
], gr
->gr_name
)) {
197 fprintf (out
, "duplicate group %s(gid=%d)\n",
198 gr
->gr_name
, (int) gr
->gr_gid
);
202 if (i
>= numgroups
) {
203 if (numgroups
>= maxgroups
) {
205 grps
= (char **) mh_xrealloc(grps
,
206 (size_t) (maxgroups
* sizeof(*grps
)));
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
, (void *) NULL
);
370 adios (mailproc
, "unable to exec ");
374 out
= fdopen (pd
[1], "w");
375 fprintf (out
, "%s: the following is suspicious\n\n",