| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- * pamtest3.c - PAM client with a custom config directory (pam_start_confdir),
- * for testing pam_fprintd without touching /etc/pam.d or hitting faillock.
- *
- * Build: gcc -O2 -Wall -o pamtest3 pamtest3.c -lpam
- * Run: ./pamtest3 -d confdir -s fprintd-test [username]
- */
- #include <security/pam_appl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- static int silent_conv(int n, const struct pam_message **m,
- struct pam_response **r, void *d)
- {
- (void)n;
- (void)m;
- (void)r;
- (void)d;
- return PAM_CONV_ERR;
- }
- int main(int argc, char **argv)
- {
- const char *service = "fptest";
- const char *user = getenv("USER");
- const char *confdir = NULL;
- struct pam_conv conv = { silent_conv, NULL };
- pam_handle_t *pamh = NULL;
- int ret, i;
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-s") == 0 && i + 1 < argc)
- service = argv[++i];
- else if (strcmp(argv[i], "-d") == 0 && i + 1 < argc)
- confdir = argv[++i];
- else
- user = argv[i];
- }
- if (!user)
- user = "nobody";
- if (confdir)
- ret = pam_start_confdir(service, user, &conv, confdir, &pamh);
- else
- ret = pam_start(service, user, &conv, &pamh);
- if (ret != PAM_SUCCESS) {
- printf("pam_start%s: %s\n", confdir ? "_confdir" : "",
- pam_strerror(pamh, ret));
- return 2;
- }
- printf("service=%s user=%s confdir=%s\n", service, user,
- confdir ? confdir : "(default)");
- ret = pam_authenticate(pamh, 0);
- printf("\npam_authenticate => %d (%s)\n", ret, pam_strerror(pamh, ret));
- pam_end(pamh, ret);
- return ret == PAM_SUCCESS ? 0 : 1;
- }
|