#include <module.h> |
inherit "module"; |
|
|
|
|
|
#define LOCALE(X,Y) _DEF_LOCALE("mod_auth",X,Y) |
|
|
|
constant cvs_version = "$Id: auth.pike,v 1.3 2000/11/24 16:50:37 per Exp $"; |
constant module_type = MODULE_AUTH; |
LocaleString module_name_locale = LOCALE(0,"RefDoc for MODULE_AUTH"); |
LocaleString module_doc_locale = |
LOCALE(0,"This module does nothing, but its inlined documentation " |
"gets imported into the roxen programmer manual. You definetely " |
"don't want to use this module in your virtual servers, since " |
"anybody with access to your admin interface or server configuration " |
" file automatically gains access to all yourpasswords. For a " |
" budding roxen programmer, the module however does show the " |
" basics of making an authentication module."); |
|
void create() |
{ |
defvar("users", Variable.StringList(({}), VAR_INITIAL, |
LOCALE(0,"Users and Passwords"), |
LOCALE(0,"A list of username:password " |
"pairs the module should grant " |
"access for.")); |
} |
|
array|int auth(array(string) auth, RequestID id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
sscanf(auth[1], "%s:%s", string user, string password); |
int successful_auth = has_value(query("users"), auth[1]); |
return ({ |
successful_auth, |
user, |
!successful_auth && password |
}); |
} |
|
string user_from_uid(int uid, RequestID|void id) |
|
{ |
return uid->digits(256); |
} |
|
array(string) userlist(RequestID|void id) |
|
{ |
return Array.transpose(map(query("users"), `/, ":"))[0][0]; |
} |
|
array(string|int) userinfo(string user, RequestID|void id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
string passwd, name = "J. Random Hacker", homedir, shell = "/bin/zsh"; |
int uid, gid; |
array(string) matching_users = glob(user + ":*", query("users")); |
if(!sizeof(matching_users)) |
return 0; |
sscanf(matching_users[0], "%*s:%s", passwd); |
sscanf(user, "%"+sizeof(user)+"c", uid); |
gid = uid; |
homedir = "/home/" + user; |
return ({ user, crypt(passwd), uid, gid, name, homedir, shell }); |
} |
|
|