Changeset View
Changeset View
Standalone View
Standalone View
pam_kwallet.c
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | |||||
71 | 71 | | |||
72 | const static char *kdehome = NULL; | 72 | const static char *kdehome = NULL; | ||
73 | const static char *kwalletd = NULL; | 73 | const static char *kwalletd = NULL; | ||
74 | const static char *socketPath = NULL; | 74 | const static char *socketPath = NULL; | ||
75 | const static char *kwalletPamDataKey = NULL; | 75 | const static char *kwalletPamDataKey = NULL; | ||
76 | const static char *logPrefix = NULL; | 76 | const static char *logPrefix = NULL; | ||
77 | static int force_run = 0; | 77 | static int force_run = 0; | ||
78 | 78 | | |||
79 | #ifdef KWALLET5 | | |||
80 | const static char *envVar = "PAM_KWALLET5_LOGIN"; | 79 | const static char *envVar = "PAM_KWALLET5_LOGIN"; | ||
81 | #else | | |||
82 | const static char *envVar = "PAM_KWALLET_LOGIN"; | | |||
83 | #endif | | |||
84 | 80 | | |||
85 | static int argumentsParsed = -1; | 81 | static int argumentsParsed = -1; | ||
86 | 82 | | |||
87 | int kwallet_hash(pam_handle_t *pamh, const char *passphrase, struct passwd *userInfo, char *key); | 83 | int kwallet_hash(pam_handle_t *pamh, const char *passphrase, struct passwd *userInfo, char *key); | ||
88 | 84 | | |||
89 | static void parseArguments(int argc, const char **argv) | 85 | static void parseArguments(int argc, const char **argv) | ||
90 | { | 86 | { | ||
91 | //If already parsed | 87 | //If already parsed | ||
92 | if (argumentsParsed != -1) { | 88 | if (argumentsParsed != -1) { | ||
93 | return; | 89 | return; | ||
94 | } | 90 | } | ||
95 | 91 | | |||
96 | int x = 0; | 92 | int x = 0; | ||
97 | for (;x < argc; ++x) { | 93 | for (;x < argc; ++x) { | ||
98 | if (strstr(argv[x], "kdehome=") != NULL) { | 94 | if (strstr(argv[x], "kdehome=") != NULL) { | ||
99 | kdehome = argv[x] + 8; | 95 | kdehome = argv[x] + 8; | ||
100 | } else if (strstr(argv[x], "kwalletd=") != NULL) { | 96 | } else if (strstr(argv[x], "kwalletd=") != NULL) { | ||
101 | kwalletd = argv[x] + 9; | 97 | kwalletd = argv[x] + 9; | ||
102 | } else if (strstr(argv[x], "socketPath=") != NULL) { | 98 | } else if (strstr(argv[x], "socketPath=") != NULL) { | ||
103 | socketPath= argv[x] + 11; | 99 | socketPath= argv[x] + 11; | ||
104 | } else if (strcmp(argv[x], "force_run") == 0) { | 100 | } else if (strcmp(argv[x], "force_run") == 0) { | ||
105 | force_run = 1; | 101 | force_run = 1; | ||
106 | } | 102 | } | ||
107 | } | 103 | } | ||
108 | #ifdef KWALLET5 | | |||
109 | if (kdehome == NULL) { | 104 | if (kdehome == NULL) { | ||
110 | kdehome = ".local/share"; | 105 | kdehome = ".local/share"; | ||
111 | } | 106 | } | ||
112 | if (kwalletd == NULL) { | 107 | if (kwalletd == NULL) { | ||
113 | kwalletd = "/usr/bin/kwalletd5"; | 108 | kwalletd = "/usr/bin/kwalletd5"; | ||
114 | } | 109 | } | ||
115 | if (kwalletPamDataKey == NULL) { | 110 | if (kwalletPamDataKey == NULL) { | ||
116 | kwalletPamDataKey = "kwallet5_key"; | 111 | kwalletPamDataKey = "kwallet5_key"; | ||
117 | } | 112 | } | ||
118 | if (logPrefix == NULL) { | 113 | if (logPrefix == NULL) { | ||
119 | logPrefix = "pam_kwallet5"; | 114 | logPrefix = "pam_kwallet5"; | ||
120 | } | 115 | } | ||
121 | #else | | |||
122 | if (kdehome == NULL) { | | |||
123 | kdehome = ".kde"; | | |||
124 | } | | |||
125 | if (kwalletd == NULL) { | | |||
126 | kwalletd = "/usr/bin/kwalletd"; | | |||
127 | } | | |||
128 | if (kwalletPamDataKey == NULL) { | | |||
129 | kwalletPamDataKey = "kwallet_key"; | | |||
130 | } | | |||
131 | if (logPrefix == NULL) { | | |||
132 | logPrefix = "pam_kwallet"; | | |||
133 | } | | |||
134 | #endif | | |||
135 | } | 116 | } | ||
136 | 117 | | |||
137 | static const char* get_env(pam_handle_t *ph, const char *name) | 118 | static const char* get_env(pam_handle_t *ph, const char *name) | ||
138 | { | 119 | { | ||
139 | const char *env = pam_getenv (ph, name); | 120 | const char *env = pam_getenv (ph, name); | ||
140 | if (env && env[0]) { | 121 | if (env && env[0]) { | ||
141 | return env; | 122 | return env; | ||
142 | } | 123 | } | ||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Line(s) | 362 | { | |||
447 | } | 428 | } | ||
448 | 429 | | |||
449 | //TODO use a pam argument for full path kwalletd | 430 | //TODO use a pam argument for full path kwalletd | ||
450 | char pipeInt[4]; | 431 | char pipeInt[4]; | ||
451 | sprintf(pipeInt, "%d", toWalletPipe[0]); | 432 | sprintf(pipeInt, "%d", toWalletPipe[0]); | ||
452 | char sockIn[4]; | 433 | char sockIn[4]; | ||
453 | sprintf(sockIn, "%d", envSocket); | 434 | sprintf(sockIn, "%d", envSocket); | ||
454 | 435 | | |||
455 | #ifdef KWALLET5 | 436 | char *args[] = {strdup(kwalletd), "--pam-login", pipeInt, sockIn, NULL, NULL}; | ||
arrowd: I wonder why one of `NULL` wasn't removed completely? | |||||
The first of the NULL replaced extraArg naively. meven: The first of the NULL replaced `extraArg` naively.
You can send a simple MR for this. | |||||
456 | char* extraArg = NULL; | | |||
457 | #else | | |||
458 | char* extraArg = "--nofork"; | | |||
459 | #endif | | |||
460 | char *args[] = {strdup(kwalletd), "--pam-login", pipeInt, sockIn, extraArg, NULL}; | | |||
461 | execve(args[0], args, pam_getenvlist(pamh)); | 437 | execve(args[0], args, pam_getenvlist(pamh)); | ||
462 | syslog(LOG_ERR, "%s: could not execute kwalletd from %s", logPrefix, kwalletd); | 438 | syslog(LOG_ERR, "%s: could not execute kwalletd from %s", logPrefix, kwalletd); | ||
463 | 439 | | |||
464 | cleanup: | 440 | cleanup: | ||
465 | exit(EXIT_FAILURE); | 441 | exit(EXIT_FAILURE); | ||
466 | } | 442 | } | ||
467 | 443 | | |||
468 | static int better_write(int fd, const char *buffer, int len) | 444 | static int better_write(int fd, const char *buffer, int len) | ||
Show All 21 Lines | 461 | { | |||
490 | sigPipe.sa_handler = SIG_IGN; | 466 | sigPipe.sa_handler = SIG_IGN; | ||
491 | sigaction (SIGPIPE, &sigPipe, &oldSigPipe); | 467 | sigaction (SIGPIPE, &sigPipe, &oldSigPipe); | ||
492 | 468 | | |||
493 | int toWalletPipe[2] = { -1, -1}; | 469 | int toWalletPipe[2] = { -1, -1}; | ||
494 | if (pipe(toWalletPipe) < 0) { | 470 | if (pipe(toWalletPipe) < 0) { | ||
495 | pam_syslog(pamh, LOG_ERR, "%s: Couldn't create pipes", logPrefix); | 471 | pam_syslog(pamh, LOG_ERR, "%s: Couldn't create pipes", logPrefix); | ||
496 | } | 472 | } | ||
497 | 473 | | |||
498 | #ifdef KWALLET5 | | |||
499 | const char *socketPrefix = "kwallet5"; | 474 | const char *socketPrefix = "kwallet5"; | ||
500 | #else | | |||
501 | const char *socketPrefix = "kwallet"; | | |||
502 | #endif | | |||
503 | 475 | | |||
504 | char *fullSocket = NULL; | 476 | char *fullSocket = NULL; | ||
505 | if (socketPath) { | 477 | if (socketPath) { | ||
506 | size_t needed = snprintf(NULL, 0, "%s/%s_%s%s", socketPath, socketPrefix, userInfo->pw_name, ".socket"); | 478 | size_t needed = snprintf(NULL, 0, "%s/%s_%s%s", socketPath, socketPrefix, userInfo->pw_name, ".socket"); | ||
507 | needed += 1; | 479 | needed += 1; | ||
508 | fullSocket = malloc(needed); | 480 | fullSocket = malloc(needed); | ||
509 | snprintf(fullSocket, needed, "%s/%s_%s%s", socketPath, socketPrefix, userInfo->pw_name, ".socket"); | 481 | snprintf(fullSocket, needed, "%s/%s_%s%s", socketPath, socketPrefix, userInfo->pw_name, ".socket"); | ||
510 | } else { | 482 | } else { | ||
▲ Show 20 Lines • Show All 298 Lines • ▼ Show 20 Line(s) | 777 | { | |||
809 | } | 781 | } | ||
810 | 782 | | |||
811 | struct stat info; | 783 | struct stat info; | ||
812 | if (stat(userInfo->pw_dir, &info) != 0 || !S_ISDIR(info.st_mode)) { | 784 | if (stat(userInfo->pw_dir, &info) != 0 || !S_ISDIR(info.st_mode)) { | ||
813 | syslog(LOG_ERR, "%s-kwalletd: user home folder does not exist", logPrefix); | 785 | syslog(LOG_ERR, "%s-kwalletd: user home folder does not exist", logPrefix); | ||
814 | return 1; | 786 | return 1; | ||
815 | } | 787 | } | ||
816 | 788 | | |||
817 | #ifdef KWALLET5 | | |||
818 | const char *fixpath = "kwalletd/kdewallet.salt"; | 789 | const char *fixpath = "kwalletd/kdewallet.salt"; | ||
819 | #else | | |||
820 | const char *fixpath = "share/apps/kwallet/kdewallet.salt"; | | |||
821 | #endif | | |||
822 | size_t pathSize = strlen(userInfo->pw_dir) + strlen(kdehome) + strlen(fixpath) + 3;//3 == /, / and \0 | 790 | size_t pathSize = strlen(userInfo->pw_dir) + strlen(kdehome) + strlen(fixpath) + 3;//3 == /, / and \0 | ||
823 | char *path = (char*) malloc(pathSize); | 791 | char *path = (char*) malloc(pathSize); | ||
824 | sprintf(path, "%s/%s/%s", userInfo->pw_dir, kdehome, fixpath); | 792 | sprintf(path, "%s/%s/%s", userInfo->pw_dir, kdehome, fixpath); | ||
825 | 793 | | |||
826 | createNewSalt(pamh, path, userInfo); | 794 | createNewSalt(pamh, path, userInfo); | ||
827 | 795 | | |||
828 | char salt[KWALLET_PAM_SALTSIZE] = {}; | 796 | char salt[KWALLET_PAM_SALTSIZE] = {}; | ||
829 | const int readSaltSuccess = readSaltFile(pamh, path, userInfo, salt); | 797 | const int readSaltSuccess = readSaltFile(pamh, path, userInfo, salt); | ||
Show All 30 Lines |
I wonder why one of NULL wasn't removed completely?