Initial commit for Tizen
[profile/extras/shadow-utils.git] / lib / prototypes.h
1 /*
2  * Copyright (c) 1990 - 1994, Julianne Frances Haugh
3  * Copyright (c) 1996 - 2000, Marek Michałkiewicz
4  * Copyright (c) 2003 - 2006, Tomasz Kłoczko
5  * Copyright (c) 2007 - 2009, Nicolas François
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the copyright holders or contributors may not be used to
17  *    endorse or promote products derived from this software without
18  *    specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 /*
34  * prototypes.h
35  *
36  * prototypes of libmisc functions, and private lib functions.
37  *
38  * $Id: prototypes.h 2935 2009-05-18 18:32:17Z nekral-guest $
39  *
40  */
41
42 #ifndef _PROTOTYPES_H
43 #define _PROTOTYPES_H
44
45 #include <sys/stat.h>
46 #ifdef USE_UTMPX
47 #include <utmpx.h>
48 #else
49 #include <utmp.h>
50 #endif
51 #include <sys/types.h>
52 #include <pwd.h>
53 #include <grp.h>
54 #include <shadow.h>
55 #include <lastlog.h>
56
57 #include "defines.h"
58 #include "commonio.h"
59
60 extern char *Prog;
61
62 /* addgrps.c */
63 #if defined (HAVE_SETGROUPS) && ! defined (USE_PAM)
64 extern int add_groups (const char *);
65 #endif
66
67 /* age.c */
68 extern void agecheck (/*@null@*/const struct spwd *);
69 extern int expire (const struct passwd *, /*@null@*/const struct spwd *);
70 /* isexpired.c */
71 extern int isexpired (const struct passwd *, /*@null@*/const struct spwd *);
72
73 /* basename() renamed to Basename() to avoid libc name space confusion */
74 /* basename.c */
75 extern char *Basename (char *str);
76
77 /* chowndir.c */
78 extern int chown_tree (const char *, uid_t, uid_t, gid_t, gid_t);
79
80 /* chowntty.c */
81 extern void chown_tty (const struct passwd *);
82
83 /* cleanup.c */
84 typedef void (*cleanup_function) (/*@null@*/void *arg);
85 void add_cleanup (cleanup_function pcf, /*@null@*/void *arg);
86 void del_cleanup (cleanup_function pcf);
87 void do_cleanups (void);
88
89 /* cleanup_group.c */
90 struct cleanup_info_mod {
91         char *audit_msg;
92         char *action;
93         char *name;
94 };
95 void cleanup_report_add_group (void *group_name);
96 void cleanup_report_add_group_group (void *group_name);
97 #ifdef SHADOWGRP
98 void cleanup_report_add_group_gshadow (void *group_name);
99 #endif
100 void cleanup_report_del_group (void *group_name);
101 void cleanup_report_del_group_group (void *group_name);
102 #ifdef SHADOWGRP
103 void cleanup_report_del_group_gshadow (void *group_name);
104 #endif
105 void cleanup_report_mod_passwd (void *cleanup_info);
106 void cleanup_report_mod_group (void *cleanup_info);
107 void cleanup_report_mod_gshadow (void *cleanup_info);
108 void cleanup_unlock_group (/*@null@*/void *unused);
109 #ifdef SHADOWGRP
110 void cleanup_unlock_gshadow (/*@null@*/void *unused);
111 #endif
112 void cleanup_unlock_passwd (/*@null@*/void *unused);
113
114 /* console.c */
115 extern bool console (const char *);
116
117 /* copydir.c */
118 extern int copy_tree (const char *src_root, const char *dst_root,
119                       long int uid, long int gid);
120 extern int remove_tree (const char *root);
121
122 #ifdef WITH_SELINUX
123 extern int selinux_file_context (const char *dst_name);
124 #endif
125
126 /* encrypt.c */
127 extern char *pw_encrypt (const char *, const char *);
128
129 /* entry.c */
130 extern void pw_entry (const char *, struct passwd *);
131
132 /* env.c */
133 extern void addenv (const char *, /*@null@*/const char *);
134 extern void initenv (void);
135 extern void set_env (int, char *const *);
136 extern void sanitize_env (void);
137
138 /* fields.c */
139 extern void change_field (char *, size_t, const char *);
140 extern int valid_field (const char *, const char *);
141
142 /* find_new_gid.c */
143 extern int find_new_gid (bool sys_group,
144                          gid_t *gid,
145                          /*@null@*/gid_t const *preferred_gid);
146
147 /* find_new_uid.c */
148 extern int find_new_uid (bool sys_user,
149                          uid_t *uid,
150                          /*@null@*/uid_t const *preferred_uid);
151
152 /* get_gid.c */
153 extern int get_gid (const char *gidstr, gid_t *gid);
154
155 /* getgr_nam_gid.c */
156 extern /*@null@*/struct group *getgr_nam_gid (const char *grname);
157
158 /* getlong.c */
159 extern int getlong (const char *numstr, /*@out@*/long int *result);
160
161 /* get_pid.c */
162 extern int get_pid (const char *pidstr, pid_t *pid);
163
164 /* getrange */
165 extern int getrange (char *range,
166                      unsigned long *min, bool *has_min,
167                      unsigned long *max, bool *has_max);
168
169 /* get_uid.c */
170 extern int get_uid (const char *uidstr, uid_t *uid);
171
172 /* getulong.c */
173 extern int getulong (const char *numstr, /*@out@*/unsigned long int *result);
174
175 /* fputsx.c */
176 extern /*@null@*/char *fgetsx (/*@returned@*/ /*@out@*/char *, int, FILE *);
177 extern int fputsx (const char *, FILE *);
178
179 /* groupio.c */
180 extern void __gr_del_entry (const struct commonio_entry *ent);
181 extern /*@observer@*/const struct commonio_db *__gr_get_db (void);
182 extern /*@dependent@*/ /*@null@*/struct commonio_entry *__gr_get_head (void);
183 extern void __gr_set_changed (void);
184
185 /* groupmem.c */
186 extern /*@null@*/ /*@only@*/struct group *__gr_dup (const struct group *grent);
187 extern void gr_free (/*@out@*/ /*@only@*/struct group *grent);
188
189 /* hushed.c */
190 extern bool hushed (const char *username);
191
192 /* audit_help.c */
193 #ifdef WITH_AUDIT
194 extern int audit_fd;
195 extern void audit_help_open (void);
196 /* Use AUDIT_NO_ID when a name is provided to audit_logger instead of an ID */
197 #define AUDIT_NO_ID     ((unsigned int) -1)
198 typedef enum {
199         SHADOW_AUDIT_FAILURE = 0,
200         SHADOW_AUDIT_SUCCESS = 1} shadow_audit_result;
201 extern void audit_logger (int type, const char *pgname, const char *op,
202                           const char *name, unsigned int id,
203                           shadow_audit_result result);
204 void audit_logger_message (const char *message, shadow_audit_result result);
205 #endif
206
207 /* limits.c */
208 #ifndef USE_PAM
209 extern void setup_limits (const struct passwd *);
210 #endif
211
212 /* list.c */
213 extern /*@only@*/ /*@out@*/char **add_list (/*@returned@*/ /*@only@*/char **, const char *);
214 extern /*@only@*/ /*@out@*/char **del_list (/*@returned@*/ /*@only@*/char **, const char *);
215 extern /*@only@*/ /*@out@*/char **dup_list (char *const *);
216 extern bool is_on_list (char *const *list, const char *member);
217 extern /*@only@*/char **comma_to_list (const char *);
218
219 /* log.c */
220 extern void dolastlog (
221         struct lastlog *ll,
222         const struct passwd *pw,
223         /*@unique@*/const char *line,
224         /*@unique@*/const char *host);
225
226 /* login_nopam.c */
227 extern int login_access (const char *user, const char *from);
228
229 /* loginprompt.c */
230 extern void login_prompt (const char *, char *, int);
231
232 /* mail.c */
233 extern void mailcheck (void);
234
235 /* motd.c */
236 extern void motd (void);
237
238 /* myname.c */
239 extern /*@null@*/struct passwd *get_my_pwent (void);
240
241 /* pam_pass_non_interractive.c */
242 #ifdef USE_PAM
243 extern int do_pam_passwd_non_interractive (const char *pam_service,
244                                            const char *username,
245                                            const char* password);
246 #endif                          /* USE_PAM */
247
248 /* obscure.c */
249 #ifndef USE_PAM
250 extern int obscure (const char *, const char *, const struct passwd *);
251 #endif
252
253 /* pam_pass.c */
254 #ifdef USE_PAM
255 extern void do_pam_passwd (const char *user, bool silent, bool change_expired);
256 #endif
257
258 /* port.c */
259 extern bool isttytime (const char *, const char *, time_t);
260
261 /* pwd2spwd.c */
262 #ifndef USE_PAM
263 extern struct spwd *pwd_to_spwd (const struct passwd *);
264 #endif
265
266 /* pwdcheck.c */
267 #ifndef USE_PAM
268 extern void passwd_check (const char *, const char *, const char *);
269 #endif
270
271 /* pwd_init.c */
272 extern void pwd_init (void);
273
274 /* pwio.c */
275 extern void __pw_del_entry (const struct commonio_entry *ent);
276 extern struct commonio_db *__pw_get_db (void);
277 extern /*@dependent@*/ /*@null@*/struct commonio_entry *__pw_get_head (void);
278
279 /* pwmem.c */
280 extern /*@null@*/ /*@only@*/struct passwd *__pw_dup (const struct passwd *pwent);
281 extern void pw_free (/*@out@*/ /*@only@*/struct passwd *pwent);
282
283 /* rlogin.c */
284 extern int do_rlogin (const char *remote_host, char *name, size_t namelen,
285                       char *term, size_t termlen);
286
287 /* salt.c */
288 extern /*@observer@*/const char *crypt_make_salt (/*@null@*/const char *meth, /*@null@*/void *arg);
289
290 /* setugid.c */
291 extern int setup_groups (const struct passwd *info);
292 extern int change_uid (const struct passwd *info);
293 #if (defined HAVE_INITGROUPS) && (! defined USE_PAM)
294 extern int setup_uid_gid (const struct passwd *info, bool is_console);
295 #else
296 extern int setup_uid_gid (const struct passwd *info);
297 #endif
298
299 /* setup.c */
300 extern void setup (struct passwd *);
301
302 /* setupenv.c */
303 extern void setup_env (struct passwd *);
304
305 /* sgetgrent.c */
306 extern struct group *sgetgrent (const char *buf);
307
308 /* sgetpwent.c */
309 extern struct passwd *sgetpwent (const char *buf);
310
311 /* sgetspent.c */
312 #ifndef HAVE_SGETSPENT
313 extern struct spwd *sgetspent (const char *string);
314 #endif
315
316 /* sgroupio.c */
317 extern void __sgr_del_entry (const struct commonio_entry *ent);
318 extern /*@null@*/ /*@only@*/struct sgrp *__sgr_dup (const struct sgrp *sgent);
319 extern void sgr_free (/*@out@*/ /*@only@*/struct sgrp *sgent);
320 extern /*@dependent@*/ /*@null@*/struct commonio_entry *__sgr_get_head (void);
321 extern void __sgr_set_changed (void);
322
323 /* shadowio.c */
324 extern /*@dependent@*/ /*@null@*/struct commonio_entry *__spw_get_head (void);
325 extern void __spw_del_entry (const struct commonio_entry *ent);
326
327 /* shadowmem.c */
328 extern /*@null@*/ /*@only@*/struct spwd *__spw_dup (const struct spwd *spent);
329 extern void spw_free (/*@out@*/ /*@only@*/struct spwd *spent);
330
331 /* shell.c */
332 extern int shell (const char *file, /*@null@*/const char *arg, char *const envp[]);
333
334 /* system.c */
335 extern int safe_system (const char *command,
336                         const char *argv[],
337                         const char *env[],
338                         int ignore_stderr);
339
340 /* strtoday.c */
341 extern long strtoday (const char *);
342
343 /* suauth.c */
344 extern int check_su_auth (const char *actual_id, const char *wanted_id);
345
346 /* sulog.c */
347 extern void sulog (const char *tty,
348                    bool success,
349                    const char *oldname,
350                    const char *name);
351
352 /* sub.c */
353 extern void subsystem (const struct passwd *);
354
355 /* ttytype.c */
356 extern void ttytype (const char *);
357
358 /* tz.c */
359 #ifndef USE_PAM
360 extern char *tz (const char *);
361 #endif
362
363 /* ulimit.c */
364 extern int set_filesize_limit (int blocks);
365
366 /* user_busy.c */
367 extern int user_busy (const char *name, uid_t uid);
368
369 /* utmp.c */
370 extern /*@null@*/struct utmp *get_current_utmp (void);
371 extern struct utmp *prepare_utmp (const char *name,
372                                   const char *line,
373                                   const char *host,
374                                   /*@null@*/const struct utmp *ut);
375 extern int setutmp (struct utmp *ut);
376 #ifdef USE_UTMPX
377 extern struct utmpx *prepare_utmpx (const char *name,
378                                     const char *line,
379                                     const char *host,
380                                     /*@null@*/const struct utmp *ut);
381 extern int setutmpx (struct utmpx *utx);
382 #endif                          /* USE_UTMPX */
383
384 /* valid.c */
385 extern bool valid (const char *, const struct passwd *);
386
387 /* xmalloc.c */
388 extern /*@maynotreturn@*/ /*@out@*//*@only@*/char *xmalloc (size_t size)
389   /*@ensures MaxSet(result) == (size - 1); @*/;
390 extern /*@maynotreturn@*/ /*@only@*/char *xstrdup (const char *);
391
392 /* xgetpwnam.c */
393 extern /*@null@*/ /*@only@*/struct passwd *xgetpwnam (const char *);
394 /* xgetpwuid.c */
395 extern /*@null@*/ /*@only@*/struct passwd *xgetpwuid (uid_t);
396 /* xgetgrnam.c */
397 extern /*@null@*/ /*@only@*/struct group *xgetgrnam (const char *);
398 /* xgetgrgid.c */
399 extern /*@null@*/ /*@only@*/struct group *xgetgrgid (gid_t);
400 /* xgetspnam.c */
401 extern /*@null@*/ /*@only@*/struct spwd *xgetspnam(const char *);
402
403 /* yesno.c */
404 extern bool yes_or_no (bool read_only);
405
406 #endif                          /* _PROTOTYPES_H */