xref: /illumos-gate/usr/src/lib/libtecla/common/homedir.h (revision 201ceb75ab95f9bf1f42ea1dc9ab363b43ba47cf)
1 #ifndef homedir_h
2 #define homedir_h
3 
4 /*
5  * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
6  *
7  * All rights reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, and/or sell copies of the Software, and to permit persons
14  * to whom the Software is furnished to do so, provided that the above
15  * copyright notice(s) and this permission notice appear in all copies of
16  * the Software and that both the above copyright notice(s) and this
17  * permission notice appear in supporting documentation.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
22  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
24  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
25  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
26  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
27  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28  *
29  * Except as contained in this notice, the name of a copyright holder
30  * shall not be used in advertising or otherwise to promote the sale, use
31  * or other dealings in this Software without prior written authorization
32  * of the copyright holder.
33  */
34 
35 typedef struct HomeDir HomeDir;
36 
37 /*
38  * The following constructor and destructor functions create and
39  * delete the resources needed to look up home directories.
40  */
41 HomeDir *_new_HomeDir(void);
42 HomeDir *_del_HomeDir(HomeDir *home);
43 
44 /*
45  * Return the home directory of a specified user, or NULL if unknown.
46  */
47 const char *_hd_lookup_home_dir(HomeDir *home, const char *user);
48 
49 /*
50  * Get the description of the that occured when _hd_lookup_home_dir() was
51  * last called.
52  */
53 const char *_hd_last_home_dir_error(HomeDir *home);
54 
55 /*
56  * The _hd_scan_user_home_dirs() function calls a user-provided function
57  * for each username known by the system, passing the function both
58  * the name and the home directory of the user.
59  *
60  * The following macro can be used to declare both pointers and
61  * prototypes for the callback functions. The 'data' argument is
62  * a copy of the 'data' argument passed to _hd_scan_user_home_dirs()
63  * and is intended for the user of _hd_scan_user_home_dirs() to use
64  * to pass anonymous context data to the callback function.
65  * The username and home directories are passed to the callback function
66  * in the *usrnam and *homedir arguments respectively.
67  * To abort the scan, and have _hd_scan_user_home_dirs() return 1, the
68  * callback function can return 1. A description of up to maxerr
69  * characters before the terminating '\0', can be written to errmsg[].
70  * This can then be examined by calling _hd_last_home_dir_error().
71  * To indicate success and continue the scan, the callback function
72  * should return 0. _hd_scan_user_home_dirs() returns 0 on successful
73  * completion of the scan, or 1 if an error occurred or a call to the
74  * callback function returned 1.
75  */
76 #define HOME_DIR_FN(fn) int (fn)(void *data, const char *usrnam, const char *homedir, char *errmsg, int maxerr)
77 
78 int _hd_scan_user_home_dirs(HomeDir *home, const char *prefix, void *data,
79 			    HOME_DIR_FN(*callback_fn));
80 
81 #endif
82