Commit 05edceec authored by claes's avatar claes

Interface to wb_adm

parent c66bd679
......@@ -45,6 +45,8 @@ int GeUser::load( char *filename)
if ( !check_file( filename))
return USER__FILEOPEN;
strcpy( fname, filename);
fp.open( filename);
#ifndef OS_VMS
if ( !fp)
......@@ -103,8 +105,14 @@ int GeUser::load_system( ifstream& fp)
{
// Insert
SystemList *system_list = new SystemList("", 0, 0);
system_list->next = root;
SystemList *sl = root;
if ( !sl)
root = system_list;
else {
while( sl->next)
sl = sl->next;
sl->next = system_list;
}
system_list->load( fp);
return 1;
}
......@@ -164,11 +172,14 @@ int GeUser::remove_system( char *name)
}
SystemList *sl = find_system( sn);
if ( !sl)
{
if ( !sl) {
delete sn;
return USER__NOSUCHSYSTEM;
}
if ( sl->childlist || sl->userlist) {
delete sn;
return USER__SYSTEMNOTEMPTY;
}
SystemName *parent = sn->parent();
if ( !parent)
......@@ -529,8 +540,14 @@ int SystemList::load_user( ifstream& fp)
{
// Insert
UserList *user_list = new UserList("", "", 0);
user_list->next = (UserList *) userlist;
userlist = (void *) user_list;
UserList *ul = userlist;
if ( !ul)
userlist = user_list;
else {
while( ul->next)
ul = ul->next;
ul->next = user_list;
}
user_list->load( fp);
return 1;
}
......@@ -539,8 +556,14 @@ int SystemList::load_system( ifstream& fp)
{
// Insert
SystemList *system_list = new SystemList("", 0, 0);
system_list->next = childlist;
SystemList *sl = childlist;
if ( !sl)
childlist = system_list;
else {
while ( sl->next)
sl = sl->next;
sl->next = system_list;
}
system_list->load( fp);
return 1;
}
......@@ -640,8 +663,14 @@ int SystemList::add_user( char *user, char *password, unsigned int priv)
if ( ul) return USER__USERALREXIST;
ul = new UserList( user, password, priv);
ul->next = (UserList *) userlist;
userlist = (void *) ul;
UserList *u = userlist;
if ( !u)
userlist = ul;
else {
while( u->next)
u = u->next;
u->next = ul;
}
return USER__SUCCESS;
}
......@@ -654,8 +683,14 @@ int SystemList::add_system( SystemName *name, unsigned int attributes)
if ( sl) return USER__SYSTEMALREXIST;
sl = new SystemList( name->segment(level+1), level + 1, attributes);
sl->next = childlist;
SystemList *s = childlist;
if ( !s)
childlist = sl;
else {
while( s->next)
s = s->next;
s->next = sl;
}
return USER__SUCCESS;
}
......@@ -917,6 +952,9 @@ char *GeUser::get_status( int sts)
case USER__SYSTEMALREXIST :
strcpy( str, "System already exist");
break;
case USER__SYSTEMNOTEMPTY :
strcpy( str, "System is not empty");
break;
default :
strcpy( str, "Undefined message");
}
......@@ -1002,3 +1040,86 @@ void GeUser::dev_priv_to_string( unsigned int priv, char *str, int size)
strncpy( str, buff, size);
str[size-1] = 0;
}
SystemList *GeUser::get_system( UserList *user)
{
SystemList *sl = root;
while( sl) {
UserList *ul = sl->userlist;
while ( ul) {
if ( ul == user)
return sl;
ul = ul->next;
}
SystemList *found_sl = get_system_child( sl, user);
if ( found_sl)
return found_sl;
sl = sl->next;
}
return 0;
}
SystemList *GeUser::get_system_child( SystemList *system, UserList *user)
{
SystemList *sl = system->childlist;
while( sl) {
UserList *ul = sl->userlist;
while ( ul) {
if ( ul == user)
return sl;
ul = ul->next;
}
SystemList *found_sl = get_system_child( sl, user);
if ( found_sl)
return found_sl;
sl = sl->next;
}
return 0;
}
bool GeUser::get_system_name( SystemList *system, char *name)
{
SystemList *sl = root;
while( sl) {
if ( sl == system) {
strcpy( name, sl->name);
return true;
}
if ( get_system_name_child( sl, system, name)) {
char tmp[256];
strcpy( tmp, name);
strcpy( name, sl->name);
strcat( name, ".");
strcat( name, tmp);
return true;
}
sl = sl->next;
}
return false;
}
bool GeUser::get_system_name_child( SystemList *s, SystemList *system, char *name)
{
SystemList *sl = s->childlist;
while( sl) {
if ( sl == system) {
strcpy( name, sl->name);
return true;
}
if ( get_system_name_child( sl, system, name)) {
char tmp[256];
strcpy( tmp, name);
strcpy( name, sl->name);
strcat( name, ".");
strcat( name, tmp);
return true;
}
sl = sl->next;
}
return false;
}
......@@ -56,7 +56,14 @@ class SystemName {
};
class UserList;
class GeUser;
class SystemList {
friend class GeUser;
friend class UserList;
public:
SystemList( char *sl_name, int sl_level,
unsigned int sl_attributes) :
......@@ -65,13 +72,17 @@ class SystemList {
{
strcpy( name, sl_name);
};
private:
char name[40];
int level;
unsigned long attributes;
SystemList *next;
SystemList *childlist;
void *userlist;
UserList *userlist;
public:
int load( ifstream& fp);
void save( ofstream& fp);
void print();
......@@ -86,10 +97,19 @@ class SystemList {
int remove_system( SystemList *sys);
void modify( unsigned int attributes);
void get_data( unsigned int *attributes);
SystemList *first_system() { return childlist;}
SystemList *next_system() { return next;}
UserList *first_user() { return userlist;}
char *get_name() { return name;}
unsigned long get_attributes() { return attributes;}
~SystemList();
};
class UserList {
friend class SystemList;
friend class GeUser;
public:
UserList( char *ul_name, char *ul_password, unsigned int ul_priv) :
priv(ul_priv), next(NULL)
......@@ -97,34 +117,54 @@ class UserList {
strcpy( name, ul_name);
strcpy( password, ul_password);
};
private:
char name[40];
char password[40];
unsigned long priv;
UserList *next;
int load( ifstream& fp);
void save( ofstream& fp);
void print();
void print_all();
char *crypt( char *str);
unsigned long crypt( unsigned long i);
char *decrypt( char *str);
unsigned long decrypt( unsigned long i);
public:
int load( ifstream& fp);
void save( ofstream& fp);
void print();
void print_all();
void modify( char *password, unsigned int priv);
int check_password( char *password);
void get_data( char *password, unsigned int *priv);
UserList *next_user() { return next;}
char *get_name() { return name;}
unsigned long get_priv() { return priv;}
};
class GeUser {
friend class SystemList;
friend class UserList;
public:
GeUser() : root(NULL) { strcpy( version, ""); };
GeUser() : root(NULL) { strcpy( version, ""); strcpy( fname, "");}
~GeUser();
private:
SystemList *root;
SystemList *last_system;
char version[20];
char fname[256];
bool get_system_name_child( SystemList *s, SystemList *system, char *name);
SystemList *GeUser::get_system_child( SystemList *system, UserList *user);
public:
int load( char *filename);
int save() { return save( fname);}
int save( char *filename);
int load_system( ifstream& fp);
void print();
......@@ -146,6 +186,9 @@ class GeUser {
int get_user_priv( char *system, char *user,
unsigned int *priv);
char *get_status( int sts);
SystemList *root_system() { return root;}
SystemList *get_system( UserList *user);
bool get_system_name( SystemList *system, char *name);
static void priv_to_string( unsigned int priv, char *str, int size);
static void rt_priv_to_string( unsigned int priv, char *str, int size);
static void dev_priv_to_string( unsigned int priv, char *str, int size);
......@@ -158,3 +201,9 @@ class GeUser {
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment