Commit 05edceec authored by claes's avatar claes

Interface to wb_adm

parent c66bd679
...@@ -45,6 +45,8 @@ int GeUser::load( char *filename) ...@@ -45,6 +45,8 @@ int GeUser::load( char *filename)
if ( !check_file( filename)) if ( !check_file( filename))
return USER__FILEOPEN; return USER__FILEOPEN;
strcpy( fname, filename);
fp.open( filename); fp.open( filename);
#ifndef OS_VMS #ifndef OS_VMS
if ( !fp) if ( !fp)
...@@ -103,8 +105,14 @@ int GeUser::load_system( ifstream& fp) ...@@ -103,8 +105,14 @@ int GeUser::load_system( ifstream& fp)
{ {
// Insert // Insert
SystemList *system_list = new SystemList("", 0, 0); SystemList *system_list = new SystemList("", 0, 0);
system_list->next = root; SystemList *sl = root;
root = system_list; if ( !sl)
root = system_list;
else {
while( sl->next)
sl = sl->next;
sl->next = system_list;
}
system_list->load( fp); system_list->load( fp);
return 1; return 1;
} }
...@@ -164,11 +172,14 @@ int GeUser::remove_system( char *name) ...@@ -164,11 +172,14 @@ int GeUser::remove_system( char *name)
} }
SystemList *sl = find_system( sn); SystemList *sl = find_system( sn);
if ( !sl) if ( !sl) {
{
delete sn; delete sn;
return USER__NOSUCHSYSTEM; return USER__NOSUCHSYSTEM;
} }
if ( sl->childlist || sl->userlist) {
delete sn;
return USER__SYSTEMNOTEMPTY;
}
SystemName *parent = sn->parent(); SystemName *parent = sn->parent();
if ( !parent) if ( !parent)
...@@ -529,8 +540,14 @@ int SystemList::load_user( ifstream& fp) ...@@ -529,8 +540,14 @@ int SystemList::load_user( ifstream& fp)
{ {
// Insert // Insert
UserList *user_list = new UserList("", "", 0); UserList *user_list = new UserList("", "", 0);
user_list->next = (UserList *) userlist; UserList *ul = userlist;
userlist = (void *) user_list; if ( !ul)
userlist = user_list;
else {
while( ul->next)
ul = ul->next;
ul->next = user_list;
}
user_list->load( fp); user_list->load( fp);
return 1; return 1;
} }
...@@ -539,8 +556,14 @@ int SystemList::load_system( ifstream& fp) ...@@ -539,8 +556,14 @@ int SystemList::load_system( ifstream& fp)
{ {
// Insert // Insert
SystemList *system_list = new SystemList("", 0, 0); SystemList *system_list = new SystemList("", 0, 0);
system_list->next = childlist; SystemList *sl = childlist;
childlist = system_list; if ( !sl)
childlist = system_list;
else {
while ( sl->next)
sl = sl->next;
sl->next = system_list;
}
system_list->load( fp); system_list->load( fp);
return 1; return 1;
} }
...@@ -640,8 +663,14 @@ int SystemList::add_user( char *user, char *password, unsigned int priv) ...@@ -640,8 +663,14 @@ int SystemList::add_user( char *user, char *password, unsigned int priv)
if ( ul) return USER__USERALREXIST; if ( ul) return USER__USERALREXIST;
ul = new UserList( user, password, priv); ul = new UserList( user, password, priv);
ul->next = (UserList *) userlist; UserList *u = userlist;
userlist = (void *) ul; if ( !u)
userlist = ul;
else {
while( u->next)
u = u->next;
u->next = ul;
}
return USER__SUCCESS; return USER__SUCCESS;
} }
...@@ -654,8 +683,14 @@ int SystemList::add_system( SystemName *name, unsigned int attributes) ...@@ -654,8 +683,14 @@ int SystemList::add_system( SystemName *name, unsigned int attributes)
if ( sl) return USER__SYSTEMALREXIST; if ( sl) return USER__SYSTEMALREXIST;
sl = new SystemList( name->segment(level+1), level + 1, attributes); sl = new SystemList( name->segment(level+1), level + 1, attributes);
sl->next = childlist; SystemList *s = childlist;
childlist = sl; if ( !s)
childlist = sl;
else {
while( s->next)
s = s->next;
s->next = sl;
}
return USER__SUCCESS; return USER__SUCCESS;
} }
...@@ -917,6 +952,9 @@ char *GeUser::get_status( int sts) ...@@ -917,6 +952,9 @@ char *GeUser::get_status( int sts)
case USER__SYSTEMALREXIST : case USER__SYSTEMALREXIST :
strcpy( str, "System already exist"); strcpy( str, "System already exist");
break; break;
case USER__SYSTEMNOTEMPTY :
strcpy( str, "System is not empty");
break;
default : default :
strcpy( str, "Undefined message"); strcpy( str, "Undefined message");
} }
...@@ -1002,3 +1040,86 @@ void GeUser::dev_priv_to_string( unsigned int priv, char *str, int size) ...@@ -1002,3 +1040,86 @@ void GeUser::dev_priv_to_string( unsigned int priv, char *str, int size)
strncpy( str, buff, size); strncpy( str, buff, size);
str[size-1] = 0; 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 { ...@@ -56,7 +56,14 @@ class SystemName {
}; };
class UserList;
class GeUser;
class SystemList { class SystemList {
friend class GeUser;
friend class UserList;
public: public:
SystemList( char *sl_name, int sl_level, SystemList( char *sl_name, int sl_level,
unsigned int sl_attributes) : unsigned int sl_attributes) :
...@@ -65,13 +72,17 @@ class SystemList { ...@@ -65,13 +72,17 @@ class SystemList {
{ {
strcpy( name, sl_name); strcpy( name, sl_name);
}; };
private:
char name[40]; char name[40];
int level; int level;
unsigned long attributes; unsigned long attributes;
SystemList *next; SystemList *next;
SystemList *childlist; SystemList *childlist;
void *userlist; UserList *userlist;
public:
int load( ifstream& fp); int load( ifstream& fp);
void save( ofstream& fp); void save( ofstream& fp);
void print(); void print();
...@@ -86,10 +97,19 @@ class SystemList { ...@@ -86,10 +97,19 @@ class SystemList {
int remove_system( SystemList *sys); int remove_system( SystemList *sys);
void modify( unsigned int attributes); void modify( unsigned int attributes);
void get_data( 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(); ~SystemList();
}; };
class UserList { class UserList {
friend class SystemList;
friend class GeUser;
public: public:
UserList( char *ul_name, char *ul_password, unsigned int ul_priv) : UserList( char *ul_name, char *ul_password, unsigned int ul_priv) :
priv(ul_priv), next(NULL) priv(ul_priv), next(NULL)
...@@ -97,34 +117,54 @@ class UserList { ...@@ -97,34 +117,54 @@ class UserList {
strcpy( name, ul_name); strcpy( name, ul_name);
strcpy( password, ul_password); strcpy( password, ul_password);
}; };
private:
char name[40]; char name[40];
char password[40]; char password[40];
unsigned long priv; unsigned long priv;
UserList *next; UserList *next;
int load( ifstream& fp);
void save( ofstream& fp);
void print();
void print_all();
char *crypt( char *str); char *crypt( char *str);
unsigned long crypt( unsigned long i); unsigned long crypt( unsigned long i);
char *decrypt( char *str); char *decrypt( char *str);
unsigned long decrypt( unsigned long i); 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); void modify( char *password, unsigned int priv);
int check_password( char *password); int check_password( char *password);
void get_data( char *password, unsigned int *priv); 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 { class GeUser {
friend class SystemList;
friend class UserList;
public: public:
GeUser() : root(NULL) { strcpy( version, ""); }; GeUser() : root(NULL) { strcpy( version, ""); strcpy( fname, "");}
~GeUser(); ~GeUser();
private:
SystemList *root; SystemList *root;
SystemList *last_system; SystemList *last_system;
char version[20]; 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 load( char *filename);
int save() { return save( fname);}
int save( char *filename); int save( char *filename);
int load_system( ifstream& fp); int load_system( ifstream& fp);
void print(); void print();
...@@ -146,6 +186,9 @@ class GeUser { ...@@ -146,6 +186,9 @@ class GeUser {
int get_user_priv( char *system, char *user, int get_user_priv( char *system, char *user,
unsigned int *priv); unsigned int *priv);
char *get_status( int sts); 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 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 rt_priv_to_string( unsigned int priv, char *str, int size);
static void dev_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 { ...@@ -158,3 +201,9 @@ class GeUser {
#endif #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