|
#include <module.h> |
|
|
|
|
#define LOCALE(X,Y) _DEF_LOCALE("mod_auth",X,Y) |
|
|
|
|
inherit UserDB; |
inherit "module"; |
|
|
|
|
|
|
|
constant name = "example"; |
|
|
|
|
|
|
|
|
|
constant cvs_version="$Id: userdb_ex.pike,v 1.3 2001/10/09 18:07:50 nilsson Exp $"; |
|
LocaleString module_name = LOCALE(1,"RefDoc for MODULE_USERDB"); |
|
LocaleString module_doc = |
LOCALE(2,"This module does nothing special, it implements a simple " |
"user database with the passwords and usernames in a string list, " |
"but its inlined documentation gets imported into the Roxen " |
"programmer manual.\n" |
"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 a user database module."); |
|
|
static void create() |
|
|
|
{ |
defvar("users", Variable.StringList(({}), VAR_INITIAL, |
LOCALE(3,"Users and Passwords"), |
LOCALE(4,"A list of username:password " |
"pairs."))); |
} |
|
|
|
class ExUser |
|
|
{ |
static string id; |
static string pw; |
|
|
|
|
inherit User; |
|
|
|
|
|
static void create( string _id, string _pw ) |
|
|
{ |
id = _id; |
pw = _pw; |
::create( this_module() ); |
} |
|
string name() |
|
|
{ |
return id; |
} |
|
string real_name() |
|
|
|
{ |
return id; |
} |
|
string homedir() |
|
|
|
{ |
return "/"; |
} |
|
string crypted_password() |
|
|
{ |
return "x"; |
} |
|
int uid() |
|
{ |
return -1; |
} |
|
int gid() |
|
{ |
return -1; |
} |
|
string shell() |
|
{ |
return 0; |
} |
|
string gecos() |
|
|
{ |
return real_name(); |
} |
|
int password_authenticate(string password) |
|
|
|
|
{ |
return password == pw; |
} |
|
array(string) groups() |
|
|
{ |
|
|
return ({ "example" }); |
} |
} |
|
|
class ExGroup |
{ |
inherit Group; |
|
|
static void create() |
|
{ |
::create( this_module() ); |
} |
|
|
string name() |
|
{ |
|
return "example"; |
} |
int gid() |
|
{ |
return -1; |
} |
|
array(string) members() |
|
|
|
{ |
|
|
return ::list_users(); |
} |
} |
|
static ExGroup the_one_and_only_group = ExGroup(); |
|
|
array(string) list_users( RequestID id ) |
|
{ |
return column( map( query( "users" ), `/, ":" ), 0 ); |
} |
|
array(string) list_groups( RequestID id ) |
|
|
{ |
return ({ "example" }); |
} |
|
User find_user( string s, RequestID id ) |
|
{ |
foreach( query( "users" ), string user_line ) |
|
|
if( has_prefix( user_line, s+":" ) ) |
return ExUser( @user_line/":" ); |
return 0; |
} |
|
User find_user_from_uid( int id ) |
|
|
{ |
|
return 0; |
} |
|
Group find_group( string group ) |
|
|
{ |
|
if( group == "example" ) |
return the_one_and_only_group; |
} |
|
Group find_group_from_gid( int id ) |
|
|
{ |
|
return 0; |
} |
|
|