int parse_request_client( int sock, char **server_name, int *server_port, int *auth_type, char **user, int *user_sock) { int rc = PBSE_NONE; long long tmp_val = 0, tmp_port = 0, tmp_auth_type = 0, tmp_sock = 0; if ((rc = socket_read_str(sock, server_name, &tmp_val)) != PBSE_NONE) { } else if ((rc = socket_read_num(sock, &tmp_port)) != PBSE_NONE) { } else if ((rc = socket_read_num(sock, &tmp_auth_type)) != PBSE_NONE) { } else if ((rc = socket_read_str(sock, user, &tmp_val)) != PBSE_NONE) { } else if ((rc = socket_read_num(sock, &tmp_sock)) != PBSE_NONE) { } else { *server_port = (int)tmp_port; *auth_type = (int)tmp_auth_type; *user_sock = (int)tmp_sock; } return rc; }
/* memory for "the_str" is allocated in inside this function. * "str_len" is not. */ int socket_read_str( int socket, char **the_str, long long *str_len) { int rc = PBSE_NONE; long long tmp_len = 0; long long read_len = 0; char delin; if ((the_str == NULL) || (str_len == NULL)) return PBSE_INTERNAL; if ((rc = socket_read_num(socket, (long long *)&tmp_len)) != PBSE_NONE) { } else if (tmp_len == 0) { /* Valid case, NULL string */ *the_str = NULL; *str_len = 0; rc = PBSE_NONE; } else if ((*the_str = (char *)calloc(1, (tmp_len)+1)) == NULL) { rc = PBSE_INTERNAL; } /* This is where the select would go until the availbytes is > the tmp_len */ else if ((rc = socket_wait_for_xbytes(socket, tmp_len+1)) != PBSE_NONE) { } else if (socket_read_force(socket, *the_str, tmp_len, &read_len) == -1) { rc = PBSE_INTERNAL; } else if (read(socket, &delin, 1) != 1) { rc = PBSE_INTERNAL; } else if (delin != '|') { rc = PBSE_INTERNAL; } else { if (getenv("PBSDEBUG") != NULL) if (read_len != tmp_len) fprintf(stderr, "Bytes on socket = %lld, bytes read = %lld\n", tmp_len, read_len); *str_len = tmp_len; /* SUCCESS */ } return rc; } /* socket_read_str() */
int parse_terminate_request( int sock, char **username, int *pid) { int rc = PBSE_NONE; long long tmp_val; long long tmp_pid; if ((rc = socket_read_str(sock, username, &tmp_val)) != PBSE_NONE) { } else if ((rc = socket_read_num(sock, &tmp_pid)) != PBSE_NONE) { } else { *pid = tmp_pid; } return(rc); }
int validate_socket( int psock, std::string &external_err_msg) { int rc = PBSE_NONE; char tmp_buf[LOCAL_LOG_BUF]; char write_buf[1024]; char *read_buf = NULL; long long read_buf_len = 0; uid_t myrealuid; int local_socket = 0; int parent_client_socket = 0; struct passwd *pwent; char *err_msg = NULL; char *l_server = NULL; int l_server_len = 0; unsigned short af_family; long long code = -1; int write_buf_len = 0; int local_errno; pid_t mypid; char unix_sockname[MAXPATHLEN + 1]; char err_buf[MAXPATHLEN]; myrealuid = getuid(); if ((pwent = getpwuid(myrealuid)) == NULL) { snprintf(tmp_buf, LOCAL_LOG_BUF, "cannot get account info: uid %d, errno %d (%s)\n", (int)myrealuid, errno, strerror(errno)); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_SERVER, __func__, tmp_buf); } else if ((rc = get_hostaddr_hostent_af(&local_errno, (char *)AUTH_IP, &af_family, &l_server, &l_server_len)) != PBSE_NONE) { snprintf(err_buf, sizeof(err_buf), "get_hostaddr_hostend_af failed: %d", rc); external_err_msg = err_buf; } else if ((rc = get_parent_client_socket(psock, &parent_client_socket)) != PBSE_NONE) { snprintf(err_buf, sizeof(err_buf), "get_parent_client_socket failed: %d", rc); external_err_msg = err_buf; } else { snprintf(unix_sockname, sizeof(unix_sockname), "%s/%s", TRQAUTHD_SOCK_DIR, TRQAUTHD_SOCK_NAME); /* format is: * trq_system|trq_port|Validation_type|user|pid|psock| */ mypid = getpid(); sprintf(write_buf, "%d|%d|%s|%d|%d|%d|%s|%d|%d|", TRQ_AUTH_CONNECTION, (int)strlen(server_name), server_name, server_port, AUTH_TYPE_IFF, (int)strlen(pwent->pw_name), pwent->pw_name, mypid, parent_client_socket); /* * total_length|val */ write_buf_len = strlen(write_buf); if ((local_socket = socket_get_unix()) <= 0) { external_err_msg = "qsub was unable to open a socket\n"; rc = PBSE_SOCKET_FAULT; } else if ((rc = socket_connect_unix(local_socket, unix_sockname, &err_msg)) != PBSE_NONE) { external_err_msg = "qsub couldn't connect its socket to trqauthd: VERIFY THAT trqauthd IS RUNNING\n"; } else if ((rc = socket_write(local_socket, write_buf, write_buf_len)) != write_buf_len) { rc = PBSE_SOCKET_WRITE; external_err_msg = "qsub couldn't write authentication information to trqauthd"; } else if ((rc = socket_read_num(local_socket, &code)) != PBSE_NONE) { external_err_msg = "qsub couldn't read the size of information from trqauthd\n"; } else if ((rc = socket_read_str(local_socket, &read_buf, &read_buf_len)) != PBSE_NONE) { external_err_msg = "qsub couldn't read the response from trqauthd\n"; } else if ((rc = parse_daemon_response(code, read_buf_len, read_buf)) != PBSE_NONE) { snprintf(err_buf, sizeof(err_buf), "qsub received error code %lld ('%s') from trqauthd\n", code, pbse_to_txt(code)); external_err_msg = err_buf; } else { if (getenv("PBSDEBUG")) { fprintf(stdout, "%s : Connection authorized (server socket %d)\n", __func__, parent_client_socket); } } if (local_socket >= 0) socket_close(local_socket); } if (rc != PBSE_NONE) { if (err_msg != NULL) { snprintf(err_buf, sizeof(err_buf), "Error in connection to trqauthd (%d)-[%s]\n", rc, err_msg); external_err_msg = err_buf; } } if (err_msg != NULL) free(err_msg); if (read_buf != NULL) free(read_buf); if (l_server != NULL) free(l_server); return(rc); }
int validate_socket( int psock) { int rc = PBSE_NONE; static char id[] = "validate_socket"; char tmp_buf[LOCAL_LOG_BUF]; char write_buf[1024]; char *read_buf = NULL; long long read_buf_len = 0; uid_t myrealuid; int local_socket = 0; int parent_client_socket = 0; struct passwd *pwent; char *err_msg = NULL; char *l_server = NULL; int l_server_len = 0; unsigned short af_family; long long code = -1; int write_buf_len = 0; int local_errno; myrealuid = getuid(); if ((pwent = getpwuid(myrealuid)) == NULL) { snprintf(tmp_buf, LOCAL_LOG_BUF, "cannot get account info: uid %d, errno %d (%s)\n", (int)myrealuid, errno, strerror(errno)); log_event(PBSEVENT_ADMIN,PBS_EVENTCLASS_SERVER,id,tmp_buf); } else if ((rc = get_hostaddr_hostent_af(&local_errno, AUTH_IP, &af_family, &l_server, &l_server_len)) != PBSE_NONE) { } else if ((rc = get_parent_client_socket(psock, &parent_client_socket)) != PBSE_NONE) { } else { /* format is: * trq_system|trq_port|Validation_type|user|psock| */ sprintf(write_buf, "%d|%s|%d|%d|%d|%s|%d|", (int)strlen(server_name), server_name, server_port, AUTH_TYPE_IFF, (int)strlen(pwent->pw_name), pwent->pw_name, parent_client_socket); /* * total_length|val */ write_buf_len = strlen(write_buf); if ((local_socket = socket_get_tcp()) <= 0) { fprintf(stderr, "socket_get_tcp error\n"); rc = PBSE_SOCKET_FAULT; } else if ((rc = socket_connect(&local_socket, l_server, l_server_len, AUTH_PORT, AF_INET, 0, &err_msg)) != PBSE_NONE) { fprintf(stderr, "socket_connect error (VERIFY THAT trqauthd IS RUNNING)\n"); } else if ((rc = socket_write(local_socket, write_buf, write_buf_len)) != write_buf_len) { rc = PBSE_SOCKET_WRITE; fprintf(stderr, "socket_write error\n"); } else if ((rc = socket_read_num(local_socket, &code)) != PBSE_NONE) { fprintf(stderr, "socket_read_num error\n"); } else if ((rc = socket_read_str(local_socket, &read_buf, &read_buf_len)) != PBSE_NONE) { fprintf(stderr, "socket_read_str error\n"); } else if ((rc = parse_daemon_response(code, read_buf_len, read_buf)) != PBSE_NONE) { fprintf(stderr, "parse_daemon_response error\n"); } else { if (getenv("PBSDEBUG")) { fprintf(stderr, "%s : Connection authorized (server socket %d)\n", id, parent_client_socket); } socket_close(local_socket); } } if (rc != PBSE_NONE) { if (err_msg != NULL) { fprintf(stderr, "Error in connection to trqauthd (%d)-[%s]\n", rc, err_msg); } } if (err_msg != NULL) free(err_msg); if (read_buf != NULL) free(read_buf); return rc; }
int get_active_pbs_server( char **active_server, int *port) { char *err_msg = NULL; char *current_server = NULL; char unix_sockname[MAXPATHLEN + 1]; char write_buf[MAX_LINE]; int write_buf_len; char *read_buf = NULL; long long read_buf_len = MAX_LINE; int local_socket; int rc = PBSE_NONE; long long ret_code = PBSE_NONE; char *timeout_ptr; if ((timeout_ptr = getenv("PBSAPITIMEOUT")) != NULL) { time_t tmp_timeout = strtol(timeout_ptr, NULL, 0); if (tmp_timeout > 0) { pbs_tcp_timeout = tmp_timeout; } } /* the syntax for this call is a number followed by a | (pipe). The pipe indicates the end of a number */ sprintf(write_buf, "%d|", TRQ_GET_ACTIVE_SERVER); write_buf_len = strlen(write_buf); snprintf(unix_sockname, sizeof(unix_sockname), "%s/%s", TRQAUTHD_SOCK_DIR, TRQAUTHD_SOCK_NAME); local_socket = socket_get_unix(); if (local_socket < 0) return(local_socket * -1); /* socket_get_unix returns a negative PBSE error on failure. make it positive */ rc = socket_connect_unix(local_socket, unix_sockname, &err_msg); if (err_msg != NULL) free(err_msg); if (rc != PBSE_NONE) { close(local_socket); fprintf(stderr, "socket_connect_unix failed: %d\n", rc); return(rc); } rc = socket_write(local_socket, write_buf, write_buf_len); if (rc <= 0 ) { close(local_socket); fprintf(stderr, "socket_write failed: %d\n", rc); return(PBSE_SYSTEM); } /* get the server name */ if ((rc = socket_read_num(local_socket, &ret_code)) != PBSE_NONE) { close(local_socket); return(rc); } else if ((rc = socket_read_str(local_socket, &read_buf, &read_buf_len)) != PBSE_NONE) { if (read_buf != NULL) free(read_buf); close(local_socket); return(rc); } else if ((rc = socket_read_num(local_socket, (long long *)port)) != PBSE_NONE) { if (read_buf != NULL) free(read_buf); close(local_socket); return(rc); } close(local_socket); if (read_buf_len == 0) { if (read_buf != NULL) free(read_buf); return(PBSE_SOCKET_READ); } // read_buf has been allocated in socket_read_str() current_server = read_buf; *active_server = current_server; return(rc); } /* END get_active_pbs_server() */
int validate_active_pbs_server( char **active_server) { char *err_msg = NULL; char unix_sockname[MAXPATHLEN + 1]; char write_buf[MAX_LINE]; int write_buf_len; char *read_buf = NULL; long long read_buf_len = MAX_LINE; int local_socket; int rc; long long ret_code; /* the format is TRQ command */ sprintf(write_buf, "%d|", TRQ_VALIDATE_ACTIVE_SERVER); write_buf_len = strlen(write_buf); snprintf(unix_sockname, sizeof(unix_sockname), "%s/%s", TRQAUTHD_SOCK_DIR, TRQAUTHD_SOCK_NAME); local_socket = socket_get_unix(); if (local_socket < 0) { fprintf(stderr, "could not allocate unix domain socket: %d\n", local_socket); return(local_socket * -1); /*socket_get_unix returns a negative PBSE error value Change it back */ } rc = socket_connect_unix(local_socket, unix_sockname, &err_msg); if (err_msg != NULL) free(err_msg); if (rc != PBSE_NONE) { close(local_socket); fprintf(stderr, "socket_connect_unix failed: %d\n", rc); return(rc); } rc = socket_write(local_socket, write_buf, write_buf_len); if (rc <= 0 ) { close(local_socket); fprintf(stderr, "socket_write failed: %d\n", rc); return(PBSE_SYSTEM); } rc = socket_read_num(local_socket, &ret_code); if (rc != PBSE_NONE) { close(local_socket); return(rc); } rc = socket_read_str(local_socket, &read_buf, &read_buf_len); close(local_socket); if ((rc == PBSE_NONE) && (read_buf_len != 0)) { *active_server = read_buf; } else { if (read_buf != NULL) free(read_buf); if (rc != PBSE_NONE) return(rc); if (read_buf_len == 0) return(PBSE_SOCKET_READ); } return(rc); } /* END validate_active_pbs_server() */
void *process_svr_conn( void *sock) { const char *className = "trqauthd"; int rc = PBSE_NONE; char *server_name = NULL; int server_port = 0; char *user_name = NULL; int user_pid = 0; int user_sock = 0; std::string error_string; std::string message; int msg_len = 0; int local_socket = *(int *)sock; char msg_buf[1024]; long long req_type; /* Type of request coming in */ rc = socket_read_num(local_socket, &req_type); if (rc == PBSE_NONE) { switch (req_type) { case TRQ_DOWN_TRQAUTHD: { rc = parse_terminate_request(local_socket, &user_name, &user_pid); if (rc != PBSE_NONE) break; /* root is the only user that can terminate trqauthd */ if (strcmp(user_name, "root")) { rc = PBSE_PERM; break; } rc = validate_user(local_socket, user_name, user_pid, msg_buf); if (rc == PBSE_NONE) { trqauthd_up = false; rc = build_active_server_response(message); } break; } case TRQ_PING_SERVER: case TRQ_GET_ACTIVE_SERVER: { /* rc will get evaluated after the switch statement. */ rc = build_active_server_response(message); break; } case TRQ_VALIDATE_ACTIVE_SERVER: { if ((rc = validate_server(server_name, server_port, NULL, NULL)) != PBSE_NONE) { break; } else if ((rc = build_active_server_response(message)) != PBSE_NONE) { break; } break; } case TRQ_AUTH_CONNECTION: { rc = authorize_socket(local_socket, message, msg_buf, &server_name, &user_name, error_string); break; } default: rc = PBSE_IVALREQ; break; } } else { sprintf(msg_buf, "socket_read_num failed: %d", rc); log_record(PBSEVENT_CLIENTAUTH, PBS_EVENTCLASS_TRQAUTHD, __func__, msg_buf); } #ifdef UNIT_TEST /* process_svr_conn_rc is used by ./test/trq_auth/test_trq_auth.c to discover the status of unit test calls to process_svr_conn */ process_svr_conn_rc = rc; #endif if (rc != PBSE_NONE) { /* Failure case */ msg_len = 6 + 1 + 6 + 1 + 1; if (error_string.size() == 0) { char *err = pbse_to_txt(rc); if (err != NULL) error_string = err; } msg_len += error_string.size(); message = string_format("%d|%d|%s|",rc, error_string.size(), error_string.c_str()); if (debug_mode == TRUE) { if (server_name != NULL) fprintf(stderr, "Conn to %s port %d Fail. Conn %d not authorized (Err Num %d)\n", server_name, server_port, user_sock, rc); } if (error_string.size() == 0) { if (server_name != NULL) snprintf(msg_buf, sizeof(msg_buf), "User %s at IP:port %s:%d login attempt failed --no message", (user_name) ? user_name : "null", server_name, server_port); } else { snprintf(msg_buf, sizeof(msg_buf), "User %s at IP:port %s:%d login attempt failed --%s", (user_name) ? user_name : "null", (server_name) ? server_name : "null", server_port, error_string.c_str()); } log_record(PBSEVENT_CLIENTAUTH | PBSEVENT_FORCE, PBS_EVENTCLASS_TRQAUTHD, className, msg_buf); } if (message.length() != 0) rc = socket_write(local_socket, message.c_str(), message.length()); if (server_name != NULL) free(server_name); if (user_name != NULL) free(user_name); socket_close(local_socket); free(sock); return(NULL); } /* END process_svr_conn() */
int terminate_trqauthd() { int rc = PBSE_NONE; int sock = -1; char write_buf[MAX_LINE]; char *read_buf = NULL; char log_buf[MAX_BUF]; long long read_buf_len = MAX_LINE; long long ret_code; uid_t myrealuid; pid_t mypid; struct passwd *pwent; myrealuid = getuid(); pwent = getpwuid(myrealuid); if (pwent == NULL) { snprintf(log_buf, MAX_BUF, "cannot get account info: uid %d, errno %d (%s)\n", (int)myrealuid, errno, strerror(errno)); log_event(PBSEVENT_ADMIN, PBS_EVENTCLASS_SERVER, __func__, log_buf); return(PBSE_SYSTEM); } mypid = getpid(); sprintf(write_buf, "%d|%d|%s|%d|", TRQ_DOWN_TRQAUTHD, (int )strlen(pwent->pw_name), pwent->pw_name, mypid); if((rc = connect_to_trqauthd(&sock)) != PBSE_NONE) { fprintf(stderr, "Could not connect to trqauthd. trqauthd may already be down\n"); } else if ((rc = socket_write(sock, write_buf, strlen(write_buf))) < 0) { fprintf(stderr, "Failed to send termnation request to trqauthd: %d\n", rc); } else if ((rc = socket_read_num(sock, &ret_code)) != PBSE_NONE) { fprintf(stderr, "trqauthd did not give proper response. Check to see if traquthd has terminated: %d\n", rc); } else if (ret_code != PBSE_NONE) { rc = socket_read_str(sock, &read_buf, &read_buf_len); fprintf(stderr, "trqauthd not shutdown. %s\n", read_buf); } else if ((rc = socket_read_str(sock, &read_buf, &read_buf_len)) != PBSE_NONE) { fprintf(stderr, "trqauthd did not respond. Check to see if trqauthd has terminated: %d\n", rc); } else if( (rc = connect_to_trqauthd(&sock)) != PBSE_NONE) /* We do this because the accept loop on trqauthd is still waiting for a command before it realizes it is terminated */ { fprintf(stdout, "\ntrqauthd has been terminated\n"); } else { fprintf(stdout, "\ntrqauthd has been terminated\n"); } if (sock != -1) close(sock); if (read_buf != NULL) { free(read_buf); } return(rc); }
void *process_svr_conn( void *sock) { const char *className = "trqauthd"; int rc = PBSE_NONE; char *server_name = NULL; int server_port = 0; int auth_type = 0; char *user_name = NULL; int user_pid = 0; int user_sock = 0; char *error_msg = NULL; std::string message; int send_len = 0; char *trq_server_addr = NULL; int trq_server_addr_len = 0; int svr_sock = -1; int msg_len = 0; int debug_mark = 0; int local_socket = *(int *)sock; char msg_buf[1024]; long long req_type; /* Type of request coming in */ rc = socket_read_num(local_socket, &req_type); if (rc == PBSE_NONE) { switch (req_type) { case TRQ_DOWN_TRQAUTHD: { rc = parse_terminate_request(local_socket, &user_name, &user_pid); if (rc != PBSE_NONE) break; /* root is the only user that can terminate trqauthd */ if (strcmp(user_name, "root")) { rc = PBSE_PERM; break; } rc = validate_user(local_socket, user_name, user_pid, msg_buf); if (rc == PBSE_NONE) { trqauthd_up = false; rc = build_active_server_response(message); } break; } case TRQ_PING_SERVER: case TRQ_GET_ACTIVE_SERVER: { /* rc will get evaluated after the switch statement. */ rc = build_active_server_response(message); break; } case TRQ_VALIDATE_ACTIVE_SERVER: { if ((rc = validate_server(server_name, server_port, NULL, NULL)) != PBSE_NONE) { break; } else if ((rc = build_active_server_response(message)) != PBSE_NONE) { break; } break; } case TRQ_AUTH_CONNECTION: { int disconnect_svr = TRUE; /* incoming message format is: * trq_system_len|trq_system|trq_port|Validation_type|user_len|user|pid|psock| * message format to pbs_server is: * +2+22+492+user+sock+0 * format from pbs_server is: * +2+2+0+0+1 * outgoing message format is: * #|msg_len|message| * Send response to client here!! * Disconnect message to svr: * +2+22+592+{user_len}{user} * * msg to client in the case of success: * 0|0|| */ if ((rc = parse_request_client(local_socket, &server_name, &server_port, &auth_type, &user_name, &user_pid, &user_sock)) != PBSE_NONE) { disconnect_svr = FALSE; debug_mark = 1; } else { int retries = 0; while (retries < MAX_RETRIES) { rc = PBSE_NONE; disconnect_svr = TRUE; if ((rc = validate_user(local_socket, user_name, user_pid, msg_buf)) != PBSE_NONE) { log_record(PBSEVENT_CLIENTAUTH | PBSEVENT_FORCE, PBS_EVENTCLASS_TRQAUTHD, __func__, msg_buf); disconnect_svr = FALSE; debug_mark = 1; retries++; usleep(20000); continue; } else if ((rc = get_trq_server_addr(server_name, &trq_server_addr, &trq_server_addr_len)) != PBSE_NONE) { disconnect_svr = FALSE; debug_mark = 2; retries++; usleep(20000); continue; } else if ((svr_sock = socket_get_tcp_priv()) < 0) { rc = PBSE_SOCKET_FAULT; disconnect_svr = FALSE; debug_mark = 3; retries++; usleep(10000); continue; } else if ((rc = socket_connect(&svr_sock, trq_server_addr, trq_server_addr_len, server_port, AF_INET, 1, &error_msg)) != PBSE_NONE) { /* for now we only need ssh_key and sign_key as dummys */ char *ssh_key = NULL; char *sign_key = NULL; char log_buf[LOCAL_LOG_BUF_SIZE]; validate_server(server_name, server_port, ssh_key, &sign_key); sprintf(log_buf, "Active server is %s", active_pbs_server); log_event(PBSEVENT_CLIENTAUTH, PBS_EVENTCLASS_TRQAUTHD, __func__, log_buf); disconnect_svr = FALSE; debug_mark = 4; socket_close(svr_sock); retries++; usleep(50000); continue; } else if ((rc = build_request_svr(auth_type, user_name, user_sock, message)) != PBSE_NONE) { socket_close(svr_sock); disconnect_svr = FALSE; debug_mark = 5; retries++; usleep(50000); continue; } else if ((send_len = message.length()) <= 0) { socket_close(svr_sock); disconnect_svr = FALSE; rc = PBSE_INTERNAL; debug_mark = 6; retries++; usleep(50000); continue; } else if ((rc = socket_write(svr_sock, message.c_str(), send_len)) != send_len) { socket_close(svr_sock); disconnect_svr = FALSE; rc = PBSE_SOCKET_WRITE; debug_mark = 7; retries++; usleep(50000); continue; } else if ((rc = parse_response_svr(svr_sock, &error_msg)) != PBSE_NONE) { socket_close(svr_sock); disconnect_svr = FALSE; debug_mark = 8; retries++; usleep(50000); continue; } else { /* Success case */ message = "0|0||"; if (debug_mode == TRUE) { fprintf(stderr, "Conn to %s port %d success. Conn %d authorized\n", server_name, server_port, user_sock); } snprintf(msg_buf, sizeof(msg_buf), "User %s at IP:port %s:%d logged in", user_name, server_name, server_port); log_record(PBSEVENT_CLIENTAUTH | PBSEVENT_FORCE, PBS_EVENTCLASS_TRQAUTHD, className, msg_buf); } break; } } if (TRUE == disconnect_svr) { send_svr_disconnect(svr_sock, user_name); socket_close(svr_sock); } break; } default: rc = PBSE_IVALREQ; break; } } else { sprintf(msg_buf, "socket_read_num failed: %d", rc); log_record(PBSEVENT_CLIENTAUTH, PBS_EVENTCLASS_TRQAUTHD, __func__, msg_buf); } #ifdef UNIT_TEST /* process_svr_conn_rc is used by ./test/trq_auth/test_trq_auth.c to discover the status of unit test calls to process_svr_conn */ process_svr_conn_rc = rc; #endif if (rc != PBSE_NONE) { /* Failure case */ msg_len = 6 + 1 + 6 + 1 + 1; if (error_msg == NULL) { char *tmp_err = pbse_to_txt(rc); if (tmp_err != NULL) error_msg = strdup(tmp_err); else error_msg = strdup(""); } msg_len += strlen(error_msg); message = string_format("%d|%d|%s|",rc,strlen(error_msg),error_msg); if (debug_mode == TRUE) { fprintf(stderr, "Conn to %s port %d Fail. Conn %d not authorized (dm = %d, Err Num %d)\n", server_name, server_port, user_sock, debug_mark, rc); } snprintf(msg_buf, sizeof(msg_buf), "User %s at IP:port %s:%d login attempt failed --%s", (user_name) ? user_name : "null", (server_name) ? server_name : "null", server_port, (error_msg) ? error_msg : "null"); log_record(PBSEVENT_CLIENTAUTH | PBSEVENT_FORCE, PBS_EVENTCLASS_TRQAUTHD, className, msg_buf); } if (message.length() != 0) rc = socket_write(local_socket, message.c_str(), message.length()); if (trq_server_addr != NULL) free(trq_server_addr); if (server_name != NULL) free(server_name); if (user_name != NULL) free(user_name); if (error_msg != NULL) free(error_msg); socket_close(local_socket); free(sock); return(NULL); } /* END process_svr_conn() */