Annotation of libaitcfg/inc/aitpwd.h, revision 1.1.2.8

1.1.2.1   misho       1: /*************************************************************************
                      2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
                      3: *  by Michael Pounov <misho@openbsd-bg.org>
                      4: *
                      5: * $Author: misho $
1.1.2.8 ! misho       6: * $Id: aitpwd.h,v 1.1.2.7 2012/09/19 11:53:52 misho Exp $
1.1.2.1   misho       7: *
                      8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
                     15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
                     16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
                     46: #ifndef __AITPWD_H
                     47: #define __AITPWD_H
                     48: 
                     49: 
                     50: #include <time.h>
1.1.2.7   misho      51: #include <sys/types.h>
                     52: #include <aitio.h>
1.1.2.1   misho      53: 
                     54: 
1.1.2.5   misho      55: #define PWD_CRIT_NAME  0
                     56: #define PWD_CRIT_UID   1
                     57: #define PWD_CRIT_GID   2
                     58: 
                     59: 
1.1.2.1   misho      60: struct tagAcctDB {
                     61:        unsigned short  db_ver;
                     62:        unsigned char   db_lock;
                     63:        unsigned char   db_wrap;
                     64: 
                     65:        unsigned int    db_rmin;
                     66:        unsigned int    db_rmax;
                     67:        uint64_t        db_rsize;
                     68: 
                     69:        uint64_t        db_since;
                     70: 
                     71:        int             db_h;           /* optional */
                     72: } __packed;
                     73: 
                     74: /* Search callback function, compare to match argument to record match ... 
                     75:  *  (return: -1 error, 0 not match or 1 match)
                     76:  */
                     77: typedef int (*cb_acct_f)(void * /*current db_record*/, void * /*argument*/);
                     78: 
                     79: 
                     80: struct tagUser {
1.1.2.3   misho      81:        int                     usr_fields;
                     82: 
1.1.2.1   misho      83:        ait_val_t               usr_name;
                     84:        ait_val_t               usr_pass;
                     85:        ait_val_t               usr_uid;
                     86:        ait_val_t               usr_gid;
                     87:        ait_val_t               usr_class;
                     88:        ait_val_t               usr_change;
                     89:        ait_val_t               usr_expire;
                     90:        ait_val_t               usr_realm;
                     91:        ait_val_t               usr_home;
                     92:        ait_val_t               usr_shell;
                     93: 
1.1.2.3   misho      94:        SLIST_ENTRY(tagUser)    usr_next;
                     95:        RB_ENTRY(tagUser)       usr_node;
1.1.2.1   misho      96: };
1.1.2.2   misho      97: typedef struct tagPWD {
                     98:        pthread_mutex_t         pwd_mtx;
1.1.2.1   misho      99: 
1.1.2.2   misho     100:        struct tagUser          *slh_first;
                    101:        struct tagUser          *rbh_root;
                    102: } pwd_root_t;
                    103: #define PWD_LOCK(x)    pthread_mutex_lock(&(x)->pwd_mtx)
                    104: #define PWD_UNLOCK(x)  pthread_mutex_unlock(&(x)->pwd_mtx)
                    105: 
                    106: #define PWD_ISEMPTY(x) RB_EMPTY((x))
1.1.2.1   misho     107: 
                    108: typedef enum { ALL = -1, 
                    109:        Username, 
                    110:        Password, 
                    111:        UID, 
                    112:        GID, 
                    113:        Class, 
                    114:        Change, 
                    115:        Expire, 
                    116:        Realm, 
                    117:        Home, 
                    118:        Shell 
                    119: } passwd_attr_t;
                    120: 
                    121: 
                    122: /*
1.1.2.2   misho     123:  * cfgInitPasswd() - Init password root
                    124:  *
                    125:  * @pwd = Password root
                    126:  * return: -1 error or 0 ok
                    127:  */
                    128: int cfgInitPasswd(pwd_root_t * __restrict pwd);
1.1.2.1   misho     129: /*
1.1.2.2   misho     130:  * cfgLoadPasswd() - Load passwords from file
                    131:  *
                    132:  * @pwdName = Passwords filename
                    133:  * @pwd = Password root
                    134:  * return: -1 error or 0 ok
                    135:  */
                    136: int cfgLoadPasswd(const char *pwdName, pwd_root_t * __restrict pwd);
1.1.2.1   misho     137: /*
1.1.2.2   misho     138:  * cfgClearPasswd() - Clear passwords and free resources
                    139:  *
                    140:  * @cfg = Password root
                    141:  * return: none
                    142:  */
                    143: void cfgClearPasswd(pwd_root_t * __restrict pwd);
                    144: /*
                    145:  * cfgUnloadPasswd() - Unload passwords from memory and destroy resources
                    146:  *
                    147:  * @pwd = Password root
                    148:  * return: none
                    149:  */
                    150: void cfgUnloadPasswd(pwd_root_t * __restrict pwd);
                    151: /*
                    152:  * cfgCreatePasswd() - Create password file from memory
                    153:  *
                    154:  * @pwdName = New password filename
                    155:  * @pwd = Password root
                    156:  * return: -1 error or 0 ok
                    157:  */
                    158: int cfgCreatePasswd(const char *pwdName, pwd_root_t * __restrict pwd);
1.1.2.1   misho     159: 
1.1.2.3   misho     160: /*
                    161:  * cfgReadPasswd() - Read file and add new item at password root
                    162:  *
                    163:  * @f = File resource
                    164:  * @pwd = Password root
                    165:  * return: -1 error or 0 ok
                    166:  */
                    167: int cfgReadPasswd(FILE *f, pwd_root_t * __restrict pwd);
                    168: /*
                    169:  * cfgWritePasswd() - Write passwords from memory
                    170:  *
                    171:  * @f = File handle
                    172:  * @pwd = Password root
                    173:  * return: -1 error or 0 ok
                    174:  */
                    175: int cfgWritePasswd(FILE *f, pwd_root_t * __restrict pwd);
1.1.2.1   misho     176: /*
1.1.2.4   misho     177:  * cfgConcatPasswd() - Concat two password roots into one
                    178:  *
                    179:  * @pwd = Password root
                    180:  * @add_pwd = Concated password root will be destroy after merge
                    181:  * return: -1 error or 0 ok
                    182:  */
                    183: int cfgConcatPasswd(pwd_root_t * __restrict pwd, pwd_root_t * __restrict add_pwd);
1.1.2.1   misho     184: 
1.1.2.5   misho     185: /*
1.1.2.6   misho     186:  * cfgAuthPasswd() - Authenticate user against passwords db
                    187:  *
                    188:  * @pwd = Password root
                    189:  * @csName = Username
                    190:  * @csPass = Password
                    191:  * return: -1 error, 1 deny or 0 allow
                    192:  */
                    193: int cfgAuthPasswd(pwd_root_t * __restrict pwd, const char *csName, const char *csPass);
                    194: 
                    195: /*
1.1.2.5   misho     196:  * cfg_findPasswdBy() - Find user by criteria position in list
                    197:  *
                    198:  * @pwd = Password root
                    199:  * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID|PWD_CRIT_GID]
                    200:  * @arg1 = Username | UID | GID
                    201:  * return: NULL not found item or error and !=NULL found item
                    202:  */
1.1.2.8 ! misho     203: const struct tagUser *cfg_findPasswdBy(pwd_root_t * __restrict pwd, int criteria, ...);
1.1.2.5   misho     204: /*
                    205:  * cfg_unsetPasswd() - Unset item from passwords and free resources
                    206:  *
                    207:  * @pwd = Password root
                    208:  * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID]
                    209:  * @arg1 = Username | UID
                    210:  * return: 0 item not found, -1 error or 1 removed item
                    211:  */
                    212: int cfg_unsetPasswd(pwd_root_t * __restrict pwd, int criteria, ...);
1.1.2.1   misho     213: /*
1.1.2.6   misho     214:  * cfg_setPasswd() - Set item in password or adding new item if not exists
                    215:  *
                    216:  * @cfg = Password root
                    217:  * @csName = Username
                    218:  * @csPass = Password
                    219:  * @uid = UID
                    220:  * @gid = GID
                    221:  * @Class = Login class
                    222:  * @change = Chage date
                    223:  * @expire = Expire date
                    224:  * @csRealm = Realm
                    225:  * @csHome = Home dir
                    226:  * @csShell = Shell
                    227:  * return: 0 nothing changed, -1 error, 1 found and updated item or 2 added new item
                    228:  */
                    229: int cfg_setPasswd(pwd_root_t * __restrict pwd, const char *csName, const char *csPass, 
                    230:                unsigned int uid, unsigned int gid, const char *csClass, 
                    231:                unsigned int change, unsigned int expire, const char *csRealm, 
                    232:                const char *csHome, const char *csShell);
1.1.2.1   misho     233: /*
1.1.2.6   misho     234:  * cfg_getPasswd() - Get item from passwords and return structure from it
                    235:  *
                    236:  * @pwd = Password root
                    237:  * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID]
                    238:  * @arg1 = Username | UID
                    239:  * return: NULL item not found, !=NULL structure found
1.1.2.1   misho     240:  */
1.1.2.6   misho     241: inline const struct tagUser *cfg_getPasswd(pwd_root_t * __restrict pwd, int criteria, ...);
1.1.2.1   misho     242: 
                    243: 
                    244: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>