1 /** conf.h
2  **
3  ** Fichier de configuration pour calife.c
4  **
5  ** cree pour simplifier calife.c
6  **
7  ** Copyright (c) 1991-2010 par O. ROBERT
8  **
9  ** @(#) $Id$
10  **/
11 
12 #ifndef CONF_H                  /* evite les includes multiples */
13 #define CONF_H
14 
15 #define ROOT_LOGIN      "root"
16 
17 #ifdef SUNOS4
18 #define _PATH_UTMP  "/etc/utmp" /* sigh */
19 #endif
20 
21                                 /* for Gould NP1 */
22 #ifdef GOULD
23 #define BSD
24 #endif
25 
26 #if (defined(BSD) && (BSD >= 199306))   /* for both NetBSD & FreeBSD */
27 #define ADMIN_LOG   "/var/log/calife"
28 #define HAVE_SYSCONF
29 #endif /* __386BSD__ */
30 
31 
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 
35 #ifdef HAVE_SYS_PARAM_H
36 #include <sys/param.h>
37 #endif /* HAVE_SYS_PARAM_H */
38 
39 #if defined(HAVE_SYS_WAIT_H) || defined(HAVE_NON_POSIX_WAIT_H)
40 #include <sys/wait.h>
41 #endif /* HAVE_SYS_WAIT_H && HAVE_NON_POSIX_WAIT_H */
42 
43 #ifdef HAVE_UNISTD_H
44 #include <unistd.h>
45 #endif /* HAVE_UNISTD_H */
46 
47 #ifdef HAVE_STDLIB_H
48 #include <stdlib.h>
49 #endif /* HAVE_STDLIB_H */
50 
51 #ifdef HAVE_SYSLOG_H
52 #include <syslog.h>
53 #endif /* HAVE_SYSLOG_H */
54 
55 #ifdef HAVE_SYS_TIME_H
56 #include <sys/time.h>
57 #endif /* HAVE_SYS_TIME_H */
58 
59 #include <signal.h>
60 #include <stdio.h>
61 #include <time.h>
62 #include <pwd.h>
63 #include <grp.h>
64 
65 #if defined (SUNOS4) || defined (__linux__)
66 # include <sys/time.h>
67 # include <utmp.h>
68 #endif /* SunOS && __linux__ */
69 
70 #ifdef HAVE_SHADOW_H
71 #include <shadow.h>
72 #endif /* HAVE_SHADOW_H */
73 
74 #include <errno.h>
75 
76 #ifdef HAVE_STRING_H
77 #include <string.h>
78 #endif /* HAVE_STRING_H */
79 
80 #ifdef NEED_STRINGS_H
81 #include <strings.h>
82 #endif /* NEED_STRINGS_H */
83 
84 #ifdef HAVE_FCNTL_H
85 #include <fcntl.h>
86 #endif /* HAVE_FCNTL_H */
87 
88 #ifdef HAVE_RLIMIT
89 #include <sys/resource.h>
90 #endif /* HAVE_RLIMIT */
91 
92 #ifdef HAVE_LIBGEN_H
93 #include <libgen.h>
94 #endif /* HAVE_LIBGEN_H */
95 
96                                 /* A verifier */
97 #ifdef BSD
98 #if !defined(__FreeBSD__) && !defined(HAVE_SYS_WAIT_H)
99 #define WEXITSTATUS(x)  ((x).w_retcode)
100 #define WCOREDUMP(x)    ((x).w_coredump)
101 #define WTERMSIG(x)     ((x).w_termsig)
102 #endif
103 #endif
104 
105 /*
106  * Number of attempts the code will try to verify the password
107  */
108 #define MAX_ATTEMPTS    3
109 
110 #ifdef WITH_PAM
111 /*
112  * the following code is stolen from imap-uw PAM authentication module and
113  * login.c
114  */
115 #define COPY_STRING(s) (s ? strdup(s) : NULL)
116 
117 struct cred_t {
118 	const char *uname;		/* user name */
119 	const char *pass;		  /* password */
120 };
121 typedef struct cred_t cred_t;
122 
123 #ifdef HAVE_PAM_PAM_APPL_H
124 #include <pam/pam_appl.h>
125 #else
126 #include <security/pam_appl.h>
127 #endif
128 #endif /* WITH_PAM */
129 
130 /*
131  * Try to simplify the code
132  */
133 #include <assert.h>
134 #ifdef HPUX
135 #  define GET_ROOT { \
136                         int e = setresuid(-1,ssid,-1); \
137                         assert(e == 0); \
138                    }
139 #else
140 #  define GET_ROOT { \
141                         int e = seteuid(ssid); \
142                         assert(e == 0); \
143                    }
144 #endif /* HPUX */
145 
146 #ifdef HPUX
147 #  define RELEASE_ROOT { \
148                             int e = setresuid(-1,getuid (),-1);
149                             assert(e == 0); \
150                        }
151 #else
152 #  define RELEASE_ROOT { \
153                             int e = seteuid(getuid ()); \
154                             assert(e == 0); \
155                        }
156 #endif /* HPUX */
157 
158 /* compiler-related keywords */
159 #include "compiler.h"
160 
161 #define MAX_STRING  1024        /* "safe" value */
162 
163 #ifndef MAXLOGNAME
164 #define MAXLOGNAME  16
165 #endif
166 
167 #define ACCEPT_ALPHAL   "abcdefghijklmnopqrstuvwxyz"
168 #define ACCEPT_ALPHAU   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
169 #define ACCEPT_NUM      "0123456789"
170 #define ACCEPT_PUNCT    "-_"
171 
172 #define ACCEPT_CHARS    ACCEPT_ALPHAL \
173                         ACCEPT_ALPHAU \
174                         ACCEPT_NUM \
175                         ACCEPT_PUNCT
176 
177 #define AUTH_OK    0
178 #define AUTH_NULL  1
179 #define AUTH_ERR   2
180 #define AUTH_BADP  3
181 
182   int open_databases (void);
183   void authenticate_user (char *, char *, char *, char *);
184   int verify_auth_info (char *, char *);
185   void exec_shell (char *);
186 # ifndef HAVE_BASENAME
187   char * basename (char * file_name);
188 # endif /* HAVE_BASENAME */
189   void * xalloc (size_t size);
190   _Noreturn void die (int err, const char * fmt,...) _NORETURN;
191   char * whoami(void);
192 #ifdef WITH_PAM
193   int  auth_pam(struct passwd **ppw, const char *pass);
194 #endif
195 
196 #ifndef MAIN_MODULE
197 extern  int     custom_shell;   /* modification du shell ? */
198 extern  char    * shell;        /* nom du shell */
199 extern  uid_t   ssid;           /* POSIX saved uid */
200 extern  char    * _group;       /* Si user E group */
201 #ifdef WITH_PAM
202 extern  pam_handle_t	*pamh;
203 #endif /* WITH_PAM */
204 #endif /* !MAIN_MODULE */
205 
206 extern  int errno;
207 
208 #ifdef DEBUG
209 #define MESSAGE(x) fprintf (stderr, (x)); \
210                    fflush (stderr)
211 #define MESSAGE_1(x,y) fprintf (stderr, (x), (y)); \
212                        fflush (stderr)
213 #define MESSAGE_2(x,y,z) fprintf (stderr, (x), (y), (z)); \
214                          fflush (stderr)
215 #define MESSAGE_3(x,y,z,t) fprintf (stderr, (x), (y), (z), (t)); \
216                            fflush (stderr)
217 #define MESSAGE_4(x,y,z,t,u) fprintf (stderr, (x), (y), (z), (t), (u)); \
218                              fflush (stderr)
219 #define MESSAGE_5(x,y,z,t,u,v) fprintf (stderr, (x), (y), (z), (t), \
220                                                 (u), (v)); \
221                                fflush (stderr)
222 #else
223 #define MESSAGE(x)
224 #define MESSAGE_1(x,y)
225 #define MESSAGE_2(x,y,z)
226 #define MESSAGE_3(x,y,z,t)
227 #define MESSAGE_4(x,y,z,t,u)
228 #define MESSAGE_5(x,y,z,t,u,v)
229 #endif /* DEBUG */
230 
231 #ifdef NO_SYSLOG
232 #define ADMIN_LOG   "/var/log/calife.log"
233 #endif /* NO_SYSLOG */
234 
235 #endif /* CONF_H */
236