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