Better error checking and cleaned up support for scripts.

This commit is contained in:
Nikos Mavrogiannopoulos
2014-01-11 20:37:46 +01:00
parent d6060587e2
commit ea45e710d0
3 changed files with 24 additions and 8 deletions
+2 -2
View File
@@ -338,7 +338,7 @@ const char* group;
/* do scripts and utmp */
ret = user_connected(s, proc);
if (ret < 0) {
if (ret < 0 && ret != ERR_WAIT_FOR_SCRIPT) {
mslog(s, proc, LOG_INFO, "user '%s' disconnected due to script", proc->username);
}
@@ -548,7 +548,7 @@ int handle_commands(main_server_st *s, struct proc_st* proc)
} else if (ret == 0) {
ret = accept_user(s, proc, cmd);
if (ret < 0) {
goto cleanup;
goto cleanup_auth;
}
proc->auth_status = PS_AUTH_COMPLETED;
goto cleanup;
+18 -6
View File
@@ -66,26 +66,38 @@ const char* script;
char local[64];
char remote[64];
if (proc->ipv4 == NULL && proc->ipv6 == NULL)
if (proc->ipv4 == NULL && proc->ipv6 == NULL) {
mslog(s, proc, LOG_DEBUG, "no IP configured; script failed");
exit(1);
}
if (getnameinfo((void*)&proc->remote_addr, proc->remote_addr_len, real, sizeof(real), NULL, 0, NI_NUMERICHOST) != 0)
if (getnameinfo((void*)&proc->remote_addr, proc->remote_addr_len, real, sizeof(real), NULL, 0, NI_NUMERICHOST) != 0) {
mslog(s, proc, LOG_DEBUG, "cannot determine peer address; script failed");
exit(1);
}
if (proc->ipv4 && proc->ipv4->lip_len > 0) {
if (getnameinfo((void*)&proc->ipv4->lip, proc->ipv4->lip_len, local, sizeof(local), NULL, 0, NI_NUMERICHOST) != 0)
if (getnameinfo((void*)&proc->ipv4->lip, proc->ipv4->lip_len, local, sizeof(local), NULL, 0, NI_NUMERICHOST) != 0) {
mslog(s, proc, LOG_DEBUG, "cannot determine local VPN address; script failed");
exit(1);
}
} else {
if (getnameinfo((void*)&proc->ipv6->lip, proc->ipv6->lip_len, local, sizeof(local), NULL, 0, NI_NUMERICHOST) != 0)
if (getnameinfo((void*)&proc->ipv6->lip, proc->ipv6->lip_len, local, sizeof(local), NULL, 0, NI_NUMERICHOST) != 0) {
mslog(s, proc, LOG_DEBUG, "cannot determine local VPN PtP address; script failed");
exit(1);
}
}
if (proc->ipv4 && proc->ipv4->rip_len > 0) {
if (getnameinfo((void*)&proc->ipv4->rip, proc->ipv4->rip_len, remote, sizeof(remote), NULL, 0, NI_NUMERICHOST) != 0)
if (getnameinfo((void*)&proc->ipv4->rip, proc->ipv4->rip_len, remote, sizeof(remote), NULL, 0, NI_NUMERICHOST) != 0) {
mslog(s, proc, LOG_DEBUG, "cannot determine local VPN address; script failed");
exit(1);
}
} else {
if (getnameinfo((void*)&proc->ipv6->rip, proc->ipv6->rip_len, remote, sizeof(remote), NULL, 0, NI_NUMERICHOST) != 0)
if (getnameinfo((void*)&proc->ipv6->rip, proc->ipv6->rip_len, remote, sizeof(remote), NULL, 0, NI_NUMERICHOST) != 0) {
mslog(s, proc, LOG_DEBUG, "cannot determine local VPN PtP address; script failed");
exit(1);
}
}
setenv("USERNAME", proc->username, 1);
+4
View File
@@ -180,6 +180,10 @@ static int recv_auth_reply(worker_st *ws, char* txt, size_t max_txt_size)
ret = recv_socket_msg(ws->cmd_fd, AUTH_REP, &socketfd,
(void*)&msg,
(unpack_func)auth_reply_msg__unpack);
if (ret < 0) {
oclog(ws, LOG_ERR, "error receiving auth reply message");
return ret;
}
switch(msg->reply) {
case AUTH_REPLY_MSG__AUTH__REP__MSG: