authvchkpw.c
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:2k
- /*
- ** Copyright 1998 - 2000 Double Precision, Inc. See COPYING for
- ** distribution information.
- */
- #if HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <pwd.h>
- #if HAVE_UNISTD_H
- #include <unistd.h>
- #endif
- #include "auth.h"
- #include "authmod.h"
- static const char rcsid[]="$Id: authvchkpw.c,v 1.11 2000/04/30 01:04:09 mrsam Exp $";
- extern int auth_vchkpw_pre(const char *userid, const char *service,
- int (*callback)(struct authinfo *, void *),
- void *arg);
- extern char *authvchkpw_isvirtual(char *);
- extern FILE *authvchkpw_file(const char *, const char *);
- extern struct passwd *authvchkpw_search(FILE *, const char *);
- struct callback_info {
- const char *pass;
- char *userret;
- int issession;
- void (*callback_func)(struct authinfo *, void *);
- void *callback_arg;
- };
- static int callback_vchkpw(struct authinfo *a, void *p)
- {
- struct callback_info *i=(struct callback_info *)p;
- if (a->passwd == 0 || authcheckpassword(i->pass, a->passwd))
- return (-1);
- if ((i->userret=strdup(a->address)) == 0)
- {
- perror("malloc");
- return (1);
- }
- if (i->callback_func == 0)
- {
- authsuccess(a->homedir, 0, a->sysuserid, &a->sysgroupid,
- a->address, a->fullname);
- putenv("MAILDIR=");
- }
- else
- (*i->callback_func)(a, i->callback_arg);
- return (0);
- }
- char *auth_vchkpw(const char *service, const char *authtype, char *authdata,
- int issession,
- void (*callback_func)(struct authinfo *, void *), void *callback_arg)
- {
- char *user, *pass;
- int rc;
- struct callback_info ci;
- if (strcmp(authtype, AUTHTYPE_LOGIN) ||
- (user=strtok(authdata, "n")) == 0 ||
- (pass=strtok(0, "n")) == 0)
- {
- errno=EPERM;
- return (0);
- }
- ci.pass=pass;
- ci.issession=issession;
- ci.callback_func=callback_func;
- ci.callback_arg=callback_arg;
- rc=auth_vchkpw_pre(user, service, &callback_vchkpw, &ci);
- if (rc < 0)
- {
- errno=EPERM;
- return (0);
- }
- if (rc > 0)
- {
- errno=EACCES;
- return (0);
- }
- putenv("MAILDIR=");
- return (ci.userret);
- }