d9898ee8 |
1 | #ifndef numlib_h |
2 | #define numlib_h |
3 | |
4 | /* |
5 | ** Copyright 1998 - 2003 Double Precision, Inc. |
6 | ** See COPYING for distribution information. |
7 | */ |
8 | |
9 | #ifdef __cplusplus |
10 | extern "C" { |
11 | #endif |
12 | |
13 | static const char numlib_h_rcsid[]="$Id: numlib.h,v 1.10 2004/01/11 02:47:33 mrsam Exp $"; |
14 | |
15 | #if HAVE_CONFIG_H |
16 | #include "../numlib/config.h" /* VPATH build */ |
17 | #endif |
18 | |
19 | #include <sys/types.h> |
20 | #include <time.h> |
21 | |
22 | #define NUMBUFSIZE 60 |
23 | |
24 | /* Convert various system types to decimal */ |
25 | |
26 | char *libmail_str_time_t(time_t, char *); |
27 | char *libmail_str_off_t(off_t, char *); |
28 | char *libmail_str_pid_t(pid_t, char *); |
29 | char *libmail_str_dev_t(dev_t, char *); |
30 | char *libmail_str_ino_t(ino_t, char *); |
31 | char *libmail_str_uid_t(uid_t, char *); |
32 | char *libmail_str_gid_t(gid_t, char *); |
33 | char *libmail_str_size_t(size_t, char *); |
34 | |
35 | char *libmail_str_sizekb(unsigned long, char *); /* X Kb or X Mb */ |
36 | |
37 | /* Convert selected system types to hex */ |
38 | |
39 | char *libmail_strh_time_t(time_t, char *); |
40 | char *libmail_strh_pid_t(pid_t, char *); |
41 | char *libmail_strh_ino_t(ino_t, char *); |
42 | char *libmail_strh_dev_t(dev_t, char *); |
43 | |
44 | /* And, now let's do the reverse */ |
45 | |
46 | time_t libmail_strtotime_t(const char **); |
47 | time_t libmail_atotime_t(const char *); |
48 | |
49 | uid_t libmail_strtouid_t(const char **); |
50 | uid_t libmail_atouid_t(const char *); |
51 | |
52 | gid_t libmail_strtogid_t(const char **); |
53 | gid_t libmail_atogid_t(const char *); |
54 | |
55 | /* Common macros: */ |
56 | |
57 | #define LIBMAIL_STRIMPL(type, f1, f2) \ |
58 | \ |
59 | type f1(const char **p)\ |
60 | {\ |
61 | type n=0;\ |
62 | while ( **p >= '0' && **p <= '9') n=n*10 + (char)(*(*p)++ - '0');\ |
63 | return n;\ |
64 | }\ |
65 | \ |
66 | type f2(const char *p)\ |
67 | {\ |
68 | return f1(&p);\ |
69 | } |
70 | |
71 | |
72 | /* |
73 | ** The following functions are used by root to reset its user and group id |
74 | ** to the authenticated user's. Various functions are provided to handle |
75 | ** various situations. |
76 | */ |
77 | |
78 | void libmail_changegroup(gid_t); /* Set the group id only. Also clear any |
79 | ** auxiliary group ids */ |
80 | |
81 | void libmail_changeuidgid(uid_t, gid_t); |
82 | /* Set both user id and group id. Also clear |
83 | ** aux group ids */ |
84 | |
85 | void libmail_changeusername(const char *, const gid_t *); |
86 | /* |
87 | ** Set the userid to the indicate user's. If second argument is |
88 | ** not null, it points to the groupid to set. If it's null, the |
89 | ** group id is taken from the passwd file. Auxiliary IDs are set |
90 | ** to any aux IDs set for the user in the group file. If there are |
91 | ** no aux group IDs for the user, any AUX ids are cleared. |
92 | */ |
93 | |
94 | #ifdef __cplusplus |
95 | } |
96 | #endif |
97 | #endif |