Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- pam_kwallet_old.c 2020-02-19 23:03:03.952797869 +0100
- +++ pam_kwallet.c 2020-02-19 22:47:03.689180218 +0100
- @@ -360,6 +360,7 @@
- static void execute_kwallet(pam_handle_t *pamh, struct passwd *userInfo, int toWalletPipe[2], char *fullSocket)
- {
- + syslog(LOG_DEBUG, "%s: Function execute_kwallet...\n", logPrefix);
- //In the child pam_syslog does not work, using syslog directly
- //keep stderr open so socket doesn't returns us that fd
- int x = 3;
- @@ -375,47 +376,26 @@
- //Change to the user in case we are not it yet
- if (drop_privileges(userInfo) < 0) {
- - syslog(LOG_ERR, "%s: could not set gid/uid/euid/egit for kwalletd", logPrefix);
- + syslog(LOG_ERR, "%s: could not set gid/uid/euid/egit for kwalletd\n", logPrefix);
- free(fullSocket);
- goto cleanup;
- }
- -
- - int envSocket;
- - if ((envSocket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
- - syslog(LOG_ERR, "%s: couldn't create socket", logPrefix);
- - free(fullSocket);
- + //Create a named pipe
- + syslog(LOG_DEBUG, "%s: Creating named pipe...\n", logPrefix);
- + if(access(fullSocket, F_OK) != -1 && remove(fullSocket) == -1) {
- + syslog(LOG_DEBUG, "%s: couldn't remove previous file: %s\n", logPrefix, fullSocket);
- goto cleanup;
- }
- -
- - struct sockaddr_un local;
- - local.sun_family = AF_UNIX;
- -
- - if (strlen(fullSocket) > sizeof(local.sun_path)) {
- - syslog(LOG_ERR, "%s: socket path %s too long to open",
- - logPrefix, fullSocket);
- - free(fullSocket);
- - goto cleanup;
- - }
- - strcpy(local.sun_path, fullSocket);
- - free(fullSocket);
- - fullSocket = NULL;
- - unlink(local.sun_path);//Just in case it exists from a previous login
- -
- - syslog(LOG_DEBUG, "%s: final socket path: %s", logPrefix, local.sun_path);
- -
- - size_t len = strlen(local.sun_path) + sizeof(local.sun_family);
- - if (bind(envSocket, (struct sockaddr *)&local, len) == -1) {
- - syslog(LOG_INFO, "%s-kwalletd: Couldn't bind to local file\n", logPrefix);
- + if(mkfifo(fullSocket, 0755) == -1) {
- + syslog(LOG_DEBUG, "%s: couldn't create named pipe: %s\n", logPrefix, fullSocket);
- goto cleanup;
- }
- - if (listen(envSocket, 5) == -1) {
- - syslog(LOG_INFO, "%s-kwalletd: Couldn't listen in socket\n", logPrefix);
- - goto cleanup;
- - }
- + syslog(LOG_DEBUG, "%s: final named pipe path: %s\n", logPrefix, fullSocket);
- +
- //finally close stderr
- close(2);
- -
- +
- // Fork twice to daemonize kwallet
- setsid();
- pid_t pid = fork();
- @@ -430,12 +410,12 @@
- //TODO use a pam argument for full path kwalletd
- char pipeInt[4];
- sprintf(pipeInt, "%d", toWalletPipe[0]);
- - char sockIn[4];
- - sprintf(sockIn, "%d", envSocket);
- - char *args[] = {strdup(kwalletd), "--pam-login", pipeInt, sockIn, NULL, NULL};
- + syslog(LOG_DEBUG, "%s: hash pipe: %d; env pipe path: %s\n", logPrefix, toWalletPipe[0], fullSocket);
- + syslog(LOG_DEBUG, "%s: Starting kwalletd...\n", logPrefix);
- + char *args[] = {strdup(kwalletd), "--pam-login", pipeInt, fullSocket, NULL, NULL};
- execve(args[0], args, pam_getenvlist(pamh));
- - syslog(LOG_ERR, "%s: could not execute kwalletd from %s", logPrefix, kwalletd);
- + syslog(LOG_ERR, "%s: could not execute kwalletd from %s\n", logPrefix, kwalletd);
- cleanup:
- exit(EXIT_FAILURE);
Advertisement
Add Comment
Please, Sign In to add comment