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