1 |
|
|
2 |
/* Copyright (C) 1999 Beau Kuiper |
/* Copyright (C) 1999 Beau Kuiper |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
23 |
|
|
24 |
/* This file contains code to autheticate against custom password files */ |
/* This file contains code to autheticate against custom password files */ |
25 |
|
|
26 |
typedef struct |
typedef struct |
27 |
{ |
{ |
28 |
char *udata; |
char *udata; |
29 |
char *password; |
char *password; |
30 |
char *username; |
char *username; |
31 |
char *homedir; |
char *homedir; |
32 |
char *rootdir; |
char *rootdir; |
33 |
} PASSWDSTRUCT; |
} |
34 |
|
PASSWDSTRUCT; |
35 |
|
|
36 |
int internalauth_config(char *username, char *data, int line, void *h) |
int internalauth_config(char *username, |
37 |
|
char *data, |
38 |
|
int line, |
39 |
|
void *h) |
40 |
{ |
{ |
41 |
PASSWDSTRUCT *handle = (PASSWDSTRUCT *)h; |
PASSWDSTRUCT *handle = (PASSWDSTRUCT *) h; |
42 |
|
|
43 |
if (strcmp(username, handle->username) == 0) |
if (strcmp(username, handle->username) == 0) |
44 |
{ |
{ |
45 |
handle->udata = strdupwrapper(data); |
handle->udata = strdupwrapper(data); |
46 |
return(GOT_USER); |
return (GOT_USER); |
47 |
} |
} |
48 |
return(NOT_GOT_USER); |
return (NOT_GOT_USER); |
49 |
} |
} |
50 |
|
|
51 |
void *internalauth_gethandle(FTPSTATE *peer, TOKENSET *tset, char *username, int *err) |
void *internalauth_gethandle(FTPSTATE * peer, |
52 |
|
TOKENSET * tset, |
53 |
|
char *username, |
54 |
|
int *err) |
55 |
{ |
{ |
56 |
PASSWDSTRUCT *newhandle; |
PASSWDSTRUCT *newhandle; |
57 |
int result, error, line; |
int result, error, line; |
58 |
char *passwdfile = NULL; |
char *passwdfile = NULL; |
59 |
|
|
60 |
/* assume we don't find the user */ |
/* |
61 |
|
* assume we don't find the user |
62 |
|
*/ |
63 |
*err = AUTH_USERNKNOW; |
*err = AUTH_USERNKNOW; |
64 |
|
|
65 |
newhandle = mallocwrapper(sizeof(PASSWDSTRUCT)); |
newhandle = mallocwrapper(sizeof(PASSWDSTRUCT)); |
66 |
newhandle->username = strdupwrapper(username); |
newhandle->username = strdupwrapper(username); |
67 |
|
|
68 |
passwdfile = mktokconfstr(tset, auth_getcursectionid(peer), "internal_passfile", NULL); |
passwdfile = |
69 |
|
mktokconfstr(tset, auth_getcursectionid(peer), "internal_passfile", |
70 |
|
NULL); |
71 |
if (passwdfile == NULL) |
if (passwdfile == NULL) |
72 |
goto logerror; |
goto logerror; |
73 |
|
|
74 |
/* make sure that the password file is secure */ |
/* |
75 |
result = loadconfigfile(passwdfile, internalauth_config, newhandle, TRUE, &error, &line); |
* make sure that the password file is secure |
76 |
|
*/ |
77 |
|
result = |
78 |
|
loadconfigfile(passwdfile, internalauth_config, newhandle, TRUE, |
79 |
|
&error, &line); |
80 |
|
|
81 |
switch (result) |
switch (result) |
82 |
{ |
{ |
83 |
case CONFIG_OK: |
case CONFIG_OK: |
84 |
goto error; |
goto error; |
85 |
case CONFIG_HANDLER_ERROR: |
case CONFIG_HANDLER_ERROR: |
86 |
break; /* found the user */ |
break; /* found the user */ |
87 |
default: |
default: |
88 |
goto logerror; |
goto logerror; |
89 |
} |
} |
90 |
|
|
91 |
if (strchrcount(newhandle->udata, ':') != 2) |
if (strchrcount(newhandle->udata, ':') != 2) |
97 |
newhandle->password = newhandle->udata; |
newhandle->password = newhandle->udata; |
98 |
newhandle->homedir = strchr(newhandle->udata, ':') + 1; |
newhandle->homedir = strchr(newhandle->udata, ':') + 1; |
99 |
|
|
100 |
/* lets hope this doesn't cause heart attacks. It may not |
/* |
101 |
work with flakey C compilers */ |
* lets hope this doesn't cause heart attacks. It may not |
102 |
|
* work with flakey C compilers |
103 |
|
*/ |
104 |
newhandle->homedir[-1] = 0; |
newhandle->homedir[-1] = 0; |
105 |
newhandle->rootdir = strchr(newhandle->homedir, ':') + 1; |
newhandle->rootdir = strchr(newhandle->homedir, ':') + 1; |
106 |
newhandle->rootdir[-1] = 0; |
newhandle->rootdir[-1] = 0; |
107 |
|
|
108 |
*err = AUTH_OK; |
*err = AUTH_OK; |
109 |
freewrapper(passwdfile); |
freewrapper(passwdfile); |
110 |
return(newhandle); |
return (newhandle); |
111 |
|
|
112 |
logerror: |
logerror: |
113 |
if (passwdfile == NULL) |
if (passwdfile == NULL) |
114 |
log_addentry(MYLOG_INFO, NULL, "You didn't specify a password file for internal authentication!"); |
log_addentry(MYLOG_INFO, NULL, |
115 |
|
"You didn't specify a password file for internal authentication!"); |
116 |
else |
else |
117 |
log_giveentry(MYLOG_INFO, NULL, safe_snprintf("Error loading '%s': %s", passwdfile, config_errorstr(result))); |
log_giveentry(MYLOG_INFO, NULL, |
118 |
|
safe_snprintf("Error loading '%s': %s", passwdfile, |
119 |
|
config_errorstr(result))); |
120 |
*err = AUTH_ERROR; |
*err = AUTH_ERROR; |
121 |
|
|
122 |
error: |
error: |
123 |
freeifnotnull(passwdfile); |
freeifnotnull(passwdfile); |
124 |
freewrapper(newhandle->username); |
freewrapper(newhandle->username); |
125 |
freewrapper(newhandle); |
freewrapper(newhandle); |
126 |
|
|
127 |
return(NULL); |
return (NULL); |
128 |
} |
} |
129 |
|
|
130 |
void internalauth_freehandle(void *h) |
void internalauth_freehandle(void *h) |
131 |
{ |
{ |
132 |
PASSWDSTRUCT *handle = (PASSWDSTRUCT *)h; |
PASSWDSTRUCT *handle = (PASSWDSTRUCT *) h; |
133 |
|
|
134 |
freewrapper(handle->udata); |
freewrapper(handle->udata); |
135 |
freewrapper(handle->username); |
freewrapper(handle->username); |
136 |
freewrapper(handle); |
freewrapper(handle); |
137 |
} |
} |
138 |
|
|
139 |
int internalauth_checkpasswd(void *h, char *password, char **errmsg) |
int internalauth_checkpasswd(void *h, |
140 |
|
char *password, |
141 |
|
char **errmsg) |
142 |
{ |
{ |
143 |
PASSWDSTRUCT *handle = (PASSWDSTRUCT *)h; |
PASSWDSTRUCT *handle = (PASSWDSTRUCT *) h; |
144 |
return(chkpassword(handle->password, password)); |
|
145 |
|
return (chkpassword(handle->password, password)); |
146 |
} |
} |
147 |
|
|
148 |
char *internalauth_gethomedir(void *h) |
char *internalauth_gethomedir(void *h) |
149 |
{ |
{ |
150 |
return(((PASSWDSTRUCT *)h)->homedir); |
return (((PASSWDSTRUCT *) h)->homedir); |
151 |
} |
} |
152 |
|
|
153 |
char *internalauth_getrootdir(void *h) |
char *internalauth_getrootdir(void *h) |
154 |
{ |
{ |
155 |
return(((PASSWDSTRUCT *)h)->rootdir); |
return (((PASSWDSTRUCT *) h)->rootdir); |
156 |
} |
} |
157 |
|
|
158 |
PERMSTRUCT internalauth_commands = |
PERMSTRUCT internalauth_commands = { |
|
{ |
|
159 |
internalauth_checkpasswd, |
internalauth_checkpasswd, |
160 |
internalauth_gethomedir, |
internalauth_gethomedir, |
161 |
internalauth_getrootdir, |
internalauth_getrootdir, |