3c2848 | 2000-08-28 | Johan Sundström | | #include <module.h>
inherit "module";
constant cvs_version = "$Id: auth.pike,v 1.1 2000/08/28 16:05:26 jhs Exp $";
constant module_type = MODULE_AUTH;
constant module_name = "RefDoc for MODULE_AUTH";
constant module_doc = #"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 your
passwords. 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, "Users and Passwords",
"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 user, 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 });
}
|