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