@@ -53,19 +53,19 @@ static char *resolve_authfile_path(const cfg_t *cfg, const struct passwd *user,
5353
5454 if (cfg -> auth_file == NULL ) {
5555 if ((dir = secure_getenv (DEFAULT_AUTHFILE_DIR_VAR )) == NULL ) {
56- debug_dbg ( cfg , "Variable %s is not set, using default" ,
57- DEFAULT_AUTHFILE_DIR_VAR );
56+ LOG ( LOG_DEBUG , "Variable %s is not set, using default" ,
57+ DEFAULT_AUTHFILE_DIR_VAR );
5858 dir = user -> pw_dir ;
5959 path = cfg -> sshformat ? DEFAULT_AUTHFILE_DIR_SSH "/" DEFAULT_AUTHFILE_SSH
6060 : DEFAULT_AUTHFILE_DIR "/" DEFAULT_AUTHFILE ;
6161 } else {
62- debug_dbg ( cfg , "Variable %s set to %s" , DEFAULT_AUTHFILE_DIR_VAR , dir );
62+ LOG ( LOG_DEBUG , "Variable %s set to %s" , DEFAULT_AUTHFILE_DIR_VAR , dir );
6363 * openasuser = 0 ; /* documented exception, require explicit openasuser */
6464 path = cfg -> sshformat ? DEFAULT_AUTHFILE_SSH : DEFAULT_AUTHFILE ;
6565 if (!cfg -> openasuser ) {
66- debug_dbg ( cfg , "WARNING: not dropping privileges when reading the "
67- "authentication file, please consider setting "
68- "openasuser=1 in the module configuration" );
66+ LOG ( LOG_WARNING , "not dropping privileges when reading the "
67+ "authentication file, please consider setting "
68+ "openasuser=1 in the module configuration" );
6969 }
7070 }
7171 } else {
@@ -111,17 +111,17 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
111111 strcpy (buffer , DEFAULT_ORIGIN_PREFIX );
112112 if (gethostname (buffer + strlen (DEFAULT_ORIGIN_PREFIX ),
113113 BUFSIZE - strlen (DEFAULT_ORIGIN_PREFIX )) == -1 ) {
114- debug_dbg ( cfg , "Unable to get host name" );
114+ LOG ( LOG_ERR , "Unable to get host name (errno=%d)" , errno );
115115 retval = PAM_SYSTEM_ERR ;
116116 goto done ;
117117 }
118118 } else {
119119 strcpy (buffer , SSH_ORIGIN );
120120 }
121- debug_dbg ( cfg , "Origin not specified, using \"%s\"" , buffer );
121+ LOG ( LOG_DEBUG , "Origin not specified, using \"%s\"" , buffer );
122122 cfg -> origin = strdup (buffer );
123123 if (!cfg -> origin ) {
124- debug_dbg ( cfg , "Unable to allocate memory" );
124+ LOG ( LOG_CRIT , "Unable to allocate memory (errno=%d)" , errno );
125125 retval = PAM_BUF_ERR ;
126126 goto done ;
127127 } else {
@@ -130,11 +130,11 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
130130 }
131131
132132 if (!cfg -> appid ) {
133- debug_dbg ( cfg , "Appid not specified, using the value of origin (%s)" ,
134- cfg -> origin );
133+ LOG ( LOG_DEBUG , "Appid not specified, using the value of origin (%s)" ,
134+ cfg -> origin );
135135 cfg -> appid = strdup (cfg -> origin );
136136 if (!cfg -> appid ) {
137- debug_dbg ( cfg , "Unable to allocate memory" );
137+ LOG ( LOG_CRIT , "Unable to allocate memory (errno=%d)" , errno );
138138 retval = PAM_BUF_ERR ;
139139 goto done ;
140140 } else {
@@ -143,8 +143,8 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
143143 }
144144
145145 if (cfg -> max_devs == 0 ) {
146- debug_dbg ( cfg , "Maximum number of devices not set. Using default (%d )" ,
147- MAX_DEVS );
146+ LOG ( LOG_DEBUG , "Maximum number of devices not set. Using default (%u )" ,
147+ MAX_DEVS );
148148 cfg -> max_devs = MAX_DEVS ;
149149 }
150150#if WITH_FUZZING
@@ -154,36 +154,36 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
154154
155155 devices = calloc (cfg -> max_devs , sizeof (device_t ));
156156 if (!devices ) {
157- debug_dbg ( cfg , "Unable to allocate memory" );
157+ LOG ( LOG_CRIT , "Unable to allocate memory (errno=%d)" , errno );
158158 retval = PAM_BUF_ERR ;
159159 goto done ;
160160 }
161161
162162 pgu_ret = pam_get_user (pamh , & user , NULL );
163163 if (pgu_ret != PAM_SUCCESS || user == NULL ) {
164- debug_dbg ( cfg , "Unable to get username from PAM" );
164+ LOG ( LOG_ERR , "Unable to get username from PAM" );
165165 retval = PAM_CONV_ERR ;
166166 goto done ;
167167 }
168168
169- debug_dbg ( cfg , "Requesting authentication for user %s" , user );
169+ LOG ( LOG_INFO , "Requesting authentication for user %s" , user );
170170
171171 gpn_ret = getpwnam_r (user , & pw_s , buffer , sizeof (buffer ), & pw );
172172 if (gpn_ret != 0 || pw == NULL || pw -> pw_dir == NULL ||
173173 pw -> pw_dir [0 ] != '/' ) {
174- debug_dbg ( cfg , "Unable to retrieve credentials for user %s, (%s )" , user ,
175- strerror ( errno ) );
174+ LOG ( LOG_ERR , "Unable to retrieve credentials for user %s (errno=%d )" , user ,
175+ errno );
176176 retval = PAM_SYSTEM_ERR ;
177177 goto done ;
178178 }
179179
180- debug_dbg ( cfg , "Found user %s" , user );
181- debug_dbg ( cfg , "Home directory for %s is %s" , user , pw -> pw_dir );
180+ LOG ( LOG_DEBUG , "Found user %s" , user );
181+ LOG ( LOG_DEBUG , "Home directory for %s is %s" , user , pw -> pw_dir );
182182
183183 // Perform variable expansion.
184184 if (cfg -> expand && cfg -> auth_file ) {
185185 if ((cfg -> auth_file = expand_variables (cfg -> auth_file , user )) == NULL ) {
186- debug_dbg ( cfg , "Failed to perform variable expansion" );
186+ LOG ( LOG_ERR , "Failed to perform variable expansion" );
187187 retval = PAM_BUF_ERR ;
188188 goto done ;
189189 }
@@ -193,7 +193,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
193193 if (!cfg -> auth_file || cfg -> auth_file [0 ] != '/' ) {
194194 char * tmp = resolve_authfile_path (cfg , pw , & openasuser );
195195 if (tmp == NULL ) {
196- debug_dbg ( cfg , "Could not resolve authfile path" );
196+ LOG ( LOG_ERR , "Could not resolve authfile path" );
197197 retval = PAM_BUF_ERR ;
198198 goto done ;
199199 }
@@ -204,29 +204,29 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
204204 should_free_auth_file = 1 ;
205205 }
206206
207- debug_dbg ( cfg , "Using authentication file %s" , cfg -> auth_file );
207+ LOG ( LOG_DEBUG , "Using authentication file %s" , cfg -> auth_file );
208208
209209 if (!openasuser ) {
210210 openasuser = geteuid () == 0 && cfg -> openasuser ;
211211 }
212212 if (openasuser ) {
213- debug_dbg ( cfg , "Dropping privileges" );
213+ LOG ( LOG_DEBUG , "Dropping privileges" );
214214 if (pam_modutil_drop_priv (pamh , & privs , pw )) {
215- debug_dbg ( cfg , "Unable to switch user to uid %i" , pw -> pw_uid );
215+ LOG ( LOG_ERR , "Unable to switch user to uid %ji" , ( intmax_t ) pw -> pw_uid );
216216 retval = PAM_SYSTEM_ERR ;
217217 goto done ;
218218 }
219- debug_dbg ( cfg , "Switched to uid %i" , pw -> pw_uid );
219+ LOG ( LOG_DEBUG , "Switched to uid %ji" , ( intmax_t ) pw -> pw_uid );
220220 }
221221 retval = get_devices_from_authfile (cfg , user , devices , & n_devices );
222222
223223 if (openasuser ) {
224224 if (pam_modutil_regain_priv (pamh , & privs )) {
225- debug_dbg ( cfg , "could not restore privileges" );
225+ LOG ( LOG_ERR , "could not restore privileges" );
226226 retval = PAM_SYSTEM_ERR ;
227227 goto done ;
228228 }
229- debug_dbg ( cfg , "Restored privileges" );
229+ LOG ( LOG_DEBUG , "Restored privileges" );
230230 }
231231
232232 if (retval != PAM_SUCCESS ) {
@@ -242,32 +242,33 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
242242 cfg -> authpending_file = strdup (buffer );
243243 }
244244 if (!cfg -> authpending_file ) {
245- debug_dbg ( cfg , "Unable to allocate memory for the authpending_file, "
246- "touch request notifications will not be emitted" );
245+ LOG ( LOG_ERR , "Unable to allocate memory for the authpending_file, "
246+ "touch request notifications will not be emitted" );
247247 } else {
248248 should_free_authpending_file = 1 ;
249249 }
250250 } else {
251251 if (strlen (cfg -> authpending_file ) == 0 ) {
252- debug_dbg ( cfg , "authpending_file is set to an empty value, touch request "
252+ LOG ( LOG_DEBUG , "authpending_file is set to an empty value, touch request "
253253 "notifications will be disabled" );
254254 cfg -> authpending_file = NULL ;
255255 }
256256 }
257257
258258 int authpending_file_descriptor = -1 ;
259259 if (cfg -> authpending_file ) {
260- debug_dbg ( cfg , "Touch request notifications will be emitted via '%s'" ,
261- cfg -> authpending_file );
260+ LOG ( LOG_DEBUG , "Touch request notifications will be emitted via '%s'" ,
261+ cfg -> authpending_file );
262262
263263 // Open (or create) the authpending_file to indicate that we start waiting
264264 // for a touch
265265 authpending_file_descriptor =
266266 open (cfg -> authpending_file ,
267267 O_RDONLY | O_CREAT | O_CLOEXEC | O_NOFOLLOW | O_NOCTTY , 0664 );
268268 if (authpending_file_descriptor < 0 ) {
269- debug_dbg (cfg , "Unable to emit 'authentication started' notification: %s" ,
270- strerror (errno ));
269+ LOG (LOG_ERR ,
270+ "Unable to emit 'authentication started' notification (errno=%d)" ,
271+ errno );
271272 }
272273 }
273274
@@ -283,8 +284,9 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
283284 // Close the authpending_file to indicate that we stop waiting for a touch
284285 if (authpending_file_descriptor >= 0 ) {
285286 if (close (authpending_file_descriptor ) < 0 ) {
286- debug_dbg (cfg , "Unable to emit 'authentication stopped' notification: %s" ,
287- strerror (errno ));
287+ LOG (LOG_ERR ,
288+ "Unable to emit 'authentication stopped' notification (errno=%d)" ,
289+ errno );
288290 }
289291 }
290292
@@ -312,10 +314,10 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
312314 }
313315
314316 if (cfg -> alwaysok && retval != PAM_SUCCESS ) {
315- debug_dbg ( cfg , "alwaysok needed (otherwise return with %d)" , retval );
317+ LOG ( LOG_DEBUG , "alwaysok needed (otherwise return with %d)" , retval );
316318 retval = PAM_SUCCESS ;
317319 }
318- debug_dbg ( cfg , "done. [%s]" , pam_strerror (pamh , retval ));
320+ LOG ( LOG_DEBUG , "done. [%s]" , pam_strerror (pamh , retval ));
319321
320322 cfg_free (cfg );
321323 return retval ;
0 commit comments