| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /*
- * pamtest2.c - minimal PAM client with a configurable service name.
- * Used to exercise pam_fprintd.so against the real GDM service files
- * without touching /etc/pam.d (e.g. -s gdm-fingerprint).
- *
- * Build: gcc -O2 -Wall -o pamtest2 pamtest2.c -lpam
- * Run: ./pamtest2 -s gdm-fingerprint [username]
- */
- #include <security/pam_appl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- static int noop_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");
- struct pam_conv conv = { noop_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
- user = argv[i];
- }
- if (!user)
- user = "nobody";
- ret = pam_start(service, user, &conv, &pamh);
- if (ret != PAM_SUCCESS) {
- printf("pam_start: %s\n", pam_strerror(pamh, ret));
- return 2;
- }
- printf("service=%s user=%s\n", service, user);
- 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;
- }
|