Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * UNIX SOCK_STREAM protocol layer (uxst) |
| 3 | * |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 4 | * Copyright 2000-2010 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <ctype.h> |
| 14 | #include <errno.h> |
| 15 | #include <fcntl.h> |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 16 | #include <pwd.h> |
| 17 | #include <grp.h> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <syslog.h> |
| 22 | #include <time.h> |
| 23 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 24 | #include <sys/socket.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/un.h> |
| 28 | |
| 29 | #include <common/compat.h> |
| 30 | #include <common/config.h> |
| 31 | #include <common/debug.h> |
Willy Tarreau | d740bab | 2007-10-28 11:14:07 +0100 | [diff] [blame] | 32 | #include <common/errors.h> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 33 | #include <common/mini-clist.h> |
| 34 | #include <common/standard.h> |
| 35 | #include <common/time.h> |
| 36 | #include <common/version.h> |
| 37 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 38 | #include <types/global.h> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 40 | #include <proto/connection.h> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 41 | #include <proto/fd.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 42 | #include <proto/listener.h> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 43 | #include <proto/log.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 44 | #include <proto/protocol.h> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 45 | #include <proto/proto_uxst.h> |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 46 | #include <proto/task.h> |
| 47 | |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 48 | static int uxst_bind_listener(struct listener *listener, char *errmsg, int errlen); |
| 49 | static int uxst_bind_listeners(struct protocol *proto, char *errmsg, int errlen); |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 50 | static int uxst_unbind_listeners(struct protocol *proto); |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 51 | static int uxst_connect_server(struct connection *conn, int data, int delack); |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 52 | |
| 53 | /* Note: must not be declared <const> as its list will be overwritten */ |
| 54 | static struct protocol proto_unix = { |
| 55 | .name = "unix_stream", |
| 56 | .sock_domain = PF_UNIX, |
| 57 | .sock_type = SOCK_STREAM, |
| 58 | .sock_prot = 0, |
| 59 | .sock_family = AF_UNIX, |
| 60 | .sock_addrlen = sizeof(struct sockaddr_un), |
| 61 | .l3_addrlen = sizeof(((struct sockaddr_un*)0)->sun_path),/* path len */ |
Willy Tarreau | bbebbbf | 2012-05-07 21:22:09 +0200 | [diff] [blame] | 62 | .accept = &listener_accept, |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 63 | .connect = &uxst_connect_server, |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 64 | .bind = uxst_bind_listener, |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 65 | .bind_all = uxst_bind_listeners, |
| 66 | .unbind_all = uxst_unbind_listeners, |
| 67 | .enable_all = enable_all_listeners, |
| 68 | .disable_all = disable_all_listeners, |
Willy Tarreau | 59b9479 | 2012-05-11 16:16:40 +0200 | [diff] [blame] | 69 | .get_src = uxst_get_src, |
| 70 | .get_dst = uxst_get_dst, |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 71 | .listeners = LIST_HEAD_INIT(proto_unix.listeners), |
| 72 | .nb_listeners = 0, |
| 73 | }; |
| 74 | |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 75 | /******************************** |
| 76 | * 1) low-level socket functions |
| 77 | ********************************/ |
| 78 | |
Willy Tarreau | 59b9479 | 2012-05-11 16:16:40 +0200 | [diff] [blame] | 79 | /* |
| 80 | * Retrieves the source address for the socket <fd>, with <dir> indicating |
| 81 | * if we're a listener (=0) or an initiator (!=0). It returns 0 in case of |
| 82 | * success, -1 in case of error. The socket's source address is stored in |
| 83 | * <sa> for <salen> bytes. |
| 84 | */ |
| 85 | int uxst_get_src(int fd, struct sockaddr *sa, socklen_t salen, int dir) |
| 86 | { |
| 87 | if (dir) |
| 88 | return getsockname(fd, sa, &salen); |
| 89 | else |
| 90 | return getpeername(fd, sa, &salen); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /* |
| 95 | * Retrieves the original destination address for the socket <fd>, with <dir> |
| 96 | * indicating if we're a listener (=0) or an initiator (!=0). It returns 0 in |
| 97 | * case of success, -1 in case of error. The socket's source address is stored |
| 98 | * in <sa> for <salen> bytes. |
| 99 | */ |
| 100 | int uxst_get_dst(int fd, struct sockaddr *sa, socklen_t salen, int dir) |
| 101 | { |
| 102 | if (dir) |
| 103 | return getpeername(fd, sa, &salen); |
| 104 | else |
| 105 | return getsockname(fd, sa, &salen); |
| 106 | } |
| 107 | |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 108 | |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 109 | /* Tries to destroy the UNIX stream socket <path>. The socket must not be used |
| 110 | * anymore. It practises best effort, and no error is returned. |
| 111 | */ |
| 112 | static void destroy_uxst_socket(const char *path) |
| 113 | { |
| 114 | struct sockaddr_un addr; |
| 115 | int sock, ret; |
| 116 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 117 | /* if the path was cleared, we do nothing */ |
| 118 | if (!*path) |
| 119 | return; |
| 120 | |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 121 | /* We might have been chrooted, so we may not be able to access the |
| 122 | * socket. In order to avoid bothering the other end, we connect with a |
| 123 | * wrong protocol, namely SOCK_DGRAM. The return code from connect() |
| 124 | * is enough to know if the socket is still live or not. If it's live |
| 125 | * in mode SOCK_STREAM, we get EPROTOTYPE or anything else but not |
| 126 | * ECONNREFUSED. In this case, we do not touch it because it's used |
| 127 | * by some other process. |
| 128 | */ |
| 129 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); |
| 130 | if (sock < 0) |
| 131 | return; |
| 132 | |
| 133 | addr.sun_family = AF_UNIX; |
| 134 | strncpy(addr.sun_path, path, sizeof(addr.sun_path)); |
| 135 | addr.sun_path[sizeof(addr.sun_path) - 1] = 0; |
| 136 | ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); |
| 137 | if (ret < 0 && errno == ECONNREFUSED) { |
| 138 | /* Connect failed: the socket still exists but is not used |
| 139 | * anymore. Let's remove this socket now. |
| 140 | */ |
| 141 | unlink(path); |
| 142 | } |
| 143 | close(sock); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | /******************************** |
| 148 | * 2) listener-oriented functions |
| 149 | ********************************/ |
| 150 | |
| 151 | |
| 152 | /* This function creates a UNIX socket associated to the listener. It changes |
| 153 | * the state from ASSIGNED to LISTEN. The socket is NOT enabled for polling. |
Willy Tarreau | 8ab505b | 2013-01-24 01:41:38 +0100 | [diff] [blame] | 154 | * The return value is composed from ERR_NONE, ERR_RETRYABLE and ERR_FATAL. It |
| 155 | * may return a warning or an error message in <errmsg> if the message is at |
| 156 | * most <errlen> bytes long (including '\0'). Note that <errmsg> may be NULL if |
| 157 | * <errlen> is also zero. |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 158 | */ |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 159 | static int uxst_bind_listener(struct listener *listener, char *errmsg, int errlen) |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 160 | { |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 161 | int fd; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 162 | char tempname[MAXPATHLEN]; |
| 163 | char backname[MAXPATHLEN]; |
| 164 | struct sockaddr_un addr; |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 165 | const char *msg = NULL; |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 166 | const char *path; |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 167 | int ext, ready; |
| 168 | socklen_t ready_len; |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 169 | |
| 170 | int ret; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 171 | |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 172 | /* ensure we never return garbage */ |
Willy Tarreau | 8ab505b | 2013-01-24 01:41:38 +0100 | [diff] [blame] | 173 | if (errlen) |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 174 | *errmsg = 0; |
| 175 | |
| 176 | if (listener->state != LI_ASSIGNED) |
| 177 | return ERR_NONE; /* already bound */ |
| 178 | |
| 179 | path = ((struct sockaddr_un *)&listener->addr)->sun_path; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 180 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 181 | /* if the listener already has an fd assigned, then we were offered the |
| 182 | * fd by an external process (most likely the parent), and we don't want |
| 183 | * to create a new socket. However we still want to set a few flags on |
| 184 | * the socket. |
| 185 | */ |
| 186 | fd = listener->fd; |
| 187 | ext = (fd >= 0); |
| 188 | if (ext) |
| 189 | goto fd_ready; |
| 190 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 191 | if (path[0]) { |
| 192 | ret = snprintf(tempname, MAXPATHLEN, "%s.%d.tmp", path, pid); |
| 193 | if (ret < 0 || ret >= MAXPATHLEN) { |
| 194 | msg = "name too long for UNIX socket"; |
| 195 | goto err_return; |
| 196 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 197 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 198 | ret = snprintf(backname, MAXPATHLEN, "%s.%d.bak", path, pid); |
| 199 | if (ret < 0 || ret >= MAXPATHLEN) { |
| 200 | msg = "name too long for UNIX socket"; |
| 201 | goto err_return; |
| 202 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 203 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 204 | /* 2. clean existing orphaned entries */ |
| 205 | if (unlink(tempname) < 0 && errno != ENOENT) { |
| 206 | msg = "error when trying to unlink previous UNIX socket"; |
| 207 | goto err_return; |
| 208 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 209 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 210 | if (unlink(backname) < 0 && errno != ENOENT) { |
| 211 | msg = "error when trying to unlink previous UNIX socket"; |
| 212 | goto err_return; |
| 213 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 214 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 215 | /* 3. backup existing socket */ |
| 216 | if (link(path, backname) < 0 && errno != ENOENT) { |
| 217 | msg = "error when trying to preserve previous UNIX socket"; |
| 218 | goto err_return; |
| 219 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 220 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 221 | strncpy(addr.sun_path, tempname, sizeof(addr.sun_path)); |
| 222 | addr.sun_path[sizeof(addr.sun_path) - 1] = 0; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 223 | } |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 224 | else { |
| 225 | /* first char is zero, it's an abstract socket whose address |
| 226 | * is defined by all the bytes past this zero. |
| 227 | */ |
| 228 | memcpy(addr.sun_path, path, sizeof(addr.sun_path)); |
| 229 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 230 | addr.sun_family = AF_UNIX; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 231 | |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 232 | fd = socket(PF_UNIX, SOCK_STREAM, 0); |
| 233 | if (fd < 0) { |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 234 | msg = "cannot create UNIX socket"; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 235 | goto err_unlink_back; |
| 236 | } |
| 237 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 238 | fd_ready: |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 239 | if (fd >= global.maxsock) { |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 240 | msg = "socket(): not enough free sockets, raise -n argument"; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 241 | goto err_unlink_temp; |
| 242 | } |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 243 | |
| 244 | if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 245 | msg = "cannot make UNIX socket non-blocking"; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 246 | goto err_unlink_temp; |
| 247 | } |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 248 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 249 | if (!ext && bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 250 | /* note that bind() creates the socket <tempname> on the file system */ |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 251 | msg = "cannot bind UNIX socket"; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 252 | goto err_unlink_temp; |
| 253 | } |
| 254 | |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 255 | /* <uid> and <gid> different of -1 will be used to change the socket owner. |
| 256 | * If <mode> is not 0, it will be used to restrict access to the socket. |
| 257 | * While it is known not to be portable on every OS, it's still useful |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 258 | * where it works. We also don't change permissions on abstract sockets. |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 259 | */ |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 260 | if (!ext && path[0] && |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 261 | (((listener->bind_conf->ux.uid != -1 || listener->bind_conf->ux.gid != -1) && |
| 262 | (chown(tempname, listener->bind_conf->ux.uid, listener->bind_conf->ux.gid) == -1)) || |
| 263 | (listener->bind_conf->ux.mode != 0 && chmod(tempname, listener->bind_conf->ux.mode) == -1))) { |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 264 | msg = "cannot change UNIX socket ownership"; |
Willy Tarreau | e6ad2b1 | 2007-10-18 12:45:54 +0200 | [diff] [blame] | 265 | goto err_unlink_temp; |
| 266 | } |
| 267 | |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 268 | ready = 0; |
| 269 | ready_len = sizeof(ready); |
| 270 | if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &ready, &ready_len) == -1) |
| 271 | ready = 0; |
| 272 | |
| 273 | if (!(ext && ready) && /* only listen if not already done by external process */ |
| 274 | listen(fd, listener->backlog ? listener->backlog : listener->maxconn) < 0) { |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 275 | msg = "cannot listen to UNIX socket"; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 276 | goto err_unlink_temp; |
| 277 | } |
| 278 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 279 | /* Point of no return: we are ready, we'll switch the sockets. We don't |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 280 | * fear loosing the socket <path> because we have a copy of it in |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 281 | * backname. Abstract sockets are not renamed. |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 282 | */ |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 283 | if (!ext && path[0] && rename(tempname, path) < 0) { |
Willy Tarreau | b40dc94 | 2010-11-07 12:10:51 +0100 | [diff] [blame] | 284 | msg = "cannot switch final and temporary UNIX sockets"; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 285 | goto err_rename; |
| 286 | } |
| 287 | |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 288 | /* Cleanup: If we're bound to an fd inherited from the parent, we |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 289 | * want to ensure that destroy_uxst_socket() will never remove the |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 290 | * path, and for this we simply clear the path to the socket, which |
| 291 | * under Linux corresponds to an abstract socket. |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 292 | */ |
Willy Tarreau | ccfccef | 2014-05-10 01:49:15 +0200 | [diff] [blame] | 293 | if (!ext && path[0]) |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 294 | unlink(backname); |
| 295 | else |
| 296 | ((struct sockaddr_un *)&listener->addr)->sun_path[0] = 0; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 297 | |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 298 | /* the socket is now listening */ |
| 299 | listener->fd = fd; |
| 300 | listener->state = LI_LISTEN; |
| 301 | |
| 302 | /* the function for the accept() event */ |
| 303 | fd_insert(fd); |
Willy Tarreau | aece46a | 2012-07-06 12:25:58 +0200 | [diff] [blame] | 304 | fdtab[fd].iocb = listener->proto->accept; |
Willy Tarreau | eabf313 | 2008-08-29 23:36:51 +0200 | [diff] [blame] | 305 | fdtab[fd].owner = listener; /* reference the listener instead of a task */ |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 306 | return ERR_NONE; |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 307 | err_rename: |
| 308 | ret = rename(backname, path); |
| 309 | if (ret < 0 && errno == ENOENT) |
| 310 | unlink(path); |
| 311 | err_unlink_temp: |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 312 | if (!ext) |
| 313 | unlink(tempname); |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 314 | close(fd); |
| 315 | err_unlink_back: |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 316 | if (!ext) |
| 317 | unlink(backname); |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 318 | err_return: |
Willy Tarreau | 40aa070 | 2013-03-10 23:51:38 +0100 | [diff] [blame] | 319 | if (msg && errlen) { |
| 320 | if (!ext) |
| 321 | snprintf(errmsg, errlen, "%s [%s]", msg, path); |
| 322 | else |
| 323 | snprintf(errmsg, errlen, "%s [fd %d]", msg, fd); |
| 324 | } |
Cyril Bonté | 1f5848a | 2010-11-14 17:03:19 +0100 | [diff] [blame] | 325 | return ERR_FATAL | ERR_ALERT; |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* This function closes the UNIX sockets for the specified listener. |
| 329 | * The listener enters the LI_ASSIGNED state. It always returns ERR_NONE. |
| 330 | */ |
| 331 | static int uxst_unbind_listener(struct listener *listener) |
| 332 | { |
Willy Tarreau | be58c38 | 2011-07-24 18:28:10 +0200 | [diff] [blame] | 333 | if (listener->state > LI_ASSIGNED) { |
| 334 | unbind_listener(listener); |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 335 | destroy_uxst_socket(((struct sockaddr_un *)&listener->addr)->sun_path); |
| 336 | } |
| 337 | return ERR_NONE; |
| 338 | } |
| 339 | |
| 340 | /* Add a listener to the list of unix stream listeners. The listener's state |
| 341 | * is automatically updated from LI_INIT to LI_ASSIGNED. The number of |
| 342 | * listeners is updated. This is the function to use to add a new listener. |
| 343 | */ |
| 344 | void uxst_add_listener(struct listener *listener) |
| 345 | { |
| 346 | if (listener->state != LI_INIT) |
| 347 | return; |
| 348 | listener->state = LI_ASSIGNED; |
| 349 | listener->proto = &proto_unix; |
| 350 | LIST_ADDQ(&proto_unix.listeners, &listener->proto_list); |
| 351 | proto_unix.nb_listeners++; |
| 352 | } |
| 353 | |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 354 | |
| 355 | /* |
| 356 | * This function initiates a UNIX connection establishment to the target assigned |
| 357 | * to connection <conn> using (si->{target,addr.to}). The source address is ignored |
| 358 | * and will be selected by the system. conn->target may point either to a valid |
| 359 | * server or to a backend, depending on conn->target. Only OBJ_TYPE_PROXY and |
| 360 | * OBJ_TYPE_SERVER are supported. The <data> parameter is a boolean indicating |
| 361 | * whether there are data waiting for being sent or not, in order to adjust data |
| 362 | * write polling and on some platforms. The <delack> argument is ignored. |
| 363 | * |
| 364 | * Note that a pending send_proxy message accounts for data. |
| 365 | * |
| 366 | * It can return one of : |
| 367 | * - SN_ERR_NONE if everything's OK |
| 368 | * - SN_ERR_SRVTO if there are no more servers |
| 369 | * - SN_ERR_SRVCL if the connection was refused by the server |
| 370 | * - SN_ERR_PRXCOND if the connection has been limited by the proxy (maxconn) |
| 371 | * - SN_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...) |
| 372 | * - SN_ERR_INTERNAL for any other purely internal errors |
| 373 | * Additionnally, in the case of SN_ERR_RESOURCE, an emergency log will be emitted. |
| 374 | * |
| 375 | * The connection's fd is inserted only when SN_ERR_NONE is returned, otherwise |
| 376 | * it's invalid and the caller has nothing to do. |
| 377 | */ |
| 378 | int uxst_connect_server(struct connection *conn, int data, int delack) |
| 379 | { |
| 380 | int fd; |
| 381 | struct server *srv; |
| 382 | struct proxy *be; |
| 383 | |
Willy Tarreau | 7bb2153 | 2014-05-10 09:48:28 +0200 | [diff] [blame] | 384 | conn->flags = 0; |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 385 | |
| 386 | switch (obj_type(conn->target)) { |
| 387 | case OBJ_TYPE_PROXY: |
| 388 | be = objt_proxy(conn->target); |
| 389 | srv = NULL; |
| 390 | break; |
| 391 | case OBJ_TYPE_SERVER: |
| 392 | srv = objt_server(conn->target); |
| 393 | be = srv->proxy; |
| 394 | break; |
| 395 | default: |
| 396 | conn->flags |= CO_FL_ERROR; |
| 397 | return SN_ERR_INTERNAL; |
| 398 | } |
| 399 | |
| 400 | if ((fd = conn->t.sock.fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) { |
| 401 | qfprintf(stderr, "Cannot get a server socket.\n"); |
| 402 | |
| 403 | if (errno == ENFILE) { |
| 404 | conn->err_code = CO_ER_SYS_FDLIM; |
| 405 | send_log(be, LOG_EMERG, |
| 406 | "Proxy %s reached system FD limit at %d. Please check system tunables.\n", |
| 407 | be->id, maxfd); |
| 408 | } |
| 409 | else if (errno == EMFILE) { |
| 410 | conn->err_code = CO_ER_PROC_FDLIM; |
| 411 | send_log(be, LOG_EMERG, |
| 412 | "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n", |
| 413 | be->id, maxfd); |
| 414 | } |
| 415 | else if (errno == ENOBUFS || errno == ENOMEM) { |
| 416 | conn->err_code = CO_ER_SYS_MEMLIM; |
| 417 | send_log(be, LOG_EMERG, |
| 418 | "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n", |
| 419 | be->id, maxfd); |
| 420 | } |
| 421 | else if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT) { |
| 422 | conn->err_code = CO_ER_NOPROTO; |
| 423 | } |
| 424 | else |
| 425 | conn->err_code = CO_ER_SOCK_ERR; |
| 426 | |
| 427 | /* this is a resource error */ |
| 428 | conn->flags |= CO_FL_ERROR; |
| 429 | return SN_ERR_RESOURCE; |
| 430 | } |
| 431 | |
| 432 | if (fd >= global.maxsock) { |
| 433 | /* do not log anything there, it's a normal condition when this option |
| 434 | * is used to serialize connections to a server ! |
| 435 | */ |
| 436 | Alert("socket(): not enough free sockets. Raise -n argument. Giving up.\n"); |
| 437 | close(fd); |
| 438 | conn->err_code = CO_ER_CONF_FDLIM; |
| 439 | conn->flags |= CO_FL_ERROR; |
| 440 | return SN_ERR_PRXCOND; /* it is a configuration limit */ |
| 441 | } |
| 442 | |
| 443 | if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { |
| 444 | qfprintf(stderr,"Cannot set client socket to non blocking mode.\n"); |
| 445 | close(fd); |
| 446 | conn->err_code = CO_ER_SOCK_ERR; |
| 447 | conn->flags |= CO_FL_ERROR; |
| 448 | return SN_ERR_INTERNAL; |
| 449 | } |
| 450 | |
| 451 | /* if a send_proxy is there, there are data */ |
| 452 | data |= conn->send_proxy_ofs; |
| 453 | |
| 454 | if (global.tune.server_sndbuf) |
| 455 | setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &global.tune.server_sndbuf, sizeof(global.tune.server_sndbuf)); |
| 456 | |
| 457 | if (global.tune.server_rcvbuf) |
| 458 | setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &global.tune.server_rcvbuf, sizeof(global.tune.server_rcvbuf)); |
| 459 | |
Willy Tarreau | 7bb2153 | 2014-05-10 09:48:28 +0200 | [diff] [blame] | 460 | if (connect(fd, (struct sockaddr *)&conn->addr.to, get_addr_len(&conn->addr.to)) == -1) { |
| 461 | if (errno == EALREADY || errno == EISCONN) { |
| 462 | conn->flags &= ~CO_FL_WAIT_L4_CONN; |
| 463 | } |
| 464 | else if (errno == EINPROGRESS) { |
| 465 | conn->flags |= CO_FL_WAIT_L4_CONN; |
| 466 | } |
| 467 | else if (errno == EAGAIN || errno == EADDRINUSE || errno == EADDRNOTAVAIL) { |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 468 | char *msg; |
| 469 | if (errno == EAGAIN || errno == EADDRNOTAVAIL) { |
| 470 | msg = "no free ports"; |
| 471 | conn->err_code = CO_ER_FREE_PORTS; |
| 472 | } |
| 473 | else { |
| 474 | msg = "local address already in use"; |
| 475 | conn->err_code = CO_ER_ADDR_INUSE; |
| 476 | } |
| 477 | |
| 478 | qfprintf(stderr,"Connect() failed for backend %s: %s.\n", be->id, msg); |
| 479 | close(fd); |
| 480 | send_log(be, LOG_ERR, "Connect() failed for backend %s: %s.\n", be->id, msg); |
| 481 | conn->flags |= CO_FL_ERROR; |
| 482 | return SN_ERR_RESOURCE; |
| 483 | } |
| 484 | else if (errno == ETIMEDOUT) { |
| 485 | close(fd); |
| 486 | conn->err_code = CO_ER_SOCK_ERR; |
| 487 | conn->flags |= CO_FL_ERROR; |
| 488 | return SN_ERR_SRVTO; |
| 489 | } |
| 490 | else { // (errno == ECONNREFUSED || errno == ENETUNREACH || errno == EACCES || errno == EPERM) |
| 491 | close(fd); |
| 492 | conn->err_code = CO_ER_SOCK_ERR; |
| 493 | conn->flags |= CO_FL_ERROR; |
| 494 | return SN_ERR_SRVCL; |
| 495 | } |
| 496 | } |
Willy Tarreau | 7bb2153 | 2014-05-10 09:48:28 +0200 | [diff] [blame] | 497 | else { |
| 498 | /* connect() already succeeded, which is quite usual for unix |
| 499 | * sockets. Let's avoid a second connect() probe to complete it, |
| 500 | * but we need to ensure we'll wake up if there's no more handshake |
| 501 | * pending (eg: for health checks). |
| 502 | */ |
| 503 | conn->flags &= ~CO_FL_WAIT_L4_CONN; |
| 504 | if (!(conn->flags & CO_FL_HANDSHAKE)) |
| 505 | data = 1; |
| 506 | } |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 507 | |
| 508 | conn->flags |= CO_FL_ADDR_TO_SET; |
| 509 | |
| 510 | /* Prepare to send a few handshakes related to the on-wire protocol. */ |
| 511 | if (conn->send_proxy_ofs) |
| 512 | conn->flags |= CO_FL_SEND_PROXY; |
| 513 | |
| 514 | conn_ctrl_init(conn); /* registers the FD */ |
Willy Tarreau | 7bb2153 | 2014-05-10 09:48:28 +0200 | [diff] [blame] | 515 | fdtab[fd].linger_risk = 0; /* no need to disable lingering */ |
| 516 | if (conn->flags & CO_FL_HANDSHAKE) |
| 517 | conn_sock_want_send(conn); /* for connect status or proxy protocol */ |
Willy Tarreau | 47f48c4 | 2014-05-09 22:57:47 +0200 | [diff] [blame] | 518 | |
| 519 | if (conn_xprt_init(conn) < 0) { |
| 520 | conn_force_close(conn); |
| 521 | conn->flags |= CO_FL_ERROR; |
| 522 | return SN_ERR_RESOURCE; |
| 523 | } |
| 524 | |
| 525 | if (data) |
| 526 | conn_data_want_send(conn); /* prepare to send data if any */ |
| 527 | |
| 528 | return SN_ERR_NONE; /* connection is OK */ |
| 529 | } |
| 530 | |
| 531 | |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 532 | /******************************** |
| 533 | * 3) protocol-oriented functions |
| 534 | ********************************/ |
| 535 | |
| 536 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 537 | /* This function creates all UNIX sockets bound to the protocol entry <proto>. |
| 538 | * It is intended to be used as the protocol's bind_all() function. |
| 539 | * The sockets will be registered but not added to any fd_set, in order not to |
| 540 | * loose them across the fork(). A call to uxst_enable_listeners() is needed |
| 541 | * to complete initialization. |
| 542 | * |
| 543 | * The return value is composed from ERR_NONE, ERR_RETRYABLE and ERR_FATAL. |
| 544 | */ |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 545 | static int uxst_bind_listeners(struct protocol *proto, char *errmsg, int errlen) |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 546 | { |
| 547 | struct listener *listener; |
| 548 | int err = ERR_NONE; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 549 | |
| 550 | list_for_each_entry(listener, &proto->listeners, proto_list) { |
Emeric Brun | cf20bf1 | 2010-10-22 16:06:11 +0200 | [diff] [blame] | 551 | err |= uxst_bind_listener(listener, errmsg, errlen); |
| 552 | if (err & ERR_ABORT) |
| 553 | break; |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 554 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 555 | return err; |
| 556 | } |
| 557 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 558 | |
| 559 | /* This function stops all listening UNIX sockets bound to the protocol |
| 560 | * <proto>. It does not detaches them from the protocol. |
| 561 | * It always returns ERR_NONE. |
| 562 | */ |
| 563 | static int uxst_unbind_listeners(struct protocol *proto) |
| 564 | { |
| 565 | struct listener *listener; |
| 566 | |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 567 | list_for_each_entry(listener, &proto->listeners, proto_list) |
| 568 | uxst_unbind_listener(listener); |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 569 | return ERR_NONE; |
| 570 | } |
| 571 | |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 572 | /* parse the "mode" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 573 | static int bind_parse_mode(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 574 | { |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 575 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 576 | memprintf(err, "'%s' : missing mode (octal integer expected)", args[cur_arg]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 577 | return ERR_ALERT | ERR_FATAL; |
| 578 | } |
| 579 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 580 | conf->ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | /* parse the "gid" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 585 | static int bind_parse_gid(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 586 | { |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 587 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 588 | memprintf(err, "'%s' : missing value", args[cur_arg]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 589 | return ERR_ALERT | ERR_FATAL; |
| 590 | } |
| 591 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 592 | conf->ux.gid = atol(args[cur_arg + 1]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | /* parse the "group" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 597 | static int bind_parse_group(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 598 | { |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 599 | struct group *group; |
| 600 | |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 601 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 602 | memprintf(err, "'%s' : missing group name", args[cur_arg]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 603 | return ERR_ALERT | ERR_FATAL; |
| 604 | } |
| 605 | |
| 606 | group = getgrnam(args[cur_arg + 1]); |
| 607 | if (!group) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 608 | memprintf(err, "'%s' : unknown group name '%s'", args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 609 | return ERR_ALERT | ERR_FATAL; |
| 610 | } |
| 611 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 612 | conf->ux.gid = group->gr_gid; |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | /* parse the "uid" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 617 | static int bind_parse_uid(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 618 | { |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 619 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 620 | memprintf(err, "'%s' : missing value", args[cur_arg]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 621 | return ERR_ALERT | ERR_FATAL; |
| 622 | } |
| 623 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 624 | conf->ux.uid = atol(args[cur_arg + 1]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | /* parse the "user" bind keyword */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 629 | static int bind_parse_user(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 630 | { |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 631 | struct passwd *user; |
| 632 | |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 633 | if (!*args[cur_arg + 1]) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 634 | memprintf(err, "'%s' : missing user name", args[cur_arg]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 635 | return ERR_ALERT | ERR_FATAL; |
| 636 | } |
| 637 | |
| 638 | user = getpwnam(args[cur_arg + 1]); |
| 639 | if (!user) { |
Willy Tarreau | eb6cead | 2012-09-20 19:43:14 +0200 | [diff] [blame] | 640 | memprintf(err, "'%s' : unknown user name '%s'", args[cur_arg], args[cur_arg + 1]); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 641 | return ERR_ALERT | ERR_FATAL; |
| 642 | } |
| 643 | |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 644 | conf->ux.uid = user->pw_uid; |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | /* Note: must not be declared <const> as its list will be overwritten. |
| 649 | * Please take care of keeping this list alphabetically sorted, doing so helps |
| 650 | * all code contributors. |
| 651 | * Optional keywords are also declared with a NULL ->parse() function so that |
| 652 | * the config parser can report an appropriate error when a known keyword was |
| 653 | * not enabled. |
| 654 | */ |
Willy Tarreau | 51fb765 | 2012-09-18 18:24:39 +0200 | [diff] [blame] | 655 | static struct bind_kw_list bind_kws = { "UNIX", { }, { |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 656 | { "gid", bind_parse_gid, 1 }, /* set the socket's gid */ |
| 657 | { "group", bind_parse_group, 1 }, /* set the socket's gid from the group name */ |
| 658 | { "mode", bind_parse_mode, 1 }, /* set the socket's mode (eg: 0644)*/ |
| 659 | { "uid", bind_parse_uid, 1 }, /* set the socket's uid */ |
| 660 | { "user", bind_parse_user, 1 }, /* set the socket's uid from the user name */ |
| 661 | { NULL, NULL, 0 }, |
| 662 | }}; |
Willy Tarreau | dabf2e2 | 2007-10-28 21:59:24 +0100 | [diff] [blame] | 663 | |
| 664 | /******************************** |
| 665 | * 4) high-level functions |
| 666 | ********************************/ |
| 667 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 668 | __attribute__((constructor)) |
| 669 | static void __uxst_protocol_init(void) |
| 670 | { |
| 671 | protocol_register(&proto_unix); |
Willy Tarreau | d0a895d | 2012-09-18 17:40:35 +0200 | [diff] [blame] | 672 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | |
| 676 | /* |
| 677 | * Local variables: |
| 678 | * c-indent-level: 8 |
| 679 | * c-basic-offset: 8 |
| 680 | * End: |
| 681 | */ |