annotate src/interface.c @ 421:f37384470855

Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup. Moved the lockdir out of the spool dir. (When /var/lock is a ramdisk we do well to have the lock files there.) Added the new configure option --with-lockdir to change that location. Nontheless, if we run_as_user, then lock files are always stored in the spool dir directly. Instead of installing the lockdir and piddir at installation time, we create them on startup time now if they are missing. This is necessary if lockdir or piddir are a tmpfs.
author markus schnalke <meillo@marmaro.de>
date Wed, 30 May 2012 09:38:38 +0200
parents 164468dd0953
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
1 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
2 ** MasqMail
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
3 ** Copyright (C) 2000 Oliver Kurth
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
4 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
6 ** it under the terms of the GNU General Public License as published by
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
8 ** (at your option) any later version.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
9 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
10 ** This program is distributed in the hope that it will be useful,
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
13 ** GNU General Public License for more details.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
14 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
15 ** You should have received a copy of the GNU General Public License
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
16 ** along with this program; if not, write to the Free Software
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22 /* define if you get problems... */
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
23 /* #define SOCKADDR_OLD 1 */
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
24
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
25 gboolean
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 10
diff changeset
26 init_sockaddr(struct sockaddr_in *name, interface *iface)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
27 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
28 struct hostent *he;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
29 struct in_addr ia;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
30
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
31 #ifdef SOCKADDR_OLD
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
32 /* here I tried to be intelligent and failed. */
407
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
33 if (isalpha(*iface->address)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
34 if ((he = gethostbyname(iface->address)) == NULL) {
407
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
35 logwrite(LOG_ALERT, "local address '%s' unknown. "
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
36 "(deleting)\n", iface->address);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
37 return FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
38 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
39 memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr));
407
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
40 } else if (isdigit(*iface->address)) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
41 if (inet_aton(iface->address, &ia)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
42 memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
43 } else {
407
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
44 logwrite(LOG_ALERT, "invalid address '%s': "
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
45 "inet_aton() failed (deleting)\n",
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
46 iface->address);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
47 return FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
48 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
49 } else {
407
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
50 logwrite(LOG_ALERT, "invalid address '%s', should begin with "
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
51 "a aphanumeric (deleting)\n", iface->address);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
52 return FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
53 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
54 #else
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
55 /* this is how others to it. I follow the crowd... */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
56 if (inet_aton(iface->address, &ia) != 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
57 /* IP address */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
58 memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
59 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60 if ((he = gethostbyname(iface->address)) == NULL) {
407
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
61 logwrite(LOG_ALERT, "local address '%s' unknown. "
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
62 "(deleting)\n", iface->address);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 return FALSE;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
64 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
65 memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
66 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
67 #endif
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
68 name->sin_family = AF_INET;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
69 name->sin_port = htons(iface->port);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
70
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
71 return TRUE;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
72 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
73
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
74 int
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 10
diff changeset
75 make_server_socket(interface *iface)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
76 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 int sock = -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
78 struct sockaddr_in server;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
79
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
80 memset(&server, 0, sizeof(struct sockaddr_in));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
81
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
82 /* Create the socket. */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
83 sock = socket(PF_INET, SOCK_STREAM, 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
84 if (sock < 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
85 logwrite(LOG_ALERT, "socket: %s\n", strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
86 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
87 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
88
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
89 if (init_sockaddr(&server, iface)) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
90 /* bind the socket */
407
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
91 if (bind(sock, (struct sockaddr *) &server,
164468dd0953 Minor refactoring.
markus schnalke <meillo@marmaro.de>
parents: 367
diff changeset
92 sizeof(server)) < 0) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
93 logwrite(LOG_ALERT, "bind: %s\n", strerror(errno));
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
94 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
95 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
96 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
97 close(sock);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 return -1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
99 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
100
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 return sock;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
102 }