Commit 278dab96 authored by claes's avatar claes

New user database layout and new encryption of password

parent 57b2dd6f
This diff is collapsed.
/** /**
* Proview $Id: co_user.h,v 1.5 2005-09-20 13:21:45 claes Exp $ * Proview $Id: co_user.h,v 1.6 2008-06-24 07:04:33 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005 SSAB Oxelsund AB.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -26,12 +26,15 @@ ...@@ -26,12 +26,15 @@
#include <fstream.h> #include <fstream.h>
#include <string.h> #include <string.h>
#include "pwr.h"
#if defined __cplusplus #if defined __cplusplus
extern "C" { extern "C" {
#endif #endif
#define user_cFilename "pwra_db:pwr_user.dat" #define user_cFilename "pwra_db:pwr_user2.dat"
#define user_cVersion "V1.0.0" #define user_cVersion "V2.0.0"
#define user_cNId ((pwr_tOix)(~0))
#define FSPACE " " #define FSPACE " "
typedef enum { typedef enum {
...@@ -40,18 +43,27 @@ typedef enum { ...@@ -40,18 +43,27 @@ typedef enum {
user_eData_User = 3, user_eData_User = 3,
user_eData_End = 99, user_eData_End = 99,
user_eData_GeUserVersion = 100, user_eData_GeUserVersion = 100,
user_eData_GeNextId = 101,
user_eData_SystemName = 200, user_eData_SystemName = 200,
user_eData_SystemLevel = 201, user_eData_SystemLevel = 201,
user_eData_SystemAttributes = 202, user_eData_SystemAttributes = 202,
user_eData_SystemId = 203,
user_eData_SystemDescription = 204,
user_eData_UserName = 300, user_eData_UserName = 300,
user_eData_UserPassword = 301, user_eData_UserPassword = 301,
user_eData_UserPrivilege = 302 user_eData_UserPrivilege = 302,
} user_eData; user_eData_UserId = 303,
user_eData_UserDescription = 304,
user_eData_UserFullName = 305,
user_eData_UserPhone = 306,
user_eData_UserEmail = 307,
user_eData_UserSms = 308
} user_eData;
typedef enum { typedef enum {
user_mSystemAttr_UserInherit = 1 user_mSystemAttr_UserInherit = 1
} user_mSystemAttr; } user_mSystemAttr;
class SystemName { class SystemName {
public: public:
...@@ -79,19 +91,24 @@ class SystemList { ...@@ -79,19 +91,24 @@ class SystemList {
friend class UserList; friend class UserList;
public: public:
SystemList( char *sl_name, int sl_level, SystemList( pwr_tOix sl_id, char *sl_name, int sl_level, unsigned int sl_attributes, char *sl_descr) :
unsigned int sl_attributes) : level(sl_level), attributes( sl_attributes), id(sl_id),
level(sl_level), attributes( sl_attributes),
next(0), childlist(0), userlist(0) next(0), childlist(0), userlist(0)
{ {
strcpy( name, sl_name); strcpy( name, sl_name);
if ( sl_descr)
strncpy( description, sl_descr, sizeof(description));
else
strcpy( description, "");
}; };
private: private:
char name[40]; pwr_tObjName name;
int level; int level;
unsigned long attributes; pwr_tMask attributes;
pwr_tOix id;
pwr_tString80 description;
SystemList *next; SystemList *next;
SystemList *childlist; SystemList *childlist;
UserList *userlist; UserList *userlist;
...@@ -99,18 +116,18 @@ class SystemList { ...@@ -99,18 +116,18 @@ class SystemList {
public: public:
int load( ifstream& fp); int load( ifstream& fp);
void save( ofstream& fp); void save( ofstream& fp);
void print(); void print( int brief);
void print_all(); void print_all( int brief);
void *find_user( char *name); void *find_user( char *name);
int add_user( char *user, char *password, unsigned int priv); int add_user( pwr_tOix ident, char *user, char *password, pwr_tMask priv, char *fullname, char *descr, char *phone, char *email, char *sms);
int add_system( SystemName *name, unsigned int attributes); int add_system( pwr_tOix ident, SystemName *name, pwr_tMask attributes, char *descr);
int load_system( ifstream& fp); int load_system( ifstream& fp);
int load_user( ifstream& fp); int load_user( ifstream& fp);
SystemList *find_system( SystemName *name); SystemList *find_system( SystemName *name);
int remove_user( char *user); int remove_user( char *user);
int remove_system( SystemList *sys); int remove_system( SystemList *sys);
void modify( unsigned int attributes); void modify( pwr_tMask attributes, char *description);
void get_data( unsigned int *attributes); void get_data( pwr_tMask *attributes, pwr_tOix *id, char *description);
SystemList *first_system() { return childlist;} SystemList *first_system() { return childlist;}
SystemList *next_system() { return next;} SystemList *next_system() { return next;}
UserList *first_user() { return userlist;} UserList *first_user() { return userlist;}
...@@ -125,36 +142,64 @@ class UserList { ...@@ -125,36 +142,64 @@ class UserList {
friend class GeUser; friend class GeUser;
public: public:
UserList( char *ul_name, char *ul_password, unsigned int ul_priv) : UserList( pwr_tOix ul_id, char *ul_name, char *ul_password, pwr_tMask ul_priv, char *ul_fullname, char *ul_description,
priv(ul_priv), next(NULL) char *ul_email, char *ul_phone, char *ul_sms) :
priv(ul_priv), id(ul_id), next(NULL)
{ {
strcpy( name, ul_name); strcpy( name, ul_name);
strcpy( password, ul_password); strcpy( password, ul_password);
if ( ul_fullname)
strncpy( fullname, ul_fullname, sizeof(fullname));
else
strcpy( fullname, "");
if ( ul_description)
strncpy( description, ul_description, sizeof(description));
else
strcpy( description, "");
if ( ul_email)
strncpy( email, ul_email, sizeof(email));
else
strcpy( email, "");
if ( ul_phone)
strncpy( phone, ul_phone, sizeof(phone));
else
strcpy( phone, "");
if ( ul_sms)
strncpy( sms, ul_sms, sizeof(sms));
else
strcpy( sms, "");
}; };
private: private:
char name[40]; pwr_tObjName name;
char password[40]; char password[40];
unsigned long priv; pwr_tMask priv;
pwr_tOix id;
pwr_tString80 fullname;
pwr_tString80 description;
pwr_tString80 email;
pwr_tString40 phone;
pwr_tString40 sms;
UserList *next; UserList *next;
char *crypt( char *str); unsigned long icrypt( unsigned long i);
unsigned long crypt( unsigned long i); unsigned long idecrypt( unsigned long i);
char *decrypt( char *str);
unsigned long decrypt( unsigned long i);
public: public:
int load( ifstream& fp); int load( ifstream& fp);
void save( ofstream& fp); void save( ofstream& fp);
void print(); void print( int brief);
void print_all(); void print_all( int brief);
void modify( char *password, unsigned int priv); void modify( char *password, pwr_tMask priv, char *fullname, char *description,
char *email, char *phone, char *sms);
int check_password( char *password); int check_password( char *password);
void get_data( char *password, unsigned int *priv); void get_data( char *password, pwr_tMask *priv, pwr_tOix *id, char *fullname, char *description,
char *email, char *phone, char *sms);
UserList *next_user() { return next;} UserList *next_user() { return next;}
char *get_name() { return name;} char *get_name() { return name;}
unsigned long get_priv() { return priv;} unsigned long get_priv() { return priv;}
static char *pwcrypt( char *str);
}; };
class GeUser { class GeUser {
...@@ -171,6 +216,7 @@ class GeUser { ...@@ -171,6 +216,7 @@ class GeUser {
SystemList *last_system; SystemList *last_system;
char version[20]; char version[20];
char fname[256]; char fname[256];
pwr_tOix next_id;
bool get_system_name_child( SystemList *s, SystemList *system, char *name); bool get_system_name_child( SystemList *s, SystemList *system, char *name);
SystemList *get_system_child( SystemList *system, UserList *user); SystemList *get_system_child( SystemList *system, UserList *user);
...@@ -182,19 +228,21 @@ class GeUser { ...@@ -182,19 +228,21 @@ class GeUser {
int save() { return save( fname);} 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( int brief);
void print_all(); void print_all( int brief);
SystemList *find_system( SystemName *name); SystemList *find_system( SystemName *name);
int add_system( char *name, unsigned int attributes); int add_system( char *name, unsigned int attributes, char *description, pwr_tOix id = user_cNId);
int add_user( char *system, char *user, char *password, int add_user( char *system, char *user, char *password,
unsigned int priv); unsigned int priv, char *fullname, char *description, char *email, char *phone,
char *sms, pwr_tOix id = user_cNId);
int remove_user( char *system, char *user); int remove_user( char *system, char *user);
int modify_user( char *system, char *user, char *password, int modify_user( char *system, char *user, char *password,
unsigned int priv); unsigned int priv, char *fullname, char *description, char *email, char *phone, char *sms);
int get_user_data( char *system, char *user, char *password, int get_user_data( char *system, char *user, char *password,
unsigned int *priv); pwr_tMask *priv, pwr_tOix *id, char *fullname, char *description, char *email,
int modify_system( char *system, unsigned int attributes); char *phone, char *sms);
int get_system_data( char *system, unsigned int *attributes); int modify_system( char *system, unsigned int attributes, char *description);
int get_system_data( char *system, pwr_tMask *attributes, pwr_tOix *id, char *description);
int remove_system( char *name); int remove_system( char *name);
int get_user( char *system, char *user, char *password, int get_user( char *system, char *user, char *password,
unsigned int *priv); unsigned int *priv);
...@@ -204,6 +252,7 @@ class GeUser { ...@@ -204,6 +252,7 @@ class GeUser {
SystemList *root_system() { return root;} SystemList *root_system() { return root;}
SystemList *get_system( UserList *user); SystemList *get_system( UserList *user);
bool get_system_name( SystemList *system, char *name); bool get_system_name( SystemList *system, char *name);
pwr_tOix get_next_id() { return next_id++;}
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);
......
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