|
version 1.1.2.2, 2012/09/18 08:44:19
|
version 1.8, 2025/01/31 00:03:15
|
|
Line 12 terms:
|
Line 12 terms:
|
| All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
|
| Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 | Copyright 2004 - 2024 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
|
| Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
|
Line 48 SUCH DAMAGE.
|
Line 48 SUCH DAMAGE.
|
| |
|
| |
|
| #include <time.h> |
#include <time.h> |
| |
#include <sys/types.h> |
| |
#include <elwix.h> |
| |
|
| |
|
| |
#define PWD_CRIT_NAME 0 |
| |
#define PWD_CRIT_UID 1 |
| |
#define PWD_CRIT_GID 2 |
| |
|
| |
|
| struct tagAcctDB { |
struct tagAcctDB { |
| unsigned short db_ver; |
unsigned short db_ver; |
| unsigned char db_lock; |
unsigned char db_lock; |
|
Line 62 struct tagAcctDB {
|
Line 69 struct tagAcctDB {
|
| uint64_t db_since; |
uint64_t db_since; |
| |
|
| int db_h; /* optional */ |
int db_h; /* optional */ |
| } __packed; | } __attribute__((packed)); |
| |
|
| /* Search callback function, compare to match argument to record match ... |
/* Search callback function, compare to match argument to record match ... |
| * (return: -1 error, 0 not match or 1 match) |
* (return: -1 error, 0 not match or 1 match) |
|
Line 71 typedef int (*cb_acct_f)(void * /*current db_record*/,
|
Line 78 typedef int (*cb_acct_f)(void * /*current db_record*/,
|
| |
|
| |
|
| struct tagUser { |
struct tagUser { |
| |
int usr_fields; |
| |
|
| ait_val_t usr_name; |
ait_val_t usr_name; |
| ait_val_t usr_pass; |
ait_val_t usr_pass; |
| ait_val_t usr_uid; |
ait_val_t usr_uid; |
|
Line 82 struct tagUser {
|
Line 91 struct tagUser {
|
| ait_val_t usr_home; |
ait_val_t usr_home; |
| ait_val_t usr_shell; |
ait_val_t usr_shell; |
| |
|
| SLIST_ENTRY(tagCfg) usr_next; | SLIST_ENTRY(tagUser) usr_next; |
| RB_ENTRY(tagCfg) usr_node; | RB_ENTRY(tagUser) usr_node; |
| }; |
}; |
| typedef struct tagPWD { |
typedef struct tagPWD { |
| pthread_mutex_t pwd_mtx; |
pthread_mutex_t pwd_mtx; |
|
Line 109 typedef enum { ALL = -1,
|
Line 118 typedef enum { ALL = -1,
|
| Shell |
Shell |
| } passwd_attr_t; |
} passwd_attr_t; |
| |
|
| |
#ifdef __cplusplus |
| |
extern "C" { |
| |
#endif |
| |
|
| /* |
/* |
| * cfgInitPasswd() - Init password root |
* cfgInitPasswd() - Init password root |
| * |
* |
| * @pwd = Password root | * return: NULL error or !=NULL allocated password root |
| * return: -1 error or 0 ok | |
| */ |
*/ |
| int cfgInitPasswd(pwd_root_t * __restrict pwd); | pwd_root_t *cfgInitPasswd(); |
| /* |
/* |
| |
* cfgEndPasswd() - Free resources & password root |
| |
* |
| |
* @ppwd = Password root |
| |
* return: none |
| |
*/ |
| |
void cfgEndPasswd(pwd_root_t **ppwd); |
| |
/* |
| * cfgLoadPasswd() - Load passwords from file |
* cfgLoadPasswd() - Load passwords from file |
| * |
* |
| * @pwdName = Passwords filename |
* @pwdName = Passwords filename |
|
Line 148 void cfgUnloadPasswd(pwd_root_t * __restrict pwd);
|
Line 166 void cfgUnloadPasswd(pwd_root_t * __restrict pwd);
|
| */ |
*/ |
| int cfgCreatePasswd(const char *pwdName, pwd_root_t * __restrict pwd); |
int cfgCreatePasswd(const char *pwdName, pwd_root_t * __restrict pwd); |
| |
|
| #if 0 |
|
| /* |
/* |
| * ReadPasswd() Read from file and add new item to user array | * cfgReadPasswd() - Read file and add new item at password root |
| * @f = file resource | * |
| * @ppwd = User array | * @f = File resource |
| * return: 0 ok; -1 error:: can`t allocate memory | * @pwd = Password root |
| */ | * return: -1 error or 0 ok |
| int ReadPasswd(FILE *f, passwd_t * __restrict ppwd); | */ |
| | int cfgReadPasswd(FILE *f, pwd_root_t * __restrict pwd); |
| /* |
/* |
| * WritePasswd() Write to file from items in array | * cfgWritePasswd() - Write passwords from memory |
| * @f = file resource | * |
| * @ppwd = User array | * @f = File handle |
| * return: 0 ok; -1 error:: can`t write to file | * @pwd = Password root |
| */ | * return: -1 error or 0 ok |
| int WritePasswd(FILE *f, passwd_t * __restrict ppwd); | */ |
| int cfgWritePasswd(FILE *f, pwd_root_t * __restrict pwd); |
| |
| /* |
/* |
| * pwdCleanStr() Free strings in passwd_t value | * cfgConcatPasswd() - Concat two password roots into one |
| * @pwd = User object | * |
| * return: none | * @pwd = Password root |
| */ | * @add_pwd = Concated password root will be destroy after merge |
| inline void pwdCleanStr(passwd_t __restrict pwd); | * return: -1 error or 0 ok |
| /* | */ |
| * pwdFreeValue() Free passwd_t value | int cfgConcatPasswd(pwd_root_t * __restrict pwd, pwd_root_t * __restrict add_pwd); |
| * @ppwd = User object | |
| * @idx = Index of attribute, if ALL == idx is free all structure | |
| * return: 0 ok, -1 error | |
| */ | |
| inline int pwdFreeValue(passwd_t * __restrict ppwd, passwd_attr_t idx); | |
| /* | |
| * pwdSetValue() Set passwd_t value | |
| * @ppwd = User object | |
| * @idx = Index of attribute, if ALL == idx clean User object and set username! | |
| * @Value = Value to set | |
| * return: number of fields in passwd_t; -1 error:: can`t set passwd_t | |
| */ | |
| inline int pwdSetValue(passwd_t * __restrict ppwd, passwd_attr_t idx, unsigned char *Value); | |
| /* | |
| * pwdGetValue() Get passwd_t value | |
| * @pwd = User object | |
| * @idx = Index of attribute, if ALL == idx is error! | |
| * @Value = Value to get | |
| * @valLen = Size of Value string | |
| * return: number of fields in passwd_t; -1 error:: can`t get passwd_t | |
| */ | |
| inline int pwdGetValue(passwd_t __restrict pwd, passwd_attr_t idx, unsigned char *Value, int valLen); | |
| |
|
| |
|
| /* |
/* |
| * pwd_FindAttribute() Find by attribute position in user array | * cfgAuthPasswd() - Authenticate user against passwords db |
| * @pwd = User array | * |
| * @idx = Index of attribute, if ALL == idx return number of user array elements | * @pwd = Password root |
| * @csAttr = User attribute | * @csName = Username |
| * return: 0 not found item; -1 error: null parameters; >0 position in array + 1 | * @csPass = Password |
| */ | * return: =NULL deny or !=NULL allow |
| inline int pwd_FindAttribute(passwd_t __restrict pwd, passwd_attr_t idx, const unsigned char *csAttr); | */ |
| /* | const struct tagUser *cfgAuthPasswd(pwd_root_t * __restrict pwd, |
| * pwd_SetAttribute() Set user in array or add new user if not exists | const char *csName, const char *csPass); |
| * @ppwd = User array | |
| * @idx = Index of attribute to set | |
| * @val = User structure for setup | |
| * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item | |
| */ | |
| int pwd_SetAttribute(passwd_t * __restrict ppwd, passwd_attr_t idx, passwd_t val); | |
| /* | |
| * pwd_GetAttribute() Get user from array, set username in val | |
| * @pwd = User array | |
| * @idx = Index of attribute to get, if idx == ALL return full element items | |
| * @val = User structure | |
| * return: 0 not found, -1 error; >0 found at position in array + 1 | |
| */ | |
| int pwd_GetAttribute(passwd_t __restrict pwd, passwd_attr_t idx, passwd_t val); | |
| /* | |
| * pwd_UnsetAttribute() Unset user from array and free resources! | |
| * @ppwd = User array | |
| * @idx = Index of attribute to unset, if idx == ALL unset(delete) all items in element | |
| * @val = User structure | |
| * return: 0 item not found, -1 error: null parameters; >0 number of elements leave in array | |
| */ | |
| int pwd_UnsetAttribute(passwd_t * __restrict ppwd, passwd_attr_t idx, passwd_t val); | |
| /* | |
| * pwd_Authenticate() Authenticate user, set username and password in val | |
| * @pwd = User array | |
| * @val = User structure for authenticate, set username & password | |
| after authentication fill other fields if exists | |
| * return: 0 not found, -1 error; >0 found at position in array + 1 | |
| */ | |
| int pwd_Authenticate(passwd_t __restrict pwd, passwd_t val); | |
| |
|
| |
|
| /* |
/* |
| * pwd_openAcct() Open accounting aDat binary database | * cfg_findPasswdBy() - Find user by criteria position in list |
| * @csName - DB name | * |
| * @minR - Minimum records in database | * @pwd = Password root |
| * @maxR - Maximum records in database(round-robin db), if 0 unlimited grow | * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID|PWD_CRIT_GID] |
| * @recSize - Size of record element | * @arg1 = Username | UID | GID |
| * @wrapR - If maxR >0 give ability to wrap round-robin db | * return: NULL not found item or error and !=NULL found item |
| * return: NULL error or !=NULL opened db handle | |
| */ |
*/ |
| struct tagAcctDB *pwd_openAcct(const char *csName, unsigned int minR, unsigned int maxR, | const struct tagUser *cfg_findPasswdBy(pwd_root_t * __restrict pwd, int criteria, ...); |
| size_t recSize, unsigned char wrapR); | |
| /* |
/* |
| * pwd_closeAcct() Close accounting aDat binary database | * cfg_unsetPasswd() - Unset item from passwords and free resources |
| * @db - DB handle | * |
| * return: none | * @pwd = Password root |
| | * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID] |
| | * @arg1 = Username | UID |
| | * return: 0 item not found, -1 error or 1 removed item |
| */ |
*/ |
| void pwd_closeAcct(struct tagAcctDB ** __restrict db); | int cfg_unsetPasswd(pwd_root_t * __restrict pwd, int criteria, ...); |
| /* |
/* |
| * pwd_writeAcct() Write accounting record to aDat binary database | * cfg_setPasswd() - Set item in password or adding new item if not exists |
| * @db - DB handle | * |
| * @posR - At position number, if db is unlimited grow (-1) write at last free record | * @cfg = Password root |
| * @rec - Record data | * @fields = Following parameters are continuous to certain field |
| * return: -1 error or 0 ok | * @csName = Username |
| | * @arg1 = Password |
| | * @arg2 = UID |
| | * @arg3 = GID |
| | * @arg4 = Login class |
| | * @arg5 = Chage date |
| | * @arg6 = Expire date |
| | * @arg7 = Realm |
| | * @arg8 = Home dir |
| | * @arg9 = Shell |
| | * return: 0 nothing changed, -1 error, 1 found and updated item or 2 added new item |
| */ |
*/ |
| int pwd_writeAcct(struct tagAcctDB * __restrict db, unsigned int posR, void *rec); | int cfg_setPasswd(pwd_root_t * __restrict pwd, passwd_attr_t fields, const char *csName, ...); |
| /* |
/* |
| * pwd_readAcct() Read accounting record from aDat binary database | * cfg_getPasswd() - Get item from passwords and return structure from it |
| * @db - DB handle | * |
| * @posR - From position number | * @pwd = Password root |
| * @rec - Record data buffer | * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID] |
| * @recsize - Record data buffer size | * @arg1 = Username | UID |
| * return: -1 error or 0 ok | * return: NULL item not found, !=NULL structure found |
| */ |
*/ |
| int pwd_readAcct(struct tagAcctDB * __restrict db, unsigned int posR, void *rec, int recsize); | const struct tagUser *cfg_getPasswd(pwd_root_t * __restrict pwd, int criteria, ...); |
| |
|
| /* | #ifdef __cplusplus |
| * pwd_findAcct() Find accounting record from aDat binary database | } |
| * @db - DB handle | |
| * @from - From position | |
| * @to - To position, if 0 search to end-of-file | |
| * @func - Check for match callback function | |
| * @arg - Argument passthrough to callback as argument for search | |
| * return: -1 error, 0 not found or >1 founded at position! (p.s:start from 1) | |
| */ | |
| int64_t pwd_findAcct(struct tagAcctDB * __restrict db, unsigned int from, unsigned int to, | |
| cb_acct_f func, void *arg); | |
| #endif |
#endif |
| |
|
| |
|
| #endif |
#endif |