Annotation of libaitcfg/inc/aitpwd.h, revision 1.8
1.2 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.8 ! misho 6: * $Id: aitpwd.h,v 1.7.8.1 2024/12/09 13:16:20 misho Exp $
1.2 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:
1.8 ! misho 15: Copyright 2004 - 2024
1.2 misho 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>
51: #include <sys/types.h>
1.4 misho 52: #include <elwix.h>
1.2 misho 53:
54:
55: #define PWD_CRIT_NAME 0
56: #define PWD_CRIT_UID 1
57: #define PWD_CRIT_GID 2
58:
59:
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 */
1.7 misho 72: } __attribute__((packed));
1.2 misho 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 {
81: int usr_fields;
82:
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:
94: SLIST_ENTRY(tagUser) usr_next;
95: RB_ENTRY(tagUser) usr_node;
96: };
97: typedef struct tagPWD {
98: pthread_mutex_t pwd_mtx;
99:
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))
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:
1.8 ! misho 121: #ifdef __cplusplus
! 122: extern "C" {
! 123: #endif
1.2 misho 124:
125: /*
126: * cfgInitPasswd() - Init password root
127: *
1.6 misho 128: * return: NULL error or !=NULL allocated password root
129: */
130: pwd_root_t *cfgInitPasswd();
131: /*
132: * cfgEndPasswd() - Free resources & password root
133: *
134: * @ppwd = Password root
135: * return: none
1.2 misho 136: */
1.6 misho 137: void cfgEndPasswd(pwd_root_t **ppwd);
1.2 misho 138: /*
139: * cfgLoadPasswd() - Load passwords from file
140: *
141: * @pwdName = Passwords filename
142: * @pwd = Password root
143: * return: -1 error or 0 ok
144: */
145: int cfgLoadPasswd(const char *pwdName, pwd_root_t * __restrict pwd);
146: /*
147: * cfgClearPasswd() - Clear passwords and free resources
148: *
149: * @cfg = Password root
150: * return: none
151: */
152: void cfgClearPasswd(pwd_root_t * __restrict pwd);
153: /*
154: * cfgUnloadPasswd() - Unload passwords from memory and destroy resources
155: *
156: * @pwd = Password root
157: * return: none
158: */
159: void cfgUnloadPasswd(pwd_root_t * __restrict pwd);
160: /*
161: * cfgCreatePasswd() - Create password file from memory
162: *
163: * @pwdName = New password filename
164: * @pwd = Password root
165: * return: -1 error or 0 ok
166: */
167: int cfgCreatePasswd(const char *pwdName, pwd_root_t * __restrict pwd);
168:
169: /*
170: * cfgReadPasswd() - Read file and add new item at password root
171: *
172: * @f = File resource
173: * @pwd = Password root
174: * return: -1 error or 0 ok
175: */
176: int cfgReadPasswd(FILE *f, pwd_root_t * __restrict pwd);
177: /*
178: * cfgWritePasswd() - Write passwords from memory
179: *
180: * @f = File handle
181: * @pwd = Password root
182: * return: -1 error or 0 ok
183: */
184: int cfgWritePasswd(FILE *f, pwd_root_t * __restrict pwd);
185: /*
186: * cfgConcatPasswd() - Concat two password roots into one
187: *
188: * @pwd = Password root
189: * @add_pwd = Concated password root will be destroy after merge
190: * return: -1 error or 0 ok
191: */
192: int cfgConcatPasswd(pwd_root_t * __restrict pwd, pwd_root_t * __restrict add_pwd);
193:
194: /*
195: * cfgAuthPasswd() - Authenticate user against passwords db
196: *
197: * @pwd = Password root
198: * @csName = Username
199: * @csPass = Password
200: * return: =NULL deny or !=NULL allow
201: */
202: const struct tagUser *cfgAuthPasswd(pwd_root_t * __restrict pwd,
203: const char *csName, const char *csPass);
204:
205: /*
206: * cfg_findPasswdBy() - Find user by criteria position in list
207: *
208: * @pwd = Password root
209: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID|PWD_CRIT_GID]
210: * @arg1 = Username | UID | GID
211: * return: NULL not found item or error and !=NULL found item
212: */
213: const struct tagUser *cfg_findPasswdBy(pwd_root_t * __restrict pwd, int criteria, ...);
214: /*
215: * cfg_unsetPasswd() - Unset item from passwords and free resources
216: *
217: * @pwd = Password root
218: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID]
219: * @arg1 = Username | UID
220: * return: 0 item not found, -1 error or 1 removed item
221: */
222: int cfg_unsetPasswd(pwd_root_t * __restrict pwd, int criteria, ...);
223: /*
224: * cfg_setPasswd() - Set item in password or adding new item if not exists
225: *
226: * @cfg = Password root
1.3 misho 227: * @fields = Following parameters are continuous to certain field
1.2 misho 228: * @csName = Username
229: * @arg1 = Password
230: * @arg2 = UID
231: * @arg3 = GID
232: * @arg4 = Login class
233: * @arg5 = Chage date
234: * @arg6 = Expire date
235: * @arg7 = Realm
236: * @arg8 = Home dir
237: * @arg9 = Shell
238: * return: 0 nothing changed, -1 error, 1 found and updated item or 2 added new item
239: */
1.3 misho 240: int cfg_setPasswd(pwd_root_t * __restrict pwd, passwd_attr_t fields, const char *csName, ...);
1.2 misho 241: /*
242: * cfg_getPasswd() - Get item from passwords and return structure from it
243: *
244: * @pwd = Password root
245: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID]
246: * @arg1 = Username | UID
247: * return: NULL item not found, !=NULL structure found
248: */
1.4 misho 249: const struct tagUser *cfg_getPasswd(pwd_root_t * __restrict pwd, int criteria, ...);
1.2 misho 250:
1.8 ! misho 251: #ifdef __cplusplus
! 252: }
! 253: #endif
1.2 misho 254:
255: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>