1 /*- 2 * Copyright (c) 2013 The FreeBSD Foundation 3 * 4 * This software was developed by Pawel Jakub Dawidek under sponsorship from 5 * the FreeBSD Foundation. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _CAP_PWD_H_ 30 #define _CAP_PWD_H_ 31 32 #ifdef HAVE_CASPER 33 #define WITH_CASPER 34 #endif 35 36 #include <sys/cdefs.h> 37 38 #ifdef WITH_CASPER 39 __BEGIN_DECLS 40 41 struct passwd *cap_getpwent(cap_channel_t *chan); 42 struct passwd *cap_getpwnam(cap_channel_t *chan, const char *login); 43 struct passwd *cap_getpwuid(cap_channel_t *chan, uid_t uid); 44 45 int cap_getpwent_r(cap_channel_t *chan, struct passwd *pwd, char *buffer, 46 size_t bufsize, struct passwd **result); 47 int cap_getpwnam_r(cap_channel_t *chan, const char *name, struct passwd *pwd, 48 char *buffer, size_t bufsize, struct passwd **result); 49 int cap_getpwuid_r(cap_channel_t *chan, uid_t uid, struct passwd *pwd, 50 char *buffer, size_t bufsize, struct passwd **result); 51 52 int cap_setpassent(cap_channel_t *chan, int stayopen); 53 void cap_setpwent(cap_channel_t *chan); 54 void cap_endpwent(cap_channel_t *chan); 55 56 int cap_pwd_limit_cmds(cap_channel_t *chan, const char * const *cmds, 57 size_t ncmds); 58 int cap_pwd_limit_fields(cap_channel_t *chan, const char * const *fields, 59 size_t nfields); 60 int cap_pwd_limit_users(cap_channel_t *chan, const char * const *names, 61 size_t nnames, uid_t *uids, size_t nuids); 62 63 __END_DECLS 64 65 #else 66 67 static inline struct passwd * 68 cap_getpwent(cap_channel_t *chan __unused) 69 { 70 71 return (getpwent()); 72 } 73 74 static inline struct passwd * 75 cap_getpwnam(cap_channel_t *chan __unused, const char *login) 76 { 77 78 return (getpwnam(login)); 79 } 80 81 static inline struct passwd * 82 cap_getpwuid(cap_channel_t *chan __unused, uid_t uid) 83 { 84 85 return (getpwuid(uid)); 86 } 87 88 static inline int 89 cap_getpwent_r(cap_channel_t *chan __unused, struct passwd *pwd, char *buffer, 90 size_t bufsize, struct passwd **result) 91 { 92 93 return (getpwent_r(pwd, buffer, bufsize, result)); 94 } 95 96 static inline int 97 cap_getpwnam_r(cap_channel_t *chan __unused, const char *name, 98 struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) 99 { 100 101 return (getpwnam_r(name, pwd, buffer, bufsize, result)); 102 } 103 104 static inline int 105 cap_getpwuid_r(cap_channel_t *chan __unused, uid_t uid, struct passwd *pwd, 106 char *buffer, size_t bufsize, struct passwd **result) 107 { 108 109 return (getpwuid_r(uid, pwd, buffer, bufsize, result)); 110 } 111 112 static inline int 113 cap_setpassent(cap_channel_t *chan __unused, int stayopen) 114 { 115 116 return (setpassent(stayopen)); 117 } 118 119 static inline void 120 cap_setpwent(cap_channel_t *chan __unused) 121 { 122 123 return (setpwent()); 124 } 125 126 static inline void 127 cap_endpwent(cap_channel_t *chan __unused) 128 { 129 130 return (endpwent()); 131 } 132 133 static inline int 134 cap_pwd_limit_cmds(cap_channel_t *chan __unused, 135 const char * const *cmds __unused, size_t ncmds __unused) 136 { 137 138 return (0); 139 } 140 141 static inline int 142 cap_pwd_limit_fields(cap_channel_t *chan __unused, 143 const char * const *fields __unused, size_t nfields __unused) 144 { 145 146 return (0); 147 } 148 149 static inline int 150 cap_pwd_limit_users(cap_channel_t *chan __unused, 151 const char * const *names __unused, size_t nnames __unused, 152 uid_t *uids __unused, size_t nuids __unused) 153 { 154 155 return (0); 156 } 157 #endif 158 159 #endif /* !_CAP_PWD_H_ */ 160