summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2012-09-25 10:07:29 +0200
committerPavel Březina <pbrezina@redhat.com>2012-10-08 13:13:41 +0200
commit848557a2af640bffe4787dd4ac145bcbd4e73559 (patch)
treea7de14d61c3158ffa4ddf368fd3f5c94f0a34242
parent7dc7bb79754769cc9f7ac05c6057e07be7b0d844 (diff)
downloadsssd_unused-pam-close-fd-after-request-is-finished.zip
sssd_unused-pam-close-fd-after-request-is-finished.tar.gz
sssd_unused-pam-close-fd-after-request-is-finished.tar.xz
-rw-r--r--src/sss_client/common.c36
-rw-r--r--src/sss_client/pam_sss.c4
2 files changed, 40 insertions, 0 deletions
diff --git a/src/sss_client/common.c b/src/sss_client/common.c
index 1ef3ba1..9db04c8 100644
--- a/src/sss_client/common.c
+++ b/src/sss_client/common.c
@@ -40,6 +40,7 @@
#include <fcntl.h>
#include <poll.h>
#include <time.h>
+#include <stdio.h>
#include <libintl.h>
#define _(STRING) dgettext (PACKAGE, STRING)
@@ -62,6 +63,8 @@
#define SSS_DEFAULT_WRITE_FLAGS 0
#endif
+#define DEBUG(X, ...) fprintf(stderr, X, ##__VA_ARGS__)
+
/* common functions */
int sss_cli_sd = -1; /* the sss client socket descriptor */
@@ -158,6 +161,7 @@ static enum sss_status sss_cli_send_req(enum sss_cli_command cmd,
SSS_DEFAULT_WRITE_FLAGS);
}
error = errno;
+ DEBUG("send: res %d error %d\n", res, error);
if ((res == -1) || (res == 0)) {
if ((error == EINTR) || error == EAGAIN) {
@@ -268,6 +272,7 @@ static enum sss_status sss_cli_recv_rep(enum sss_cli_command cmd,
header[0] - datarecv);
}
error = errno;
+ DEBUG("read: res %d error %d\n", res, error);
if ((res == -1) || (res == 0)) {
if ((error == EINTR) || error == EAGAIN) {
@@ -353,16 +358,24 @@ static enum sss_status sss_cli_make_request_nochecks(
int len = 0;
/* send data */
+ DEBUG("sending data...\n");
ret = sss_cli_send_req(cmd, rd, errnop);
if (ret != SSS_STATUS_SUCCESS) {
return ret;
}
+ DEBUG("sending data done\n");
+ DEBUG("responder status: %d\n", ret);
+ DEBUG("errnop: %d\n", *errnop);
/* data sent, now get reply */
+ DEBUG("receiving data...\n");
ret = sss_cli_recv_rep(cmd, &buf, &len, errnop);
if (ret != SSS_STATUS_SUCCESS) {
return ret;
}
+ DEBUG("receiving data done\n");
+ DEBUG("responder status: %d\n", ret);
+ DEBUG("errnop: %d\n", *errnop);
/* we got through, now we have the custom data in buf if any,
* return it if requested */
@@ -395,6 +408,8 @@ static bool sss_cli_check_version(const char *socket_name)
uint32_t obtained_version;
struct sss_cli_req_data req;
+ DEBUG("checking cli version: %s\n", socket_name);
+
if (strcmp(socket_name, SSS_NSS_SOCKET_NAME) == 0) {
expected_version = SSS_NSS_PROTOCOL_VERSION;
} else if (strcmp(socket_name, SSS_PAM_SOCKET_NAME) == 0 ||
@@ -409,25 +424,30 @@ static bool sss_cli_check_version(const char *socket_name)
} else if (strcmp(socket_name, SSS_PAC_SOCKET_NAME) == 0) {
expected_version = SSS_PAC_PROTOCOL_VERSION;
} else {
+ DEBUG("checking cli version: returning false\n");
return false;
}
req.len = sizeof(expected_version);
req.data = &expected_version;
+ DEBUG("checking cli version: making new request\n");
nret = sss_cli_make_request_nochecks(SSS_GET_VERSION, &req,
&repbuf, &replen, &errnop);
if (nret != SSS_STATUS_SUCCESS) {
+ DEBUG("checking cli version: returning false\n");
return false;
}
if (!repbuf) {
+ DEBUG("checking cli version: returning false\n");
return false;
}
obtained_version = ((uint32_t *)repbuf)[0];
free(repbuf);
+ DEBUG("checking cli version: returning %d\n", (obtained_version == expected_version));
return (obtained_version == expected_version);
}
@@ -632,6 +652,7 @@ static enum sss_status sss_cli_check_socket(int *errnop, const char *socket_name
int mysd;
int ret;
+ DEBUG("checking socket %d\n", sss_cli_sd);
if (getpid() != mypid) {
ret = fstat(sss_cli_sd, &mysb);
if (ret == 0) {
@@ -647,6 +668,7 @@ static enum sss_status sss_cli_check_socket(int *errnop, const char *socket_name
/* check if the socket has been closed on the other side */
if (sss_cli_sd != -1) {
+ DEBUG("testing if socket %d was closed\n", sss_cli_sd);
struct pollfd pfd;
int res, error;
@@ -685,25 +707,32 @@ static enum sss_status sss_cli_check_socket(int *errnop, const char *socket_name
break;
}
if (*errnop == 0) {
+ DEBUG("socket %d still works\n", sss_cli_sd);
+ DEBUG("socket check completed\n");
return SSS_STATUS_SUCCESS;
}
sss_cli_close_socket();
}
+ DEBUG("socket %d was closed, opening new\n", sss_cli_sd);
mysd = sss_cli_open_socket(errnop, socket_name);
if (mysd == -1) {
+ DEBUG("socket check completed\n");
return SSS_STATUS_UNAVAIL;
}
+ DEBUG("new socket: %d\n", mysd);
sss_cli_sd = mysd;
if (sss_cli_check_version(socket_name)) {
+ DEBUG("socket check completed\n");
return SSS_STATUS_SUCCESS;
}
sss_cli_close_socket();
*errnop = EFAULT;
+ DEBUG("socket check completed\n");
return SSS_STATUS_UNAVAIL;
}
@@ -805,6 +834,8 @@ int sss_pam_make_request(enum sss_cli_command cmd,
char *envval;
struct stat stat_buf;
+ DEBUG("pam request: %d\n", cmd);
+
sss_pam_lock();
/* avoid looping in the pam daemon */
@@ -848,6 +879,8 @@ int sss_pam_make_request(enum sss_cli_command cmd,
status = sss_cli_check_socket(errnop, SSS_PAM_SOCKET_NAME);
}
+ DEBUG("responder status: %d\n", status);
+ DEBUG("errnop: %d\n", *errnop);
if (status != SSS_STATUS_SUCCESS) {
ret = PAM_SERVICE_ERR;
goto out;
@@ -861,12 +894,15 @@ int sss_pam_make_request(enum sss_cli_command cmd,
goto out;
}
+ DEBUG("sending sssd request sss_cli_make_request_nochecks\n");
status = sss_cli_make_request_nochecks(cmd, rd, repbuf, replen, errnop);
if (status == SSS_STATUS_SUCCESS) {
ret = PAM_SUCCESS;
} else {
ret = PAM_SERVICE_ERR;
}
+ DEBUG("responder status: %d\n", status);
+ DEBUG("errnop: %d\n", *errnop);
out:
sss_pam_unlock();
diff --git a/src/sss_client/pam_sss.c b/src/sss_client/pam_sss.c
index efbc48b..4d87389 100644
--- a/src/sss_client/pam_sss.c
+++ b/src/sss_client/pam_sss.c
@@ -23,6 +23,8 @@
#define PAM_SM_ACCOUNT
#define PAM_SM_SESSION
#define PAM_SM_PASSWORD
+#define DEBUG(X, ...) fprintf(stderr, X, ##__VA_ARGS__)
+#define PAM_DEBUG
#include "config.h"
#include <sys/types.h>
@@ -1077,6 +1079,8 @@ static int send_and_receive(pam_handle_t *pamh, struct pam_items *pi,
errnop = 0;
ret = sss_pam_make_request(task, &rd, &repbuf, &replen, &errnop);
+ DEBUG("sss_pam_make_request returned responder status: %d\n", ret);
+ DEBUG("sss_pam_make_request returned errnop: %d\n", errnop);
if (ret != PAM_SUCCESS) {
if (errnop != 0) {