9 date 93.02.26.21.58.38; author jromine; state Exp;
14 date 92.12.15.00.20.22; author jromine; state Exp;
19 date 92.10.26.22.56.54; author jromine; state Exp;
24 date 92.10.20.22.43.10; author jromine; state Exp;
29 date 92.02.05.20.38.34; author jromine; state Exp;
34 date 92.02.03.17.57.22; author jromine; state Exp;
39 date 92.01.31.22.06.52; author jromine; state Exp;
44 date 90.04.05.14.59.03; author sources; state Exp;
49 date 90.04.02.14.42.27; author sources; state Exp;
54 date 90.03.22.19.31.36; author sources; state Exp;
59 date 90.02.06.13.14.52; author sources; state Exp;
64 date 90.01.30.11.12.03; author sources; state Exp;
69 date 90.01.29.15.19.04; author sources; state Exp;
74 date 90.01.29.15.18.42; author sources; state Exp;
88 @/* aliasbr.c - new aliasing mechanism */
90 static char ident[] = "@@(#)$Id: aliasbr.c,v 1.13 1992/12/15 00:20:22 jromine Exp jromine $";
94 #include "../h/aliasbr.h"
96 #include <sys/types.h>
104 static char *akerrst;
106 struct aka *akahead = NULL;
107 struct aka *akatail = NULL;
109 struct home *homehead = NULL;
110 struct home *hometail = NULL;
112 static char *scanp (), *getp (), *seekp (), *akval (), *getalias ();
113 static struct aka *akalloc ();
114 static struct home *hmalloc ();
117 static int aleq(), addfile(), addgroup(), addmember(), addall();
121 struct passwd *getpwent ();
122 struct group *getgrnam (), *getgrgid ();
134 (void) alias (AliasFile);
137 v = akval (akahead, s);
151 register struct aka *ak;
153 register char *cp = NULL,
156 register struct adr *ad;
158 for (ad = ak -> ak_addr; ad; ad = ad -> ad_next) {
159 pp = ad -> ad_local ? akval (ak -> ak_next, ad -> ad_text)
160 : getcpy (ad -> ad_text);
163 cp = concat (cp, ",", pp, NULLCP);
172 akvis = ak -> ak_visible;
177 static char *akval (ak, s)
178 register struct aka *ak;
184 for (; ak; ak = ak -> ak_next)
185 if (aleq (s, ak -> ak_name))
186 return akresult (ak);
192 static int aleq (string, aliasent)
193 register char *string,
198 while (c = *string++)
199 if (*aliasent == '*')
202 if ((c | 040) != (*aliasent | 040))
207 return (*aliasent == 0 || *aliasent == '*');
221 register struct aka *ak = NULL;
225 && (strncmp (file, "./", 2) && strncmp (file, "../", 3)))
226 file = libpath (file);
227 if ((fp = fopen (file, "r")) == NULL) {
232 while (vfgets (fp, &ap) == OK) {
234 switch (*(pp = scanp (bp))) {
235 case '<': /* recurse a level */
236 if (!*(cp = getp (pp + 1))) {
237 akerrst = "'<' without alias-file";
241 if ((i = alias (cp)) != AK_OK) {
246 case ':': /* comment */
254 if (!*(cp = seekp (pp, &lc, &ap))) {
258 if (!(ak = akalloc (cp))) {
264 ak -> ak_visible = 0;
268 ak -> ak_visible = 1;
276 switch (*(pp = scanp (ap))) {
281 case '<': /* read values from file */
282 if (!*(cp = getp (pp + 1))) {
286 if (!addfile (ak, cp)) {
292 case '=': /* UNIX group */
293 if (!*(cp = getp (pp + 1))) {
297 if (!addgroup (ak, cp)) {
303 case '+': /* UNIX group members */
304 if (!*(cp = getp (pp + 1))) {
308 if (!addmember (ak, cp)) {
314 case '*': /* Everyone */
319 while (cp = getalias (pp))
334 static char buffer[BUFSIZ];
338 (void) sprintf (buffer, "unable to read '%s'", akerrst);
342 (void) sprintf (buffer, "error in line '%s'", akerrst);
346 (void) sprintf (buffer, "out of memory while on '%s'", akerrst);
350 (void) sprintf (buffer, "no such group as '%s'", akerrst);
354 (void) sprintf (buffer, "unknown error (%d)", i);
363 static char *scanp (p)
372 static char *getp (p)
375 register char *cp = scanp (p);
378 while (!isspace (*cp) && *cp)
386 static char *seekp (p, c, a)
391 register char *cp = scanp (p);
394 while (!isspace (*cp) && *cp && *cp != ':' && *cp != ';')
405 static int addfile (ak, file)
406 register struct aka *ak;
413 if ((fp = fopen (libpath (file), "r")) == NULL) {
418 while (fgets (buffer, sizeof buffer, fp) != NULL)
419 while (cp = getalias (buffer))
428 static int addgroup (ak, grp)
429 register struct aka *ak;
433 register struct group *gr = getgrnam (grp);
434 register struct home *hm = NULL;
437 gr = getgrgid (atoi (grp));
444 if (homehead == NULL)
448 while (gp = *gr -> gr_mem++)
453 for (hm = homehead; hm; hm = hm -> h_next)
454 if (!strcmp (hm -> h_name, gp)) {
455 add_aka (ak, hm -> h_name);
459 if (pw = getpwnam(gp))
472 static int addmember (ak, grp)
473 register struct aka *ak;
477 register struct group *gr = getgrnam (grp);
478 register struct home *hm = NULL;
492 if (homehead == NULL)
496 for (hm = homehead; hm; hm = hm -> h_next)
497 if (hm -> h_gid == gid)
498 add_aka (ak, hm -> h_name);
505 static int addall (ak)
506 register struct aka *ak;
508 int noshell = NoShell == NULLCP || *NoShell == 0;
509 register struct home *hm;
512 if (homehead == NULL)
518 for (hm = homehead; hm; hm = hm -> h_next)
519 if (hm -> h_uid > Everyone
520 && (noshell || strcmp (hm -> h_shell, NoShell)))
521 add_aka (ak, hm -> h_name);
523 return homehead != NULL;
528 static char *getalias (addrs)
529 register char *addrs;
533 static char *cp = NULL;
541 for (pp = cp; isspace (*pp); pp++)
545 for (qp = pp; *qp != 0 && *qp != ','; qp++)
549 for (cp = qp, qp--; qp > pp; qp--)
561 static add_aka (ak, pp)
562 register struct aka *ak;
565 register struct adr *ad,
568 for (ad = ak -> ak_addr, ld = NULL; ad; ld = ad, ad = ad -> ad_next)
569 if (!strcmp (pp, ad -> ad_text))
572 ad = (struct adr *) malloc (sizeof *ad);
575 ad -> ad_text = getcpy (pp);
576 ad -> ad_local = index (pp, '@@') == NULL && index (pp, '!') == NULL;
577 ad -> ad_next = NULL;
586 register struct passwd *pw;
592 /* if the list has yet to be initialized */
593 /* zap the list, and rebuild from scratch */
601 while (pw = getpwent ())
613 static struct aka *akalloc (id)
616 register struct aka *p = (struct aka *) malloc (sizeof *p);
621 p -> ak_name = getcpy (id);
626 akatail -> ak_next = p;
635 static struct home *hmalloc (pw)
638 register struct home *p = (struct home *) malloc (sizeof *p);
643 p -> h_name = getcpy (pw -> pw_name);
644 p -> h_uid = pw -> pw_uid;
645 p -> h_gid = pw -> pw_gid;
646 p -> h_home = getcpy (pw -> pw_dir);
647 p -> h_shell = getcpy (pw -> pw_shell);
652 if (hometail != NULL)
653 hometail -> h_next = p;
654 if (homehead == NULL)
664 struct home *seek_home (name)
667 register struct home *hp;
674 if (homehead == NULL)
678 for (hp = homehead; hp; hp = hp -> h_next)
679 if (uleq (name, hp -> h_name))
682 #ifdef DBMPWD /* The only place where there might be problems */
683 /* This assumes that ALL usernames are kept in lowercase */
684 for (c = name,c1 = lname; *c; c++, c1++)
685 if (isalpha(*c) && isupper(*c))
690 if (pw = getpwnam(lname))
707 static char ident[] = "@@(#)$Id: aliasbr.c,v 1.12 1992/10/26 22:56:54 jromine Exp jromine $";
714 @use isalpha with isupper
719 static char ident[] = "@@(#)$Id: aliasbr.c,v 1.11 1992/10/20 22:43:10 jromine Exp jromine $";
732 @DBM->DBMPWD (conflict with ndbm.h)
737 static char ident[] = "@@(#)$Id: aliasbr.c,v 1.10 1992/02/05 20:38:34 jromine Exp jromine $";
746 @remove #ifdef around EVERYONE
751 static char ident[] = "@@(#)$Id: aliasbr.c,v 1.9 1992/02/03 17:57:22 jromine Exp jromine $";
805 #ifdef DBM /* The only place where there might be problems */
819 static char ident[] = "@@(#)$Id: aliasbr.c,v 1.8 1992/01/31 22:06:52 jromine Exp jromine $";
834 static char ident[] = "@@(#)$Id: aliasbr.c,v 1.7 1990/04/05 14:59:03 sources Exp jromine $";
847 static char ident[] = "@@(#)$Id:$";
850 return (*aliasent == NULL || *aliasent == '*');
874 int noshell = NoShell == NULLCP || *NoShell == NULL;
883 for (qp = pp; *qp != NULL && *qp != ','; qp++)
907 @add "#" as a comment character
946 char *scanp (), *getp (), *seekp (), *akval (), *getalias ();
947 struct aka *akalloc ();
948 struct home *hmalloc ();
955 @fix for NULL pointer
960 if ((i = alias (cp) != AK_OK)) {