/* process RPC from slurmctld * IN msg: message received * OUT resp: resource allocation response message * RET 1 if resp is filled in, 0 otherwise */ static int _handle_msg(slurm_msg_t *msg, resource_allocation_response_msg_t **resp) { uid_t req_uid = g_slurm_auth_get_uid(msg->auth_cred, NULL); uid_t uid = getuid(); uid_t slurm_uid = (uid_t) slurm_get_slurm_user_id(); int rc = 0; if ((req_uid != slurm_uid) && (req_uid != 0) && (req_uid != uid)) { error ("Security violation, slurm message from uid %u", (unsigned int) req_uid); return 0; } switch (msg->msg_type) { case RESPONSE_RESOURCE_ALLOCATION: debug2("resource allocation response received"); slurm_send_rc_msg(msg, SLURM_SUCCESS); *resp = msg->data; rc = 1; break; case SRUN_JOB_COMPLETE: info("Job has been cancelled"); break; default: error("received spurious message type: %d", msg->msg_type); } return rc; }
/* process RPC from slurmctld * IN msg: message received * OUT resp: resource allocation response message or List of them * RET 1 if resp is filled in, 0 otherwise */ static int _handle_msg(slurm_msg_t *msg, uint16_t msg_type, void **resp) { char *auth_info = slurm_get_auth_info(); uid_t req_uid; uid_t uid = getuid(); uid_t slurm_uid = (uid_t) slurm_get_slurm_user_id(); int rc = 0; req_uid = g_slurm_auth_get_uid(msg->auth_cred, auth_info); xfree(auth_info); if ((req_uid != slurm_uid) && (req_uid != 0) && (req_uid != uid)) { error ("Security violation, slurm message from uid %u", (unsigned int) req_uid); return 0; } if (msg->msg_type == msg_type) { debug2("resource allocation response received"); slurm_send_rc_msg(msg, SLURM_SUCCESS); *resp = msg->data; /* transfer payload to response */ msg->data = NULL; rc = 1; } else if (msg->msg_type == SRUN_JOB_COMPLETE) { info("Job has been cancelled"); } else { error("%s: received spurious message type: %u", __func__, msg->msg_type); } return rc; }
static void _handle_msg(slurm_msg_t *msg) { static uint32_t slurm_uid = NO_VAL; uid_t req_uid = g_slurm_auth_get_uid(msg->auth_cred, slurm_get_auth_info()); uid_t uid = getuid(); job_step_kill_msg_t *ss; srun_user_msg_t *um; if (slurm_uid == NO_VAL) slurm_uid = slurm_get_slurm_user_id(); if ((req_uid != slurm_uid) && (req_uid != 0) && (req_uid != uid)) { error ("Security violation, slurm message from uid %u", (unsigned int) req_uid); return; } switch (msg->msg_type) { case SRUN_PING: debug3("slurmctld ping received"); slurm_send_rc_msg(msg, SLURM_SUCCESS); slurm_free_srun_ping_msg(msg->data); break; case SRUN_JOB_COMPLETE: debug("received job step complete message"); runjob_signal(SIGKILL); slurm_free_srun_job_complete_msg(msg->data); break; case SRUN_USER_MSG: um = msg->data; info("%s", um->msg); slurm_free_srun_user_msg(msg->data); break; case SRUN_TIMEOUT: debug("received job step timeout message"); _handle_timeout(msg->data); slurm_free_srun_timeout_msg(msg->data); break; case SRUN_STEP_SIGNAL: ss = msg->data; debug("received step signal %u RPC", ss->signal); if (ss->signal) runjob_signal(ss->signal); slurm_free_job_step_kill_msg(msg->data); break; default: debug("received spurious message type: %u", msg->msg_type); break; } return; }
/* _background_process_msg - process an RPC to the backup_controller */ static int _background_process_msg(slurm_msg_t * msg) { int error_code = SLURM_SUCCESS; if (msg->msg_type != REQUEST_PING) { bool super_user = false; char *auth_info = slurm_get_auth_info(); uid_t uid = g_slurm_auth_get_uid(msg->auth_cred, auth_info); xfree(auth_info); if ((uid == 0) || (uid == getuid())) super_user = true; if (super_user && (msg->msg_type == REQUEST_SHUTDOWN_IMMEDIATE)) { info("Performing RPC: REQUEST_SHUTDOWN_IMMEDIATE"); } else if (super_user && (msg->msg_type == REQUEST_SHUTDOWN)) { info("Performing RPC: REQUEST_SHUTDOWN"); pthread_kill(slurmctld_config.thread_id_sig, SIGTERM); } else if (super_user && (msg->msg_type == REQUEST_TAKEOVER)) { info("Performing RPC: REQUEST_TAKEOVER"); _shutdown_primary_controller(SHUTDOWN_WAIT); takeover = true; error_code = SLURM_SUCCESS; } else if (super_user && (msg->msg_type == REQUEST_CONTROL)) { debug3("Ignoring RPC: REQUEST_CONTROL"); error_code = ESLURM_DISABLED; last_controller_response = time(NULL); } else { error("Invalid RPC received %d while in standby mode", msg->msg_type); error_code = ESLURM_IN_STANDBY_MODE; } } if (msg->msg_type != REQUEST_SHUTDOWN_IMMEDIATE) slurm_send_rc_msg(msg, error_code); return error_code; }
static void * _handle_accept(void *arg) { /*struct request_params *param = (struct request_params *)arg;*/ int fd = ((struct request_params *)arg)->fd; slurmd_job_t *job = ((struct request_params *)arg)->job; int req; int len; Buf buffer; void *auth_cred; int rc; uid_t uid; gid_t gid; debug3("Entering _handle_accept (new thread)"); xfree(arg); safe_read(fd, &req, sizeof(int)); if (req != REQUEST_CONNECT) { error("First message must be REQUEST_CONNECT"); goto fail; } safe_read(fd, &len, sizeof(int)); buffer = init_buf(len); safe_read(fd, get_buf_data(buffer), len); /* Unpack and verify the auth credential */ auth_cred = g_slurm_auth_unpack(buffer); if (auth_cred == NULL) { error("Unpacking authentication credential: %s", g_slurm_auth_errstr(g_slurm_auth_errno(NULL))); free_buf(buffer); goto fail; } rc = g_slurm_auth_verify(auth_cred, NULL, 2, NULL); if (rc != SLURM_SUCCESS) { error("Verifying authentication credential: %s", g_slurm_auth_errstr(g_slurm_auth_errno(auth_cred))); (void) g_slurm_auth_destroy(auth_cred); free_buf(buffer); goto fail; } /* Get the uid & gid from the credential, then destroy it. */ uid = g_slurm_auth_get_uid(auth_cred, NULL); gid = g_slurm_auth_get_gid(auth_cred, NULL); debug3(" Identity: uid=%d, gid=%d", uid, gid); g_slurm_auth_destroy(auth_cred); free_buf(buffer); rc = SLURM_SUCCESS; safe_write(fd, &rc, sizeof(int)); while (1) { rc = _handle_request(fd, job, uid, gid); if (rc != SLURM_SUCCESS) break; } if (close(fd) == -1) error("Closing accepted fd: %m"); pthread_mutex_lock(&message_lock); message_connections--; pthread_cond_signal(&message_cond); pthread_mutex_unlock(&message_lock); debug3("Leaving _handle_accept"); return NULL; fail: rc = SLURM_FAILURE; safe_write(fd, &rc, sizeof(int)); rwfail: if (close(fd) == -1) error("Closing accepted fd after error: %m"); debug("Leaving _handle_accept on an error"); return NULL; }
extern int spawn_req_unpack(spawn_req_t **req_ptr, Buf buf) { spawn_req_t *req = NULL; spawn_subcmd_t *subcmd = NULL; uint32_t temp32; int i, j; void *auth_cred; uid_t auth_uid, my_uid; auth_cred = g_slurm_auth_unpack(buf); if (auth_cred == NULL) { error("authentication: %s", g_slurm_auth_errstr(g_slurm_auth_errno(NULL)) ); return SLURM_ERROR; } auth_uid = g_slurm_auth_get_uid(auth_cred, NULL); (void) g_slurm_auth_destroy(auth_cred); my_uid = getuid(); if ((auth_uid != 0) && (auth_uid != my_uid)) { error("mpi/pmi2: spawn request apparently from uid %u", (uint32_t) auth_uid); return SLURM_ERROR; } req = xmalloc(sizeof(spawn_req_t)); safe_unpack32(&req->seq, buf); safe_unpackstr_xmalloc(&req->from_node, &temp32, buf); safe_unpack32(&req->subcmd_cnt, buf); /* subcmd_cnt must be greater than 0 */ req->subcmds = xmalloc(req->subcmd_cnt * sizeof(spawn_subcmd_t *)); safe_unpack32(&req->preput_cnt, buf); if (req->preput_cnt > 0) { req->pp_keys = xmalloc(req->preput_cnt * sizeof(char *)); req->pp_vals = xmalloc(req->preput_cnt * sizeof(char *)); for (i = 0; i < req->preput_cnt; i ++) { safe_unpackstr_xmalloc(&req->pp_keys[i], &temp32, buf); safe_unpackstr_xmalloc(&req->pp_vals[i], &temp32, buf); } } for (i = 0; i < req->subcmd_cnt; i ++) { req->subcmds[i] = spawn_subcmd_new(); subcmd = req->subcmds[i]; safe_unpackstr_xmalloc(&(subcmd->cmd), &temp32, buf); safe_unpack32(&(subcmd->max_procs), buf); safe_unpack32(&(subcmd->argc), buf); if (subcmd->argc > 0) { subcmd->argv = xmalloc(subcmd->argc * sizeof(char *)); for (j = 0; j < subcmd->argc; j ++) { safe_unpackstr_xmalloc(&(subcmd->argv[j]), &temp32, buf); } } safe_unpack32(&(subcmd->info_cnt), buf); if (subcmd->info_cnt > 0) { subcmd->info_keys = xmalloc(subcmd->info_cnt * sizeof(char *)); subcmd->info_vals = xmalloc(subcmd->info_cnt * sizeof(char *)); for (j = 0; j < subcmd->info_cnt; j ++) { safe_unpackstr_xmalloc(&(subcmd->info_keys[j]), &temp32, buf); safe_unpackstr_xmalloc(&(subcmd->info_vals[j]), &temp32, buf); } } } *req_ptr = req; return SLURM_SUCCESS; unpack_error: spawn_req_free(req); return SLURM_ERROR; }