]> arthur.barton.de Git - netatalk.git/blob - etc/papd/auth.c
90f416186321f273bfa932b9282e4f5618639447
[netatalk.git] / etc / papd / auth.c
1 /*
2  * Copyright (c) 1990,1993 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/types.h>
10 #include <sys/param.h>
11 #include <sys/stat.h>
12 #include <netatalk/endian.h>
13 #include <atalk/afp.h>
14 #include <atalk/compat.h>
15 #include <atalk/util.h>
16 #include <limits.h>
17 #include <string.h>
18 #include <ctype.h>
19 #include <pwd.h>
20 #include <grp.h>
21 #include <syslog.h>
22
23 #include "uam_auth.h"
24
25 static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules};
26 static struct uam_obj uam_login = {"", "", 0, {{NULL}}, &uam_login,
27                                    &uam_login};
28 static struct uam_obj uam_changepw = {"", "", 0, {{NULL}}, &uam_changepw, 
29                                       &uam_changepw};
30 static struct uam_obj uam_printer = {"", "", 0, {{NULL}}, &uam_printer,
31                                         &uam_printer};
32
33
34 /*
35  * Return a list of names for loaded uams
36  */
37 int getuamnames(const int type, char *uamnames)
38 {
39     struct uam_obj *prev, *start;
40   
41     if (!(start = UAM_LIST(type)))
42         return(-1);
43   
44     prev = start;
45       
46     while((prev = prev->uam_prev) != start) {
47         strcat(uamnames, prev->uam_name);
48         strcat(uamnames, "\n");
49     }
50  
51     strcat(uamnames, "*\n");
52     return(0);
53 }
54   
55
56 /* just do a linked list search. this could be sped up with a hashed
57  * list, but i doubt anyone's going to have enough uams to matter. */
58 struct uam_obj *auth_uamfind(const int type, const char *name, 
59                              const int len)
60 {
61   struct uam_obj *prev, *start;
62
63   if (!name || !(start = UAM_LIST(type)))
64     return NULL;
65
66   prev = start;
67   while ((prev = prev->uam_prev) != start) 
68     if (strndiacasecmp(prev->uam_name, name, len) == 0)
69       return prev;
70
71   return NULL;
72 }
73
74 int auth_register(const int type, struct uam_obj *uam)
75 {
76   struct uam_obj *start;
77
78   if (!uam || !uam->uam_name || (*uam->uam_name == '\0'))
79     return -1;
80
81   if (!(start = UAM_LIST(type)))
82     return 0; /* silently fail */
83
84   uam_attach(start, uam);
85   return 0;
86 }
87
88 /* load all of the modules */
89 int auth_load(const char *path, const char *list)
90 {
91   char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p; 
92   struct uam_mod *mod;
93   struct stat st;
94   int len;
95   
96   if (!path || !list || (len = strlen(path)) > sizeof(name) - 2)
97     return -1;
98
99   strncpy(buf, list, sizeof(buf));
100   if ((p = strtok(buf, ",")) == NULL)
101     return -1;
102
103   strcpy(name, path);
104   if (name[len - 1] != '/') {
105     strcat(name, "/");
106     len++;
107   }
108
109   while (p) {
110     strncpy(name + len, p, sizeof(name) - len);
111     if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {
112       uam_attach(&uam_modules, mod);
113       syslog(LOG_INFO, "uam: %s loaded", p);
114     }
115     p = strtok(NULL, ",");
116   }
117 }
118
119 /* get rid of all of the uams */
120 void auth_unload()
121 {
122   struct uam_mod *mod, *prev, *start = &uam_modules;
123
124   prev = start->uam_prev;
125   while ((mod = prev) != start) {
126     prev = prev->uam_prev;
127     uam_detach(mod);
128     uam_unload(mod);
129   }
130 }