static void login_security_done(struct connection *conn) { int err; struct iscsi_login_req_hdr *req = (struct iscsi_login_req_hdr *)&conn->req.bhs; struct iscsi_login_rsp_hdr *rsp = (struct iscsi_login_rsp_hdr *)&conn->rsp.bhs; struct session *session; if (!conn->tid) return; if ((session = session_find_name(conn->tid, conn->initiator, req->sid))) { if (!req->sid.id.tsih) { /* do session reinstatement */ session_conns_close(conn->tid, session->sid.id64); session = NULL; } else if (req->sid.id.tsih != session->sid.id.tsih) { /* fail the login */ rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; rsp->status_detail = ISCSI_STATUS_SESSION_NOT_FOUND; conn->state = STATE_EXIT; return; } else if ((err = conn_test(conn)) == -ENOENT) { /* do connection reinstatement */ } /* add a new connection to the session */ conn->session = session; } else { if (req->sid.id.tsih) { /* fail the login */ rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; rsp->status_detail = ISCSI_STATUS_SESSION_NOT_FOUND; conn->state = STATE_EXIT; return; } /* instantiate a new session */ } }
/* * Periodically test network connection. On signals, determine what * happened or what to do with child. Return as necessary for exit * or restart of child. */ int ssh_watch(int sock) { int r; int val; static int secs_left; int my_poll_time = first_poll_time; time_t now; double secs_to_shutdown; #if defined(HAVE_SETPROCTITLE) setproctitle("parent of %d (%d)", (int)cchild, start_count); #endif for (;;) { if (restart_ssh) { errlog(LOG_INFO, "signalled to kill and restart ssh"); ssh_kill(); return P_RESTART; } if ((val = sigsetjmp(jumpbuf, 1)) == 0) { errlog(LOG_DEBUG, "check on child %d", cchild); /* poll for expired child */ r = ssh_wait(WNOHANG); if (r != P_CONTINUE) { errlog(LOG_DEBUG, "expired child, returning %d", r); return r; } secs_left = alarm(0); if (secs_left == 0) secs_left = my_poll_time; my_poll_time = poll_time; if (max_lifetime != 0) { time(&now); secs_to_shutdown = max_lifetime - difftime(now,pid_start_time); if (secs_to_shutdown < poll_time) secs_left = secs_to_shutdown; } errlog(LOG_DEBUG, "set alarm for %d secs", secs_left); alarm(secs_left); dolongjmp = 1; pause(); } else { switch(val) { case SIGINT: case SIGTERM: case SIGQUIT: case SIGABRT: errlog(LOG_INFO, "received signal to exit (%d)", val); ssh_kill(); return P_EXIT; break; case SIGALRM: if (exceeded_lifetime()) { ssh_kill(); return P_EXIT; } if (writep && sock != -1 && !conn_test(sock, mhost, writep)) { errlog(LOG_INFO, "port down, restarting ssh"); ssh_kill(); return P_RESTART; } #ifdef TOUCH_PIDFILE /* * utimes() with a NULL time argument sets * file access and modification times to * the current time */ if (pid_file_name && utimes(pid_file_name, NULL) != 0) { errlog(LOG_ERR, "could not touch pid file: %s", strerror(errno)); } #endif break; default: break; } } } }