From: Bartlomiej Grzelewski Date: Fri, 8 Mar 2013 16:38:57 +0000 (+0100) Subject: Read or write may be interrupt. X-Git-Tag: submit/tizen_2.1/20130424.233001~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4455d568ecbbb48187d1bb590460482041cbcca0;p=platform%2Fcore%2Fsecurity%2Fsecurity-server.git Read or write may be interrupt. This commits add suport for interruption of read or write. Please note that we still need to add support for sitation when read or write returns less that we expect. [Issue#] N/A [Bug] N/A [Cause] N/A [Solution] N/A [Verification] Run all security-server tests. Change-Id: I799fd41245cce004582458f98f49511a2860ff0e --- diff --git a/src/communication/security-server-comm.c b/src/communication/security-server-comm.c index 0d5ed9c..eac1c55 100644 --- a/src/communication/security-server-comm.c +++ b/src/communication/security-server-comm.c @@ -515,7 +515,7 @@ int send_generic_response (int sockfd, unsigned char msgid, unsigned char return } /* Send to client */ - size = write(sockfd, &hdr, sizeof(hdr)); + size = TEMP_FAILURE_RETRY(write(sockfd, &hdr, sizeof(hdr))); if(size < (int)sizeof(hdr)) return SECURITY_SERVER_ERROR_SEND_FAILED; @@ -563,7 +563,7 @@ int send_cookie(int sockfd, unsigned char *cookie) return SECURITY_SERVER_ERROR_SEND_FAILED; } - ret = write(sockfd, msg, sizeof(hdr) + SECURITY_SERVER_COOKIE_LEN); + ret = TEMP_FAILURE_RETRY(write(sockfd, msg, sizeof(hdr) + SECURITY_SERVER_COOKIE_LEN)); if(ret < (int)(sizeof(hdr) + SECURITY_SERVER_COOKIE_LEN)) { /* Error on writing */ @@ -613,7 +613,7 @@ int send_object_name(int sockfd, char *obj) return SECURITY_SERVER_ERROR_SEND_FAILED; } - ret = write(sockfd, msg, sizeof(hdr) + strlen(obj)); + ret = TEMP_FAILURE_RETRY(write(sockfd, msg, sizeof(hdr) + strlen(obj))); if(ret < sizeof(hdr) + strlen(obj)) { /* Error on writing */ @@ -667,7 +667,7 @@ int send_gid(int sockfd, int gid) } /* Send it */ - ret = write(sockfd, msg, sizeof(hdr) + sizeof(gid)); + ret = TEMP_FAILURE_RETRY(write(sockfd, msg, sizeof(hdr) + sizeof(gid))); if(ret < sizeof(hdr) + sizeof(gid)) { /* Error on writing */ @@ -721,7 +721,7 @@ int send_pid(int sockfd, int pid) } /* Send it */ - ret = write(sockfd, msg, sizeof(hdr) + sizeof(pid)); + ret = TEMP_FAILURE_RETRY(write(sockfd, msg, sizeof(hdr) + sizeof(pid))); if(ret < sizeof(hdr) + sizeof(pid)) { /* Error on writing */ @@ -779,7 +779,7 @@ int send_smack(int sockfd, char * label) } /* Send it */ - ret = write(sockfd, msg, PACKET_SIZE); + ret = TEMP_FAILURE_RETRY(write(sockfd, msg, PACKET_SIZE)); if(ret < PACKET_SIZE) { /* Error on writing */ @@ -850,7 +850,7 @@ int send_pwd_response(const int sockfd, } /* Send it */ - ret = write(sockfd, msg, ptr); + ret = TEMP_FAILURE_RETRY(write(sockfd, msg, ptr)); if(ret < ptr) { /* Error on writing */ @@ -893,7 +893,7 @@ int send_cookie_request(int sock_fd) } /* Send to server */ - retval = write(sock_fd, &hdr, sizeof(hdr)); + retval = TEMP_FAILURE_RETRY(write(sock_fd, &hdr, sizeof(hdr))); if(retval < sizeof(hdr)) { /* Write error */ @@ -959,7 +959,7 @@ int send_gid_request(int sock_fd, const char* object) goto error; } - retval = write(sock_fd, buf, send_len); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, send_len)); if(retval < send_len) { /* Write error */ @@ -1014,7 +1014,7 @@ int send_object_name_request(int sock_fd, int gid) } /* Send to server */ - retval = write(sock_fd, buf, sizeof(buf)); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, sizeof(buf))); if(retval < sizeof(buf)) { /* Write error */ @@ -1069,7 +1069,7 @@ int send_privilege_check_request(int sock_fd, const char*cookie, int gid) } /* Send to server */ - retval = write(sock_fd, buf, sizeof(buf)); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, sizeof(buf))); if(retval < sizeof(buf)) { /* Write error */ @@ -1128,7 +1128,7 @@ int send_privilege_check_new_request(int sock_fd, size = sizeof(hdr) + SECURITY_SERVER_COOKIE_LEN + 2*sizeof(int) + olen + alen; /* Send to server */ - retval = write(sock_fd, buf, size); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, size)); if(retval < size) { /* Write error */ @@ -1180,7 +1180,7 @@ int send_smack_request(int sock_fd, const char * cookie) } /* Send to server */ - retval = write(sock_fd, buf, sizeof(buf)); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, sizeof(buf))); if(retval < sizeof(buf)) { /* Write error */ @@ -1232,7 +1232,7 @@ int send_pid_request(int sock_fd, const char*cookie) } /* Send to server */ - retval = write(sock_fd, buf, sizeof(buf)); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, sizeof(buf))); if(retval < sizeof(buf)) { /* Write error */ @@ -1345,7 +1345,7 @@ int send_launch_tool_request(int sock_fd, int argc, const char **argv) } /* Send to server */ - retval = write(sock_fd, buf, total_length); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, total_length)); if(retval < sizeof(buf)) { /* Write error */ @@ -1395,7 +1395,7 @@ int send_valid_pwd_request(int sock_fd) } /* Send to server */ - retval = write(sock_fd, &hdr, sizeof(hdr)); + retval = TEMP_FAILURE_RETRY(write(sock_fd, &hdr, sizeof(hdr))); if(retval < sizeof(hdr)) { /* Write error */ @@ -1493,7 +1493,7 @@ int send_set_pwd_request(int sock_fd, } /* Send to server */ - retval = write(sock_fd, buf, total_length); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, total_length)); if(retval < sizeof(buf)) { /* Write error */ @@ -1559,7 +1559,7 @@ int send_set_pwd_validity_request(int sock_fd, const unsigned int valid_period_i } /* Send to server */ - retval = write(sock_fd, buf, total_length); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, total_length)); if(retval < sizeof(buf)) { /* Write error */ @@ -1625,7 +1625,7 @@ int send_set_pwd_max_challenge_request(int sock_fd, const unsigned int max_chall } /* Send to server */ - retval = write(sock_fd, buf, total_length); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, total_length)); if(retval < sizeof(buf)) { /* Write error */ @@ -1711,7 +1711,7 @@ int send_reset_pwd_request(int sock_fd, } /* Send to server */ - retval = write(sock_fd, buf, total_length); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, total_length)); if(retval < sizeof(buf)) { /* Write error */ @@ -1784,7 +1784,7 @@ int send_chk_pwd_request(int sock_fd, const char*challenge) } /* Send to server */ - retval = write(sock_fd, buf, total_length); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, total_length)); if(retval < sizeof(buf)) { /* Write error */ @@ -1846,7 +1846,7 @@ int send_set_pwd_history_request(int sock_fd, int num) } /* Send to server */ - retval = write(sock_fd, buf, ptr); + retval = TEMP_FAILURE_RETRY(write(sock_fd, buf, ptr)); if(retval < sizeof(buf)) { /* Write error */ @@ -1879,7 +1879,7 @@ int recv_hdr(int client_sockfd, basic_header *basic_hdr) } /* Receive request header first */ - retval = read(client_sockfd, basic_hdr, sizeof(basic_header)); + retval = TEMP_FAILURE_RETRY(read(client_sockfd, basic_hdr, sizeof(basic_header))); if(retval < sizeof(basic_header)) { SEC_SVR_DBG("read failed. closing socket %d", retval); @@ -1896,14 +1896,14 @@ int recv_hdr(int client_sockfd, basic_header *basic_hdr) int recv_check_privilege_request(int sockfd, unsigned char *requested_cookie, int *requested_privilege) { int retval; - retval = read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN)); if(retval < SECURITY_SERVER_COOKIE_LEN) { SEC_SVR_DBG("Received cookie size is too small: %d", retval); return SECURITY_SERVER_ERROR_RECV_FAILED; } - retval = read(sockfd, requested_privilege, sizeof(int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_privilege, sizeof(int))); if(retval < sizeof(int)) { SEC_SVR_DBG("privilege size is too small: %d", retval); @@ -1921,28 +1921,28 @@ int recv_check_privilege_new_request(int sockfd, int retval; int olen, alen; - retval = read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN)); if(retval < SECURITY_SERVER_COOKIE_LEN) { SEC_SVR_DBG("Received cookie size is too small: %d", retval); return SECURITY_SERVER_ERROR_RECV_FAILED; } - retval = read(sockfd, &olen, sizeof(int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &olen, sizeof(int))); if(retval < sizeof(int) || olen < 0 || olen > MAX_OBJECT_LABEL_LEN) { SEC_SVR_DBG("error reading object_label len: %d", retval); return SECURITY_SERVER_ERROR_RECV_FAILED; } - retval = read(sockfd, &alen, sizeof(int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &alen, sizeof(int))); if(retval < sizeof(int) || alen < 0 || alen > MAX_MODE_STR_LEN) { SEC_SVR_DBG("error reading access_rights len: %d", retval); return SECURITY_SERVER_ERROR_RECV_FAILED; } - retval = read(sockfd, object_label, olen); + retval = TEMP_FAILURE_RETRY(read(sockfd, object_label, olen)); if(retval < olen) { SEC_SVR_DBG("error reading object_label: %d", retval); @@ -1950,7 +1950,7 @@ int recv_check_privilege_new_request(int sockfd, } object_label[olen] = '\0'; - retval = read(sockfd, access_rights, olen); + retval = TEMP_FAILURE_RETRY(read(sockfd, access_rights, alen)); if(retval < alen) { SEC_SVR_DBG("error reading access_rights: %d", retval); @@ -1965,7 +1965,7 @@ int recv_check_privilege_new_request(int sockfd, int recv_pid_request(int sockfd, unsigned char *requested_cookie) { int retval; - retval = read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN)); if(retval < SECURITY_SERVER_COOKIE_LEN) { SEC_SVR_DBG("Received cookie size is too small: %d", retval); @@ -1978,7 +1978,7 @@ int recv_pid_request(int sockfd, unsigned char *requested_cookie) int recv_smack_request(int sockfd, unsigned char *requested_cookie) { int retval; - retval = read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_cookie, SECURITY_SERVER_COOKIE_LEN)); if(retval < SECURITY_SERVER_COOKIE_LEN) { SEC_SVR_DBG("Received cookie size is too small: %d", retval); @@ -1998,7 +1998,7 @@ int recv_launch_tool_request(int sockfd, int argc, char *argv[]) for(i=1;ireturn_code); - retval = read(sockfd, gid, sizeof(int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, gid, sizeof(int))); if(retval < sizeof(int)) { /* Error on socket */ @@ -2101,7 +2101,7 @@ int recv_get_object_name(int sockfd, response_header *hdr, char *object, int max } /* Read response */ - retval = read(sockfd, hdr, sizeof(response_header)); + retval = TEMP_FAILURE_RETRY(read(sockfd, hdr, sizeof(response_header))); if(retval < sizeof(hdr) ) { /* Error on socket */ @@ -2129,7 +2129,7 @@ int recv_get_object_name(int sockfd, response_header *hdr, char *object, int max return SECURITY_SERVER_ERROR_OUT_OF_MEMORY; } - retval = read(sockfd, local_obj_name, hdr->basic_hdr.msg_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, local_obj_name, hdr->basic_hdr.msg_len)); if(retval < (hdr->basic_hdr.msg_len)) { /* Error on socket */ @@ -2162,7 +2162,7 @@ int recv_cookie(int sockfd, response_header *hdr, char *cookie) if(retval != SECURITY_SERVER_SUCCESS) return return_code_to_error_code(hdr->return_code); - retval = read(sockfd, cookie, SECURITY_SERVER_COOKIE_LEN); + retval = TEMP_FAILURE_RETRY(read(sockfd, cookie, SECURITY_SERVER_COOKIE_LEN)); if(retval < SECURITY_SERVER_COOKIE_LEN) { /* Error on socket */ @@ -2208,7 +2208,7 @@ int recv_smack_response(int sockfd, response_header *hdr, char * label) if(retval != SECURITY_SERVER_SUCCESS) return return_code_to_error_code(hdr->return_code); - retval = read(sockfd, label, SMACK_LABEL_LEN + 1); + retval = TEMP_FAILURE_RETRY(read(sockfd, label, SMACK_LABEL_LEN + 1)); if(retval < sizeof(int)) { /* Error on socket */ @@ -2226,7 +2226,7 @@ int recv_pid_response(int sockfd, response_header *hdr, int *pid) if(retval != SECURITY_SERVER_SUCCESS) return return_code_to_error_code(hdr->return_code); - retval = read(sockfd, pid, sizeof(int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, pid, sizeof(int))); if(retval < sizeof(int)) { /* Error on socket */ @@ -2263,21 +2263,21 @@ int recv_pwd_response(int sockfd, response_header *hdr, return return_code_to_error_code(hdr->return_code); } - retval = read(sockfd, current_attempts, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, current_attempts, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { /* Error on socket */ SEC_SVR_DBG("Client: Receive failed %d", retval); return SECURITY_SERVER_ERROR_RECV_FAILED; } - retval = read(sockfd, max_attempts, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, max_attempts, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { /* Error on socket */ SEC_SVR_DBG("Client: Receive failed %d", retval); return SECURITY_SERVER_ERROR_RECV_FAILED; } - retval = read(sockfd, valid_secs, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, valid_secs, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { /* Error on socket */ diff --git a/src/server/security-server-cookie.c b/src/server/security-server-cookie.c index f022c80..6ed2f30 100644 --- a/src/server/security-server-cookie.c +++ b/src/server/security-server-cookie.c @@ -339,7 +339,7 @@ int generate_random_cookie(unsigned char *cookie, int size) SEC_SVR_DBG("%s", "Cannot open /dev/urandom"); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - ret = read(fd, cookie, size); + ret = TEMP_FAILURE_RETRY(read(fd, cookie, size)); if(ret < size) { SEC_SVR_DBG("Cannot read /dev/urandom: %d", ret); @@ -570,7 +570,7 @@ int check_stored_cookie(unsigned char *cookie, int size) ret = SECURITY_SERVER_ERROR_FILE_OPERATION; goto error; } - ret = write(fd, cookie, size); + ret = TEMP_FAILURE_RETRY(write(fd, cookie, size)); if(ret < size) { SEC_SVR_DBG("%s", "Cannot save default cookie"); @@ -582,7 +582,7 @@ int check_stored_cookie(unsigned char *cookie, int size) return SECURITY_SERVER_SUCCESS; } - ret = read (fd, cookie, size); + ret = TEMP_FAILURE_RETRY(read(fd, cookie, size)); if(ret < size) { SEC_SVR_DBG("Cannot read default cookie errno=%d", errno); diff --git a/src/server/security-server-main.c b/src/server/security-server-main.c index 39d9094..cd44fa9 100644 --- a/src/server/security-server-main.c +++ b/src/server/security-server-main.c @@ -574,7 +574,7 @@ int process_object_name_request(int sockfd) } /* Receive GID */ - retval = read(sockfd, &requested_privilege, sizeof(requested_privilege)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &requested_privilege, sizeof(requested_privilege))); if (retval < (int)sizeof(requested_privilege)) { SEC_SVR_DBG("%s", "Receiving request failed"); @@ -665,7 +665,7 @@ int process_gid_request(int sockfd, int msg_len) } /* Receive group name */ - retval = read(sockfd, object_name, msg_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, object_name, msg_len)); if (retval < msg_len ) { SEC_SVR_DBG("%s", "Failed to read object name"); diff --git a/src/server/security-server-password.c b/src/server/security-server-password.c index 17e77e6..c2fb0b8 100644 --- a/src/server/security-server-password.c +++ b/src/server/security-server-password.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "security-server-password.h" @@ -145,7 +146,7 @@ int load_password(unsigned char *cur_pwd, unsigned int *max_attempt, unsigned in } /* Read and store into memory */ - retval = read(fd, cur_pwd, SECURITY_SERVER_HASHED_PWD_LEN); + retval = TEMP_FAILURE_RETRY(read(fd, cur_pwd, SECURITY_SERVER_HASHED_PWD_LEN)); if(retval < SECURITY_SERVER_HASHED_PWD_LEN) { SEC_SVR_DBG("%s", "Server: Current password corrupted. resetting to previous one. 0"); @@ -155,7 +156,7 @@ int load_password(unsigned char *cur_pwd, unsigned int *max_attempt, unsigned in continue; } - retval = read(fd, max_attempt, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(fd, max_attempt, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("%s", "Server: Current password corrupted. resetting to previous one. 1"); @@ -165,7 +166,7 @@ int load_password(unsigned char *cur_pwd, unsigned int *max_attempt, unsigned in continue; } - retval = read(fd, expire_time, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(fd, expire_time, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("%s", "Server: Current password corrupted. resetting to previous one. 2"); @@ -219,7 +220,7 @@ int get_current_attempt(int increase) return SECURITY_SERVER_ERROR_FILE_OPERATION; } attempt = increase; - retval = write(fd, &attempt, sizeof(int)); + retval = TEMP_FAILURE_RETRY(write(fd, &attempt, sizeof(int))); close(fd); if(retval < sizeof(int)) { @@ -231,7 +232,7 @@ int get_current_attempt(int increase) SEC_SVR_DBG("Current password cannot be opened. errno: %d", errno); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - retval = read(fd, &attempt, sizeof(int)); + retval = TEMP_FAILURE_RETRY(read(fd, &attempt, sizeof(int))); close(fd); if(retval < sizeof(int)) { @@ -256,7 +257,7 @@ int get_current_attempt(int increase) return SECURITY_SERVER_ERROR_FILE_OPERATION; } attempt += increase; - retval = write(fd, &attempt, sizeof(int)); + retval = TEMP_FAILURE_RETRY(write(fd, &attempt, sizeof(int))); close(fd); if(retval < sizeof(int)) { @@ -290,7 +291,7 @@ int reset_attempt(void) close(fd); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - retval = write(fd, &attempt, sizeof(int)); + retval = TEMP_FAILURE_RETRY(write(fd, &attempt, sizeof(int))); close(fd); if(retval < sizeof(int)) { @@ -374,7 +375,7 @@ int set_history(int num) close(fd); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - retval = write(fd, &num, sizeof(int)); + retval = TEMP_FAILURE_RETRY(write(fd, &num, sizeof(int))); close(fd); if(retval < sizeof(int)) { @@ -408,7 +409,7 @@ int get_history_num(void) SEC_SVR_DBG("Server ERROR: history file cannot be opened. errno: %d", errno); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - retval = read(fd, &history, sizeof(history)); + retval = TEMP_FAILURE_RETRY(read(fd, &history, sizeof(history))); close(fd); if(retval < sizeof(history)) { @@ -469,7 +470,7 @@ int check_history(const unsigned char *requested_pwd) return SECURITY_SERVER_ERROR_FILE_OPERATION; } /* Read and store into memory */ - retval = read(fd, history_pwd, SECURITY_SERVER_HASHED_PWD_LEN); + retval = TEMP_FAILURE_RETRY(read(fd, history_pwd, SECURITY_SERVER_HASHED_PWD_LEN)); if(retval < SECURITY_SERVER_HASHED_PWD_LEN) { SEC_SVR_DBG("%s", "Current password corrupted. resetting to previous one. 0"); @@ -542,21 +543,21 @@ int set_password(const unsigned char *requested_new_pwd, const unsigned int atte close(fd); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - retval = write(fd, requested_new_pwd, SECURITY_SERVER_HASHED_PWD_LEN); + retval = TEMP_FAILURE_RETRY(write(fd, requested_new_pwd, SECURITY_SERVER_HASHED_PWD_LEN)); if(retval < SECURITY_SERVER_HASHED_PWD_LEN) { SEC_SVR_DBG("%s", "Cannot write password"); close(fd); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - retval = write(fd, &attempts, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(write(fd, &attempts, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("%s", "Cannot write password"); close(fd); return SECURITY_SERVER_ERROR_FILE_OPERATION; } - retval = write(fd, &expire_time, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(write(fd, &expire_time, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("%s", "Cannot write password"); @@ -750,7 +751,7 @@ int process_set_pwd_request(int sockfd) } /* Receive size of pwds */ - retval = read(sockfd, &cur_pwd_len, sizeof(char)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &cur_pwd_len, sizeof(char))); if(retval < sizeof(char) || cur_pwd_len > SECURITY_SERVER_MAX_PASSWORD_LEN) { SEC_SVR_DBG("Server Error: current password length recieve failed: %d, %d", retval, cur_pwd_len); @@ -763,7 +764,7 @@ int process_set_pwd_request(int sockfd) } goto error; } - retval = read(sockfd, &new_pwd_len, sizeof(char)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &new_pwd_len, sizeof(char))); if(retval < sizeof(char) || new_pwd_len > SECURITY_SERVER_MAX_PASSWORD_LEN || new_pwd_len < 0) { SEC_SVR_DBG("Server Error: new password length recieve failed: %d, %d", retval, new_pwd_len); @@ -782,7 +783,7 @@ int process_set_pwd_request(int sockfd) { /* Check wheter current password is exist */ if(password_set == SECURITY_SERVER_SUCCESS) - retval = read(sockfd, requested_cur_pwd, cur_pwd_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_cur_pwd, cur_pwd_len)); if(retval < cur_pwd_len) { SEC_SVR_DBG("Server Error: current password recieve failed: %d", retval); @@ -814,7 +815,7 @@ int process_set_pwd_request(int sockfd) } /* Receive new password */ - retval = read(sockfd, requested_new_pwd, new_pwd_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_new_pwd, new_pwd_len)); if(retval < new_pwd_len) { SEC_SVR_DBG("Server Error: new password recieve failed: %d", retval); @@ -830,7 +831,7 @@ int process_set_pwd_request(int sockfd) requested_new_pwd[new_pwd_len] = 0; /* Receive max attempt */ - retval = read(sockfd, &received_attempts, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &received_attempts, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("Sever Error: Max attempt receive failed: %d", retval); @@ -845,7 +846,7 @@ int process_set_pwd_request(int sockfd) } /* Receive valid period */ - retval = read(sockfd, &valid_days, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &valid_days, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("Sever Error: Max attempt receive failed: %d", retval); @@ -1043,7 +1044,7 @@ int process_reset_pwd_request(int sockfd) } /* Receive size of pwd */ - retval = read(sockfd, &new_pwd_len, sizeof(char)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &new_pwd_len, sizeof(char))); if(retval < sizeof(char) || new_pwd_len < 0 || new_pwd_len > SECURITY_SERVER_MAX_PASSWORD_LEN) { SEC_SVR_DBG("Server Error: new password length recieve failed: %d, %d", retval, new_pwd_len); @@ -1058,7 +1059,7 @@ int process_reset_pwd_request(int sockfd) } /* Receive new password */ - retval = read(sockfd, requested_new_pwd, new_pwd_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_new_pwd, new_pwd_len)); if(retval < new_pwd_len) { SEC_SVR_DBG("Server Error: new password recieve failed: %d", retval); @@ -1074,7 +1075,7 @@ int process_reset_pwd_request(int sockfd) requested_new_pwd[new_pwd_len] = 0; /* Receive max attempt */ - retval = read(sockfd, &received_attempts, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &received_attempts, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("Sever Error: Max attempt receive failed: %d", retval); @@ -1089,7 +1090,7 @@ int process_reset_pwd_request(int sockfd) } /* Receive valid period */ - retval = read(sockfd, &valid_days, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &valid_days, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("Sever Error: Max attempt receive failed: %d", retval); @@ -1203,7 +1204,7 @@ int process_chk_pwd_request(int sockfd) } /* Receive size of challenge */ - retval = read(sockfd, &challenge_len, sizeof(char)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &challenge_len, sizeof(char))); if(retval < sizeof(char) || challenge_len > SECURITY_SERVER_MAX_PASSWORD_LEN) { SEC_SVR_DBG("Server ERROR: challenge length recieve failed: %d", retval); @@ -1219,7 +1220,7 @@ int process_chk_pwd_request(int sockfd) /* Receive challenge */ if(challenge_len > 0) { - retval = read(sockfd, requested_challenge, challenge_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, requested_challenge, challenge_len)); if(retval < challenge_len) { SEC_SVR_DBG("Server ERROR: current password recieve failed: %d", retval); @@ -1375,7 +1376,7 @@ int process_set_pwd_history_request(int sockfd) } /* Receive size of pwds */ - retval = read(sockfd, &history_num, sizeof(char)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &history_num, sizeof(char))); if(retval < sizeof(char) || history_num > SECURITY_SERVER_MAX_PASSWORD_HISTORY || history_num < 0 ) { SEC_SVR_DBG("Server Error: History number recieve failed: %d, %d", retval, history_num); @@ -1423,7 +1424,7 @@ int process_set_pwd_max_challenge_request(int sockfd) // TODO here we should probably check if the peer has rights to change // this value (max challenge) for current password - retval = read(sockfd, &max_challenge, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &max_challenge, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("Server Error: recieve failed: %d", retval); @@ -1503,7 +1504,7 @@ int process_set_pwd_validity_request(int sockfd) // TODO here we should probably check if the peer has rights to change // this value (validity) for current password - retval = read(sockfd, &validity, sizeof(unsigned int)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &validity, sizeof(unsigned int))); if(retval < sizeof(unsigned int)) { SEC_SVR_DBG("Server Error: recieve failed: %d", retval); diff --git a/src/util/security-server-util-common.c b/src/util/security-server-util-common.c index b7202aa..6270dea 100644 --- a/src/util/security-server-util-common.c +++ b/src/util/security-server-util-common.c @@ -175,7 +175,7 @@ int send_all_cookie_info(const unsigned char *buf, int size, int sockfd) } /* Send to client */ - ret = write(sockfd, buf, size); + ret = TEMP_FAILURE_RETRY(write(sockfd, buf, size)); if(ret < size) return SECURITY_SERVER_ERROR_SEND_FAILED; @@ -266,7 +266,7 @@ int send_one_cookie_info(const cookie_list *list, int sockfd) } /* Send to client */ - ret = write(sockfd, buf, total_size); + ret = TEMP_FAILURE_RETRY(write(sockfd, buf, total_size)); free(buf); if(ret < total_size) return SECURITY_SERVER_ERROR_SEND_FAILED; @@ -294,7 +294,7 @@ int util_process_cookie_from_pid(int sockfd, cookie_list* list) int pid, ret; cookie_list *result = NULL; - ret = read(sockfd, &pid, sizeof(int)); + ret = TEMP_FAILURE_RETRY(read(sockfd, &pid, sizeof(int))); if(ret < (int)sizeof(int)) { SEC_SVR_DBG("Received cookie size is too small: %d", ret); @@ -339,7 +339,7 @@ int util_process_cookie_from_cookie(int sockfd, cookie_list* list) int privileges[] = { 0 }; //only one privilege to check - root cookie_list *result = NULL; - ret = read(sockfd, cookie, SECURITY_SERVER_COOKIE_LEN); + ret = TEMP_FAILURE_RETRY(read(sockfd, cookie, SECURITY_SERVER_COOKIE_LEN)); if(ret < SECURITY_SERVER_COOKIE_LEN) { SEC_SVR_DBG("Received cookie size is too small: %d", ret); diff --git a/src/util/security-server-util.c b/src/util/security-server-util.c index 9e6e516..f6cb028 100644 --- a/src/util/security-server-util.c +++ b/src/util/security-server-util.c @@ -115,7 +115,7 @@ int send_all_cookie_info_request(int sockfd) } /* Send to server */ - retval = write(sockfd, &hdr, sizeof(hdr)); + retval = TEMP_FAILURE_RETRY(write(sockfd, &hdr, sizeof(hdr))); if(retval < sizeof(hdr)) { /* Write error */ @@ -145,7 +145,7 @@ int recv_all_cookie_info(int sockfd) } /* Receive response */ - retval = read(sockfd, &hdr, sizeof(response_header)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &hdr, sizeof(response_header))); if(retval < sizeof(hdr) ) { /* Error on socket */ @@ -172,7 +172,7 @@ int recv_all_cookie_info(int sockfd) return SECURITY_SERVER_ERROR_OUT_OF_MEMORY; } - retval = read(sockfd, buf, hdr.basic_hdr.msg_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, buf, hdr.basic_hdr.msg_len)); if(retval < hdr.basic_hdr.msg_len) { printf("Error: receiving too small amount. %d, %d\n", retval, hdr.basic_hdr.msg_len); @@ -272,7 +272,7 @@ int send_cookie_info_request_from_cookie(int sockfd, const unsigned char *cookie } /* Send to server */ - retval = write(sockfd, buf, size); + retval = TEMP_FAILURE_RETRY(write(sockfd, buf, size)); if(retval < size) { /* Write error */ @@ -320,7 +320,7 @@ int send_cookie_info_request_from_pid(int sockfd, int pid) } /* Send to server */ - retval = write(sockfd, buf, size); + retval = TEMP_FAILURE_RETRY(write(sockfd, buf, size)); if(retval < size) { /* Write error */ @@ -350,7 +350,7 @@ int recv_cookie_info_response(sockfd) } /* Receive response */ - retval = read(sockfd, &hdr, sizeof(response_header)); + retval = TEMP_FAILURE_RETRY(read(sockfd, &hdr, sizeof(response_header))); if(retval < sizeof(hdr) ) { /* Error on socket */ @@ -377,7 +377,7 @@ int recv_cookie_info_response(sockfd) return SECURITY_SERVER_ERROR_OUT_OF_MEMORY; } - retval = read(sockfd, buf, hdr.basic_hdr.msg_len); + retval = TEMP_FAILURE_RETRY(read(sockfd, buf, hdr.basic_hdr.msg_len)); if(retval < hdr.basic_hdr.msg_len) { printf("Error: receiving too small amount. %d, %d\n", retval, hdr.basic_hdr.msg_len);