72
81
struct uam_mod *mod;
75
85
if ((module = mod_open(path)) == NULL) {
76
86
LOG(log_error, logtype_afpd, "uam_load(%s): failed to load: %s", name, mod_error());
80
91
if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) {
81
92
LOG(log_error, logtype_afpd, "uam_load(%s): malloc failed", name);
82
93
goto uam_load_fail;
85
strncpy(buf, name, sizeof(buf));
86
buf[sizeof(buf) - 1] = '\0';
96
strlcpy(buf, name, sizeof(buf));
87
97
if ((p = strchr(buf, '.')))
89
101
if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) {
90
102
LOG(log_error, logtype_afpd, "uam_load(%s): mod_symbol error for symbol %s",
125
140
if (mod->uam_fcn->uam_cleanup)
126
141
(*mod->uam_fcn->uam_cleanup)();
127
144
mod_close(mod->uam_module);
131
149
/* -- client-side uam functions -- */
133
151
/* set up stuff for this uam. */
134
152
int uam_register(const int type, const char *path, const char *name, ...)
137
155
struct uam_obj *uam;
162
181
va_start(ap, name);
183
case UAM_SERVER_LOGIN_EXT: /* expect four arguments */
184
uam->u.uam_login.login = va_arg(ap, void *);
185
uam->u.uam_login.logincont = va_arg(ap, void *);
186
uam->u.uam_login.logout = va_arg(ap, void *);
187
uam->u.uam_login.login_ext = va_arg(ap, void *);
164
190
case UAM_SERVER_LOGIN: /* expect three arguments */
191
uam->u.uam_login.login_ext = NULL;
165
192
uam->u.uam_login.login = va_arg(ap, void *);
166
193
uam->u.uam_login.logincont = va_arg(ap, void *);
167
194
uam->u.uam_login.logout = va_arg(ap, void *);
178
205
/* attach to other uams */
206
ret = auth_register(type, uam);
217
int uam_register_fn(const int type, const char *path, const char *name, void *fn1, void *fn2,
218
void *fn3, void *fn4)
226
/* see if it already exists. */
227
if ((uam = auth_uamfind(type, name, strlen(name)))) {
228
if (strcmp(uam->uam_path, path)) {
229
/* it exists, but it's not the same module. */
230
LOG(log_error, logtype_afpd, "uam_register: \"%s\" already loaded by %s",
238
/* allocate space for uam */
239
if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL)
242
uam->uam_name = name;
243
uam->uam_path = strdup(path);
247
case UAM_SERVER_LOGIN_EXT: /* expect four arguments */
248
uam->u.uam_login.login_ext = fn4;
249
uam->u.uam_login.login = fn1;
250
uam->u.uam_login.logincont = fn2;
251
uam->u.uam_login.logout = fn3;
253
case UAM_SERVER_LOGIN: /* expect three arguments */
254
uam->u.uam_login.login_ext = NULL;
255
uam->u.uam_login.login = fn1;
256
uam->u.uam_login.logincont = fn2;
257
uam->u.uam_login.logout = fn3;
259
case UAM_SERVER_CHANGEPW: /* one argument */
260
uam->u.uam_changepw = fn1;
262
case UAM_SERVER_PRINTAUTH: /* x arguments */
267
/* attach to other uams */
179
268
if (auth_register(type, uam) < 0) {
180
269
free(uam->uam_path);
204
294
/* --- helper functions for plugin uams --- */
206
struct passwd *uam_getname(char *name, const int len)
296
struct passwd *uam_getname(void *private, char *name, const int len)
298
AFPObj *obj = private;
208
299
struct passwd *pwent;
300
static char username[256];
301
static char user[256];
302
static char pwname[256];
304
size_t namelen, gecoslen = 0, pwnamelen = 0;
212
306
if ((pwent = getpwnam(name)))
215
309
#ifndef NO_REAL_USER_NAME
216
for (i = 0; i < len; i++)
217
name[i] = tolower(name[i]);
311
if ( (size_t) -1 == (namelen = convert_string((utf8_encoding())?CH_UTF8_MAC:obj->options.maccharset,
312
CH_UCS2, name, strlen(name), username, sizeof(username))))
220
316
while ((pwent = getpwent())) {
221
if ((user = strchr(pwent->pw_gecos, ',')))
223
user = pwent->pw_gecos;
317
if ((p = strchr(pwent->pw_gecos, ',')))
320
if ((size_t)-1 == ( gecoslen = convert_string(obj->options.unixcharset, CH_UCS2,
321
pwent->pw_gecos, strlen(pwent->pw_gecos), user, sizeof(username))) )
323
if ((size_t)-1 == ( pwnamelen = convert_string(obj->options.unixcharset, CH_UCS2,
324
pwent->pw_name, strlen(pwent->pw_name), pwname, sizeof(username))) )
225
328
/* check against both the gecos and the name fields. the user
226
329
* might have just used a different capitalization. */
227
if ((strncasecmp(user, name, len) == 0) ||
228
(strncasecmp(pwent->pw_name, name, len) == 0)) {
229
strncpy(name, pwent->pw_name, len);
230
name[len - 1] = '\0';
331
if ( (namelen == gecoslen && strncasecmp_w((ucs2_t*)user, (ucs2_t*)username, len) == 0) ||
332
( namelen == pwnamelen && strncasecmp_w ( (ucs2_t*) pwname, (ucs2_t*) username, len) == 0)) {
333
strlcpy(name, pwent->pw_name, len);
372
int uam_random_string (AFPObj *obj, char *buf, int len)
378
if ( (len <= 0) || (len % sizeof(result)))
381
/* construct a random number */
382
if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
387
if (gettimeofday(&tv, &tz) < 0)
389
srandom(tv.tv_sec + (unsigned long) obj + (unsigned long) obj->handle);
390
for (i = 0; i < len; i += sizeof(result)) {
392
memcpy(buf + i, &result, sizeof(result));
395
ret = read(fd, buf, len);
271
403
/* afp-specific functions */
272
404
int uam_afpserver_option(void *private, const int what, void *option,
275
407
AFPObj *obj = private;
276
408
char **buf = (char **) option; /* most of the options are this */
409
struct session_info **sinfo = (struct session_info **) option;
280
411
if (!obj || !option)
284
415
case UAM_OPTION_USERNAME:
285
*buf = (void *) obj->username;
416
*buf = obj->username;
287
418
*len = sizeof(obj->username) - 1;
290
421
case UAM_OPTION_GUEST:
291
*buf = (void *) obj->options.guest;
422
*buf = obj->options.guest;
293
424
*len = strlen(obj->options.guest);
329
460
case UAM_OPTION_RANDNUM: /* returns a random number in 4-byte units. */
330
if (!len || (*len < 0) || (*len % sizeof(result)))
333
/* construct a random number */
334
if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
337
char *randnum = (char *) option;
340
if (gettimeofday(&tv, &tz) < 0)
342
srandom(tv.tv_sec + (unsigned long) obj + (unsigned long) obj->handle);
343
for (i = 0; i < *len; i += sizeof(result)) {
345
memcpy(randnum + i, &result, sizeof(result));
348
result = read(fd, option, *len);
464
return uam_random_string(obj, option, *len);
355
467
case UAM_OPTION_HOSTNAME:
356
*buf = (void *) obj->options.hostname;
468
*buf = obj->options.hostname;
358
470
*len = strlen(obj->options.hostname);
361
473
case UAM_OPTION_PROTOCOL:
362
*buf = (void *) obj->proto;
474
*((int *) option) = obj->proto;
364
477
case UAM_OPTION_CLIENTNAME:
366
479
struct DSI *dsi = obj->handle;
370
483
sizeof( struct in_addr ),
371
484
dsi->client.sin_family );
373
*buf = (void *) hp->h_name;
375
*buf = (void *) inet_ntoa( dsi->client.sin_addr );
488
*buf = inet_ntoa( dsi->client.sin_addr );
378
491
case UAM_OPTION_COOKIE:
383
496
*buf = (void *) &obj->uam_cookie;
385
498
case UAM_OPTION_KRB5SERVICE:
386
*buf = obj->options.k5service;
388
*len = strlen(obj->options.k5service);
499
*buf = obj->options.k5service;
501
*len = (*buf)?strlen(*buf):0;
503
case UAM_OPTION_KRB5REALM:
504
*buf = obj->options.k5realm;
506
*len = (*buf)?strlen(*buf):0;
508
case UAM_OPTION_FQDN:
509
*buf = obj->options.fqdn;
511
*len = (*buf)?strlen(*buf):0;
513
case UAM_OPTION_MACCHARSET:
514
*((int *) option) = obj->options.maccharset;
515
*len = sizeof(obj->options.maccharset);
517
case UAM_OPTION_UNIXCHARSET:
518
*((int *) option) = obj->options.unixcharset;
519
*len = sizeof(obj->options.unixcharset);
521
case UAM_OPTION_SESSIONINFO:
522
*sinfo = &(obj->sinfo);