mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
updates in unix socket creation
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <gnutls/crypto.h>
|
||||
#include <tlslib.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <cloexec.h>
|
||||
#include "ipc.h"
|
||||
#include "setproctitle.h"
|
||||
@@ -379,59 +380,24 @@ struct banned_st *btmp;
|
||||
|
||||
void run_sec_mod(main_server_st * s)
|
||||
{
|
||||
struct sockaddr_un sa;
|
||||
int sd, e, ret;
|
||||
int e;
|
||||
pid_t pid;
|
||||
|
||||
sa.sun_family = AF_UNIX;
|
||||
|
||||
/* make socket name */
|
||||
snprintf(s->socket_file, sizeof(s->socket_file), "%s.%u", s->config->socket_file_prefix, (unsigned)getpid());
|
||||
snprintf(sa.sun_path, sizeof(sa.sun_path), "%s", s->socket_file);
|
||||
|
||||
remove(s->socket_file);
|
||||
|
||||
sd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sd == -1) {
|
||||
e = errno;
|
||||
mslog(s, NULL, LOG_ERR, "could not create socket '%s': %s", s->socket_file, strerror(e));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = bind(sd, (struct sockaddr *)&sa, sizeof(sa));
|
||||
if (ret == -1) {
|
||||
e = errno;
|
||||
mslog(s, NULL, LOG_ERR, "could not bind socket '%s': %s", s->socket_file, strerror(e));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = chown(sa.sun_path, s->config->uid, s->config->gid);
|
||||
if (ret == -1) {
|
||||
e = errno;
|
||||
mslog(s, NULL, LOG_ERR, "could not chown socket '%s': %s", s->socket_file, strerror(e));
|
||||
}
|
||||
|
||||
ret = listen(sd, 1024);
|
||||
if (ret == -1) {
|
||||
e = errno;
|
||||
mslog(s, NULL, LOG_ERR, "could not listen to socket '%s': %s", s->socket_file, strerror(e));
|
||||
exit(1);
|
||||
}
|
||||
set_cloexec_flag (sd, 1);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) { /* child */
|
||||
prctl(PR_SET_PDEATHSIG, SIGTERM);
|
||||
setproctitle(PACKAGE_NAME"-secmod");
|
||||
|
||||
sec_mod_server(s->config, sd);
|
||||
sec_mod_server(s->config, s->socket_file);
|
||||
exit(0);
|
||||
} else if (pid > 0) { /* parent */
|
||||
close(sd);
|
||||
s->sec_mod_pid = pid;
|
||||
} else {
|
||||
e = errno;
|
||||
mslog(s, NULL, LOG_ERR, "error in fork(): %s", strerror(e));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user