Skip to content

Commit d479064

Browse files
committed
Adapt to new logging.h interface
Replace all debug_dbg() calls with LOG(), using an appropriate log level. Erase the debug_dbg() as nothing is relying on it anymore. The new LOG() macro does not depend on the configuration, so the configuration object (of type cfg_t) does not need to be passed around as parameter.
1 parent a4febd4 commit d479064

File tree

6 files changed

+251
-256
lines changed

6 files changed

+251
-256
lines changed

cfg.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -264,31 +264,31 @@ int cfg_init(cfg_t *cfg, int flags, int argc, const char **argv) {
264264

265265
exit:
266266
if (cfg->debug) {
267-
debug_dbg(cfg, "called.");
268-
debug_dbg(cfg, "flags %d argc %d", flags, argc);
267+
LOG(LOG_DEBUG, "called.");
268+
LOG(LOG_DEBUG, "flags %d argc %d", flags, argc);
269269
for (i = 0; i < argc; i++) {
270-
debug_dbg(cfg, "argv[%d]=%s", i, argv[i]);
270+
LOG(LOG_DEBUG, "argv[%d]=%s", i, argv[i]);
271271
}
272-
debug_dbg(cfg, "max_devices=%d", cfg->max_devs);
273-
debug_dbg(cfg, "debug=%d", cfg->debug);
274-
debug_dbg(cfg, "interactive=%d", cfg->interactive);
275-
debug_dbg(cfg, "cue=%d", cfg->cue);
276-
debug_dbg(cfg, "nodetect=%d", cfg->nodetect);
277-
debug_dbg(cfg, "userpresence=%d", cfg->userpresence);
278-
debug_dbg(cfg, "userverification=%d", cfg->userverification);
279-
debug_dbg(cfg, "pinverification=%d", cfg->pinverification);
280-
debug_dbg(cfg, "manual=%d", cfg->manual);
281-
debug_dbg(cfg, "nouserok=%d", cfg->nouserok);
282-
debug_dbg(cfg, "openasuser=%d", cfg->openasuser);
283-
debug_dbg(cfg, "alwaysok=%d", cfg->alwaysok);
284-
debug_dbg(cfg, "sshformat=%d", cfg->sshformat);
285-
debug_dbg(cfg, "expand=%d", cfg->expand);
286-
debug_dbg(cfg, "authfile=%s", cfg->auth_file ? cfg->auth_file : "(null)");
287-
debug_dbg(cfg, "authpending_file=%s",
288-
cfg->authpending_file ? cfg->authpending_file : "(null)");
289-
debug_dbg(cfg, "origin=%s", cfg->origin ? cfg->origin : "(null)");
290-
debug_dbg(cfg, "appid=%s", cfg->appid ? cfg->appid : "(null)");
291-
debug_dbg(cfg, "prompt=%s", cfg->prompt ? cfg->prompt : "(null)");
272+
LOG(LOG_DEBUG, "max_devices=%u", cfg->max_devs);
273+
LOG(LOG_DEBUG, "debug=%d", cfg->debug);
274+
LOG(LOG_DEBUG, "interactive=%d", cfg->interactive);
275+
LOG(LOG_DEBUG, "cue=%d", cfg->cue);
276+
LOG(LOG_DEBUG, "nodetect=%d", cfg->nodetect);
277+
LOG(LOG_DEBUG, "userpresence=%d", cfg->userpresence);
278+
LOG(LOG_DEBUG, "userverification=%d", cfg->userverification);
279+
LOG(LOG_DEBUG, "pinverification=%d", cfg->pinverification);
280+
LOG(LOG_DEBUG, "manual=%d", cfg->manual);
281+
LOG(LOG_DEBUG, "nouserok=%d", cfg->nouserok);
282+
LOG(LOG_DEBUG, "openasuser=%d", cfg->openasuser);
283+
LOG(LOG_DEBUG, "alwaysok=%d", cfg->alwaysok);
284+
LOG(LOG_DEBUG, "sshformat=%d", cfg->sshformat);
285+
LOG(LOG_DEBUG, "expand=%d", cfg->expand);
286+
LOG(LOG_DEBUG, "authfile=%s", cfg->auth_file ? cfg->auth_file : "(null)");
287+
LOG(LOG_DEBUG, "authpending_file=%s",
288+
cfg->authpending_file ? cfg->authpending_file : "(null)");
289+
LOG(LOG_DEBUG, "origin=%s", cfg->origin ? cfg->origin : "(null)");
290+
LOG(LOG_DEBUG, "appid=%s", cfg->appid ? cfg->appid : "(null)");
291+
LOG(LOG_DEBUG, "prompt=%s", cfg->prompt ? cfg->prompt : "(null)");
292292
}
293293

294294
if (r != PAM_SUCCESS)

fuzz/fuzz_format_parsers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
7777
fp_len = size - offset;
7878
fp = tmpfile();
7979
if (fp == NULL || (fwrite(&data[offset], 1, fp_len, fp)) != fp_len) {
80-
fprintf(stderr, "failed to create file for parser: %s\n", strerror(errno));
80+
fprintf(stderr, "failed to create file for parser (errno=%d)\n", errno);
8181
if (fp != NULL) {
8282
fclose(fp);
8383
}

logging.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,4 @@ void log_printf(int level, const char *, int, const char *, const char *, ...)
2525

2626
void log_debug_enable(void);
2727

28-
#define debug_dbg(cfg, ...) \
29-
do { \
30-
(void) cfg; \
31-
LOG(LOG_DEBUG, __VA_ARGS__); \
32-
} while (0)
33-
3428
#endif /* LOGGING_H */

pam-u2f.c

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)