--- libaitcfg/inc/aitpwd.h 2012/09/19 11:47:38 1.1.2.6 +++ libaitcfg/inc/aitpwd.h 2025/01/31 00:03:15 1.8 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitpwd.h,v 1.1.2.6 2012/09/19 11:47:38 misho Exp $ +* $Id: aitpwd.h,v 1.8 2025/01/31 00:03:15 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +Copyright 2004 - 2024 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -48,6 +48,8 @@ SUCH DAMAGE. #include +#include +#include #define PWD_CRIT_NAME 0 @@ -67,7 +69,7 @@ struct tagAcctDB { uint64_t db_since; int db_h; /* optional */ -} __packed; +} __attribute__((packed)); /* Search callback function, compare to match argument to record match ... * (return: -1 error, 0 not match or 1 match) @@ -116,15 +118,24 @@ typedef enum { ALL = -1, Shell } passwd_attr_t; +#ifdef __cplusplus +extern "C" { +#endif /* * cfgInitPasswd() - Init password root * - * @pwd = Password root - * return: -1 error or 0 ok + * return: NULL error or !=NULL allocated password root */ -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 * * @pwdName = Passwords filename @@ -186,9 +197,10 @@ int cfgConcatPasswd(pwd_root_t * __restrict pwd, pwd_r * @pwd = Password root * @csName = Username * @csPass = Password - * return: -1 error, 1 deny or 0 allow + * return: =NULL deny or !=NULL allow */ -int cfgAuthPasswd(pwd_root_t * __restrict pwd, const char *csName, const char *csPass); +const struct tagUser *cfgAuthPasswd(pwd_root_t * __restrict pwd, + const char *csName, const char *csPass); /* * cfg_findPasswdBy() - Find user by criteria position in list @@ -198,7 +210,7 @@ int cfgAuthPasswd(pwd_root_t * __restrict pwd, const c * @arg1 = Username | UID | GID * return: NULL not found item or error and !=NULL found item */ -struct tagUser *cfg_findPasswdBy(pwd_root_t * __restrict pwd, int criteria, ...); +const struct tagUser *cfg_findPasswdBy(pwd_root_t * __restrict pwd, int criteria, ...); /* * cfg_unsetPasswd() - Unset item from passwords and free resources * @@ -212,22 +224,20 @@ int cfg_unsetPasswd(pwd_root_t * __restrict pwd, int c * cfg_setPasswd() - Set item in password or adding new item if not exists * * @cfg = Password root + * @fields = Following parameters are continuous to certain field * @csName = Username - * @csPass = Password - * @uid = UID - * @gid = GID - * @Class = Login class - * @change = Chage date - * @expire = Expire date - * @csRealm = Realm - * @csHome = Home dir - * @csShell = Shell + * @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 cfg_setPasswd(pwd_root_t * __restrict pwd, const char *csName, const char *csPass, - unsigned int uid, unsigned int gid, const char *csClass, - unsigned int change, unsigned int expire, const char *csRealm, - const char *csHome, const char *csShell); +int cfg_setPasswd(pwd_root_t * __restrict pwd, passwd_attr_t fields, const char *csName, ...); /* * cfg_getPasswd() - Get item from passwords and return structure from it * @@ -236,7 +246,10 @@ int cfg_setPasswd(pwd_root_t * __restrict pwd, const c * @arg1 = Username | UID * return: NULL item not found, !=NULL structure found */ -inline const struct tagUser *cfg_getPasswd(pwd_root_t * __restrict pwd, int criteria, ...); +const struct tagUser *cfg_getPasswd(pwd_root_t * __restrict pwd, int criteria, ...); +#ifdef __cplusplus +} +#endif #endif