1 /* Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
2 * All Rights Reserved. See COPYRIGHT.
12 #include <sys/param.h>
15 #include <netatalk/endian.h>
16 #include <atalk/asp.h>
17 #include <atalk/dsi.h>
18 #include <atalk/afp.h>
19 #include <atalk/util.h>
23 /* --- server uam functions -- */
25 /* uam_load. uams must have a uam_setup function. */
26 struct uam_mod *uam_load(const char *path, const char *name)
28 char buf[MAXPATHLEN + 1], *p;
32 if ((module = mod_open(path)) == NULL) {
33 syslog(LOG_ERR, "uam_load(%s): failed to load.", name);
34 syslog(LOG_ERR, dlerror());
38 if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) {
39 syslog(LOG_ERR, "uam_load(%s): malloc failed", name);
43 strncpy(buf, name, sizeof(buf));
44 if ((p = strchr(buf, '.')))
46 if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) {
50 if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) {
51 syslog(LOG_ERR, "uam_load(%s): attempted to load a non-server module",
56 /* version check would go here */
58 if (!mod->uam_fcn->uam_setup ||
59 ((*mod->uam_fcn->uam_setup)(name) < 0)) {
60 syslog(LOG_ERR, "uam_load(%s): uam_setup failed", name);
64 mod->uam_module = module;
74 /* unload the module. we check for a cleanup function, but we don't
75 * die if one doesn't exist. however, things are likely to leak without one.
77 void uam_unload(struct uam_mod *mod)
79 if (mod->uam_fcn->uam_cleanup)
80 (*mod->uam_fcn->uam_cleanup)();
81 mod_close(mod->uam_module);
85 /* -- client-side uam functions -- */
87 /* set up stuff for this uam. */
88 int uam_register(const int type, const char *path, const char *name, ...)
96 /* see if it already exists. */
97 if ((uam = auth_uamfind(type, name, strlen(name)))) {
98 if (strcmp(uam->uam_path, path)) {
99 /* it exists, but it's not the same module. */
100 syslog(LOG_ERR, "uam_register: \"%s\" already loaded by %s",
108 /* allocate space for uam */
109 if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL)
112 uam->uam_name = name;
113 uam->uam_path = strdup(path);
118 case UAM_SERVER_LOGIN: /* expect three arguments */
119 uam->u.uam_login.login = va_arg(ap, void *);
120 uam->u.uam_login.logincont = va_arg(ap, void *);
121 uam->u.uam_login.logout = va_arg(ap, void *);
123 case UAM_SERVER_CHANGEPW: /* one argument */
124 uam->u.uam_changepw = va_arg(ap, void *);
126 case UAM_SERVER_PRINTAUTH: /* x arguments */
127 uam->u.uam_printer = va_arg(ap, void *);
134 /* attach to other uams */
135 if (auth_register(type, uam) < 0) {
144 void uam_unregister(const int type, const char *name)
151 uam = auth_uamfind(type, name, strlen(name));
152 if (!uam || --uam->uam_count > 0)
155 auth_unregister(uam);
160 /* Crap to support uams which call this afpd function */
161 int uam_afpserver_option(void *private, const int what, void *option,
167 /* --- helper functions for plugin uams --- */
169 struct passwd *uam_getname(char *name, const int len)
171 struct passwd *pwent;
175 if ((pwent = getpwnam(name)))
178 #ifndef NO_REAL_USER_NAME
179 for (i = 0; i < len; i++)
180 name[i] = tolower(name[i]);
183 while ((pwent = getpwent())) {
184 if (user = strchr(pwent->pw_gecos, ','))
186 user = pwent->pw_gecos;
188 /* check against both the gecos and the name fields. the user
189 * might have just used a different capitalization. */
190 if ((strncasecmp(user, name, len) == 0) ||
191 (strncasecmp(pwent->pw_name, name, len) == 0)) {
192 strncpy(name, pwent->pw_name, len);
199 /* os x server doesn't keep anything useful if we do getpwent */
200 return pwent ? getpwnam(name) : NULL;
204 int uam_checkuser(const struct passwd *pwd)
208 if (!pwd || !pwd->pw_shell || (*pwd->pw_shell == '\0'))
211 while ((p = getusershell())) {
212 if ( strcmp( p, pwd->pw_shell ) == 0 )
218 syslog( LOG_INFO, "illegal shell %s for %s",pwd->pw_shell,pwd->pw_name);