Mercurial > hg > dhcpcd
annotate src/script.c @ 5535:a0d828e25482 draft
Add --noconfigure option
With this set dhcpcd will not configure anything on the host.
The expectation is that a 3rd party script will instead.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Wed, 04 Nov 2020 14:18:48 +0000 |
| parents | 2737c3236e66 |
| children | 4fe5c2a71254 |
| rev | line source |
|---|---|
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
1 /* SPDX-License-Identifier: BSD-2-Clause */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3 * dhcpcd - DHCP client daemon |
| 4922 | 4 * Copyright (c) 2006-2020 Roy Marples <roy@marples.name> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
5 * All rights reserved |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
7 * Redistribution and use in source and binary forms, with or without |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
8 * modification, are permitted provided that the following conditions |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
9 * are met: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
10 * 1. Redistributions of source code must retain the above copyright |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
11 * notice, this list of conditions and the following disclaimer. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
13 * notice, this list of conditions and the following disclaimer in the |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
14 * documentation and/or other materials provided with the distribution. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
15 * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
26 * SUCH DAMAGE. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
27 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
28 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
29 #include <sys/stat.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
30 #include <sys/uio.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
31 #include <sys/wait.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
32 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
33 #include <netinet/in.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
34 #include <arpa/inet.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
35 |
|
4618
7eb6c52adf99
script: assert that the env strings are correctly terminated
Roy Marples <roy@marples.name>
parents:
4592
diff
changeset
|
36 #include <assert.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
37 #include <ctype.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
38 #include <errno.h> |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
39 #include <pwd.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
40 #include <signal.h> |
|
3955
40c5dcedcd9d
Fix compile with posix_spawn now being required.
Roy Marples <roy@marples.name>
parents:
3932
diff
changeset
|
41 #include <spawn.h> |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
42 #include <stdarg.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
43 #include <stdlib.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
44 #include <string.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
45 #include <unistd.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
46 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
47 #include "config.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
48 #include "common.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
49 #include "dhcp.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
50 #include "dhcp6.h" |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
51 #include "eloop.h" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
52 #include "if.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
53 #include "if-options.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
54 #include "ipv4ll.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
55 #include "ipv6nd.h" |
| 4010 | 56 #include "logerr.h" |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
57 #include "privsep.h" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
58 #include "script.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
59 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
60 #define DEFAULT_PATH "/usr/bin:/usr/sbin:/bin:/sbin" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
61 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
62 static const char * const if_params[] = { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
63 "interface", |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
64 "protocol", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
65 "reason", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
66 "pid", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
67 "ifcarrier", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
68 "ifmetric", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
69 "ifwireless", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
70 "ifflags", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
71 "ssid", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
72 "profile", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
73 "interface_order", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
74 NULL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
75 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
76 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
77 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
78 if_printoptions(void) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
79 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
80 const char * const *p; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
81 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
82 for (p = if_params; *p; p++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
83 printf(" - %s\n", *p); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
84 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
85 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
86 pid_t |
|
5123
9422e8c904d5
scripts: Run with an empty sigmask
Christos Zoulas <christos@zoulas.com>
parents:
5094
diff
changeset
|
87 script_exec(char *const *argv, char *const *env) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
88 { |
|
4811
dd1237e36c28
script: Ensure pid is initialised.
Roy Marples <roy@marples.name>
parents:
4794
diff
changeset
|
89 pid_t pid = 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
90 posix_spawnattr_t attr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
91 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
92 #ifdef USE_SIGNALS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
93 size_t i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
94 short flags; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
95 sigset_t defsigs; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
96 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
97 UNUSED(ctx); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
98 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
99 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
100 /* posix_spawn is a safe way of executing another image |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
101 * and changing signals back to how they should be. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
102 if (posix_spawnattr_init(&attr) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
103 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
104 #ifdef USE_SIGNALS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
105 flags = POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
106 posix_spawnattr_setflags(&attr, flags); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
107 sigemptyset(&defsigs); |
|
5123
9422e8c904d5
scripts: Run with an empty sigmask
Christos Zoulas <christos@zoulas.com>
parents:
5094
diff
changeset
|
108 posix_spawnattr_setsigmask(&attr, &defsigs); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
109 for (i = 0; i < dhcpcd_signals_len; i++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
110 sigaddset(&defsigs, dhcpcd_signals[i]); |
|
5227
7406014c9120
dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents:
5209
diff
changeset
|
111 for (i = 0; i < dhcpcd_signals_ignore_len; i++) |
|
7406014c9120
dhcpcd: allow sigpipe in scripts.
Roy Marples <roy@marples.name>
parents:
5209
diff
changeset
|
112 sigaddset(&defsigs, dhcpcd_signals_ignore[i]); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
113 posix_spawnattr_setsigdefault(&attr, &defsigs); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
114 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
115 errno = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
116 r = posix_spawn(&pid, argv[0], NULL, &attr, argv, env); |
|
3981
4cc60b4c804b
Call posix_spawnattr_destroy after calling posix_spawn so that
Roy Marples <roy@marples.name>
parents:
3960
diff
changeset
|
117 posix_spawnattr_destroy(&attr); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
118 if (r) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
119 errno = r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
120 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
121 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
122 return pid; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
123 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
124 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
125 #ifdef INET |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
126 static int |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
127 append_config(FILE *fp, const char *prefix, const char *const *config) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
128 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
129 size_t i; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
130 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
131 if (config == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
132 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
133 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
134 /* Do we need to replace existing config rather than append? */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
135 for (i = 0; config[i] != NULL; i++) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
136 if (efprintf(fp, "%s_%s", prefix, config[i]) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
137 return -1; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
138 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
139 return 1; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
140 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
141 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
142 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
143 |
|
4196
ed557660dc3d
hooks: set protocol to link for link layer events
Roy Marples <roy@marples.name>
parents:
4176
diff
changeset
|
144 #define PROTO_LINK 0 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
145 #define PROTO_DHCP 1 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
146 #define PROTO_IPV4LL 2 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
147 #define PROTO_RA 3 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
148 #define PROTO_DHCP6 4 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
149 #define PROTO_STATIC6 5 |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
150 static const char *protocols[] = { |
|
4196
ed557660dc3d
hooks: set protocol to link for link layer events
Roy Marples <roy@marples.name>
parents:
4176
diff
changeset
|
151 "link", |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
152 "dhcp", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
153 "ipv4ll", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
154 "ra", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
155 "dhcp6", |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
156 "static6" |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
157 }; |
|
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
158 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
159 int |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
160 efprintf(FILE *fp, const char *fmt, ...) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
161 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
162 va_list args; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
163 int r; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
164 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
165 va_start(args, fmt); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
166 r = vfprintf(fp, fmt, args); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
167 va_end(args); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
168 if (r == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
169 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
170 /* Write a trailing NULL so we can easily create env strings. */ |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
171 if (fputc('\0', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
172 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
173 return r; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
174 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
175 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
176 char ** |
| 4794 | 177 script_buftoenv(struct dhcpcd_ctx *ctx, char *buf, size_t len) |
| 178 { | |
| 179 char **env, **envp, *bufp, *endp; | |
| 180 size_t nenv; | |
| 181 | |
| 182 /* Count the terminated env strings. | |
| 183 * Assert that the terminations are correct. */ | |
| 184 nenv = 0; | |
| 185 endp = buf + len; | |
| 186 for (bufp = buf; bufp < endp; bufp++) { | |
| 187 if (*bufp == '\0') { | |
| 188 #ifndef NDEBUG | |
| 189 if (bufp + 1 < endp) | |
| 190 assert(*(bufp + 1) != '\0'); | |
| 191 #endif | |
| 192 nenv++; | |
| 193 } | |
| 194 } | |
| 195 assert(*(bufp - 1) == '\0'); | |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
196 if (nenv == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
197 return NULL; |
| 4794 | 198 |
| 199 if (ctx->script_envlen < nenv) { | |
| 200 env = reallocarray(ctx->script_env, nenv + 1, sizeof(*env)); | |
| 201 if (env == NULL) | |
| 202 return NULL; | |
| 203 ctx->script_env = env; | |
| 204 ctx->script_envlen = nenv; | |
| 205 } | |
| 206 | |
| 207 bufp = buf; | |
| 208 envp = ctx->script_env; | |
| 209 *envp++ = bufp++; | |
| 210 endp--; /* Avoid setting the last \0 to an invalid pointer */ | |
| 211 for (; bufp < endp; bufp++) { | |
| 212 if (*bufp == '\0') | |
| 213 *envp++ = bufp + 1; | |
| 214 } | |
| 215 *envp = NULL; | |
| 216 | |
| 217 return ctx->script_env; | |
| 218 } | |
| 219 | |
|
4621
0a612323151a
script: Send the actual env len, not the buffer size to listeners.
Roy Marples <roy@marples.name>
parents:
4620
diff
changeset
|
220 static long |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
221 make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp, |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
222 const char *reason) |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
223 { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
224 FILE *fp; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
225 long buf_pos, i; |
| 4794 | 226 char *path; |
| 4582 | 227 int protocol = PROTO_LINK; |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
228 const struct if_options *ifo; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
229 const struct interface *ifp2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
230 int af; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
231 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
232 const struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
233 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
234 const struct ipv4ll_state *istate; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
235 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
236 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
237 #ifdef DHCP6 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
238 const struct dhcp6_state *d6_state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
239 #endif |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
240 bool is_stdin = ifp->name[0] == '\0'; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
241 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
242 #ifdef HAVE_OPEN_MEMSTREAM |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
243 if (ctx->script_fp == NULL) { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
244 fp = open_memstream(&ctx->script_buf, &ctx->script_buflen); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
245 if (fp == NULL) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
246 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
247 ctx->script_fp = fp; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
248 } else { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
249 fp = ctx->script_fp; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
250 rewind(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
251 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
252 #else |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
253 char tmpfile[] = "/tmp/dhcpcd-script-env-XXXXXX"; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
254 int tmpfd; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
255 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
256 fp = NULL; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
257 tmpfd = mkstemp(tmpfile); |
|
5271
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
258 if (tmpfd == -1) { |
|
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
259 logerr("%s: mkstemp", __func__); |
|
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
260 return -1; |
|
8fb09d31d388
For systems without open_memstream(3) warn that /tmp needs to exit
Roy Marples <roy@marples.name>
parents:
5259
diff
changeset
|
261 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
262 unlink(tmpfile); |
|
4592
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
263 fp = fdopen(tmpfd, "w+"); |
|
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
264 if (fp == NULL) { |
|
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
265 close(tmpfd); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
266 goto eexit; |
|
4592
b61b15725a70
script: ensure that tmp files are removed
Roy Marples <roy@marples.name>
parents:
4582
diff
changeset
|
267 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
268 #endif |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
269 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
270 if (!(ifp->ctx->options & DHCPCD_DUMPLEASE)) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
271 /* Needed for scripts */ |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
272 path = getenv("PATH"); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
273 if (efprintf(fp, "PATH=%s", |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
274 path == NULL ? DEFAULT_PATH : path) == -1) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
275 goto eexit; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
276 if (efprintf(fp, "pid=%d", getpid()) == -1) |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
277 goto eexit; |
|
4995
91c3d1ed3496
privsep: Note CHROOT script
Roy Marples <roy@marples.name>
parents:
4994
diff
changeset
|
278 } |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
279 if (!is_stdin) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
280 if (efprintf(fp, "reason=%s", reason) == -1) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
281 goto eexit; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
282 } |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
283 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
284 ifo = ifp->options; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
285 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
286 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
287 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
288 istate = IPV4LL_CSTATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
289 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
290 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
291 #ifdef DHCP6 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
292 d6_state = D6_CSTATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
293 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
294 if (strcmp(reason, "TEST") == 0) { |
|
4867
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
295 if (1 == 2) { |
|
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
296 /* This space left intentionally blank |
|
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
297 * as all the below statements are optional. */ |
|
f06daa979f98
script: Document why this block is intentionally blank.
Roy Marples <roy@marples.name>
parents:
4840
diff
changeset
|
298 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
299 #ifdef INET6 |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
300 #ifdef DHCP6 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
301 else if (d6_state && d6_state->new) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
302 protocol = PROTO_DHCP6; |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
303 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
304 else if (ipv6nd_hasra(ifp)) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
305 protocol = PROTO_RA; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
306 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
307 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
308 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
309 else if (istate && istate->addr != NULL) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
310 protocol = PROTO_IPV4LL; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
311 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
312 else |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
313 protocol = PROTO_DHCP; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
314 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
315 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
316 #ifdef INET6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
317 else if (strcmp(reason, "STATIC6") == 0) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
318 protocol = PROTO_STATIC6; |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
319 #ifdef DHCP6 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
320 else if (reason[strlen(reason) - 1] == '6') |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
321 protocol = PROTO_DHCP6; |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
322 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
323 else if (strcmp(reason, "ROUTERADVERT") == 0) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
324 protocol = PROTO_RA; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
325 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
326 else if (strcmp(reason, "PREINIT") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
327 strcmp(reason, "CARRIER") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
328 strcmp(reason, "NOCARRIER") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
329 strcmp(reason, "UNKNOWN") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
330 strcmp(reason, "DEPARTED") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
331 strcmp(reason, "STOPPED") == 0) |
|
4196
ed557660dc3d
hooks: set protocol to link for link layer events
Roy Marples <roy@marples.name>
parents:
4176
diff
changeset
|
332 protocol = PROTO_LINK; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
333 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
334 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
335 else if (strcmp(reason, "IPV4LL") == 0) |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
336 protocol = PROTO_IPV4LL; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
337 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
338 else |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
339 protocol = PROTO_DHCP; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
340 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
341 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
342 if (!is_stdin) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
343 if (efprintf(fp, "interface=%s", ifp->name) == -1) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
344 goto eexit; |
|
5379
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
345 if (protocols[protocol] != NULL) { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
346 if (efprintf(fp, "protocol=%s", |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
347 protocols[protocol]) == -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
348 goto eexit; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
349 } |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
350 } |
|
5379
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
351 if (ifp->ctx->options & DHCPCD_DUMPLEASE && protocol != PROTO_LINK) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
352 goto dumplease; |
| 5535 | 353 if (efprintf(fp, "if_configured=%s", |
| 354 ifo->options & DHCPCD_CONFIGURE ? "true" : "false") == -1) | |
| 355 goto eexit; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
356 if (efprintf(fp, "ifcarrier=%s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
357 ifp->carrier == LINK_UNKNOWN ? "unknown" : |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
358 ifp->carrier == LINK_UP ? "up" : "down") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
359 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
360 if (efprintf(fp, "ifmetric=%d", ifp->metric) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
361 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
362 if (efprintf(fp, "ifwireless=%d", ifp->wireless) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
363 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
364 if (efprintf(fp, "ifflags=%u", ifp->flags) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
365 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
366 if (efprintf(fp, "ifmtu=%d", if_getmtu(ifp)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
367 goto eexit; |
|
5379
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
368 if (ifp->wireless) { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
369 char pssid[IF_SSIDLEN * 4]; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
370 |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
371 if (print_string(pssid, sizeof(pssid), OT_ESCSTRING, |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
372 ifp->ssid, ifp->ssid_len) != -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
373 { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
374 if (efprintf(fp, "ifssid=%s", pssid) == -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
375 goto eexit; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
376 } |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
377 } |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
378 if (*ifp->profile != '\0') { |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
379 if (efprintf(fp, "profile=%s", ifp->profile) == -1) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
380 goto eexit; |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
381 } |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
382 if (ifp->ctx->options & DHCPCD_DUMPLEASE) |
|
ca610debb37b
script: Make visible some link level parameters to lease dumping
Roy Marples <roy@marples.name>
parents:
5328
diff
changeset
|
383 goto dumplease; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
384 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
385 if (fprintf(fp, "interface_order=") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
386 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
387 TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
388 if (ifp2 != TAILQ_FIRST(ifp->ctx->ifaces)) { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
389 if (fputc(' ', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
390 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
391 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
392 if (fprintf(fp, "%s", ifp2->name) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
393 return -1; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
394 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
395 if (fputc('\0', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
396 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
397 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
398 if (strcmp(reason, "STOPPED") == 0) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
399 if (efprintf(fp, "if_up=false") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
400 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
401 if (efprintf(fp, "if_down=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
402 ifo->options & DHCPCD_RELEASE ? "true" : "false") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
403 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
404 } else if (strcmp(reason, "TEST") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
405 strcmp(reason, "PREINIT") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
406 strcmp(reason, "CARRIER") == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
407 strcmp(reason, "UNKNOWN") == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
408 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
409 if (efprintf(fp, "if_up=false") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
410 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
411 if (efprintf(fp, "if_down=false") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
412 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
413 } else if (1 == 2 /* appease ifdefs */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
414 #ifdef INET |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
415 || (protocol == PROTO_DHCP && state && state->new) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
416 #ifdef IPV4LL |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
417 || (protocol == PROTO_IPV4LL && IPV4LL_STATE_RUNNING(ifp)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
418 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
419 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
420 #ifdef INET6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
421 || (protocol == PROTO_STATIC6 && IPV6_STATE_RUNNING(ifp)) |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
422 #ifdef DHCP6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
423 || (protocol == PROTO_DHCP6 && d6_state && d6_state->new) |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
424 #endif |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
425 || (protocol == PROTO_RA && ipv6nd_hasra(ifp)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
426 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
427 ) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
428 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
429 if (efprintf(fp, "if_up=true") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
430 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
431 if (efprintf(fp, "if_down=false") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
432 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
433 } else { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
434 if (efprintf(fp, "if_up=false") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
435 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
436 if (efprintf(fp, "if_down=true") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
437 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
438 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
439 if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
440 if (efprintf(fp, "if_afwaiting=%d", af) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
441 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
442 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
443 if ((af = dhcpcd_afwaiting(ifp->ctx)) != AF_MAX) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
444 TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
445 if ((af = dhcpcd_ifafwaiting(ifp2)) != AF_MAX) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
446 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
447 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
448 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
449 if (af != AF_MAX) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
450 if (efprintf(fp, "af_waiting=%d", af) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
451 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
452 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
453 if (ifo->options & DHCPCD_DEBUG) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
454 if (efprintf(fp, "syslog_debug=true") == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
455 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
456 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
457 #ifdef INET |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
458 if (protocol == PROTO_DHCP && state && state->old) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
459 if (dhcp_env(fp, "old", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
460 state->old, state->old_len) == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
461 goto eexit; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
462 if (append_config(fp, "old", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
463 (const char *const *)ifo->config) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
464 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
465 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
466 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
467 #ifdef DHCP6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
468 if (protocol == PROTO_DHCP6 && d6_state && d6_state->old) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
469 if (dhcp6_env(fp, "old", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
470 d6_state->old, d6_state->old_len) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
471 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
472 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
473 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
474 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
475 dumplease: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
476 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
477 #ifdef IPV4LL |
|
5011
ec0c1c259be4
IPv4LL: A state might not always exist when running the script.
Christos Zoulas <christos@netbsd.org>
parents:
4996
diff
changeset
|
478 if (protocol == PROTO_IPV4LL && istate) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
479 if (ipv4ll_env(fp, istate->down ? "old" : "new", ifp) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
480 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
481 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
482 #endif |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
483 if (protocol == PROTO_DHCP && state && state->new) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
484 if (dhcp_env(fp, "new", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
485 state->new, state->new_len) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
486 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
487 if (append_config(fp, "new", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
488 (const char *const *)ifo->config) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
489 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
490 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
491 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
492 #ifdef INET6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
493 if (protocol == PROTO_STATIC6) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
494 if (ipv6_env(fp, "new", ifp) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
495 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
496 } |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
497 #ifdef DHCP6 |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
498 if (protocol == PROTO_DHCP6 && D6_STATE_RUNNING(ifp)) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
499 if (dhcp6_env(fp, "new", ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
500 d6_state->new, d6_state->new_len) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
501 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
502 } |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
503 #endif |
|
4176
612d80156afd
dhcpcd-run-hooks(8) should not attempt to guess the protocol.
Roy Marples <roy@marples.name>
parents:
4023
diff
changeset
|
504 if (protocol == PROTO_RA) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
505 if (ipv6nd_env(fp, ifp) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
506 goto eexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
507 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
508 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
509 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
510 /* Add our base environment */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
511 if (ifo->environ) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
512 for (i = 0; ifo->environ[i] != NULL; i++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
513 if (efprintf(fp, "%s", ifo->environ[i]) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
514 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
515 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
516 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
517 /* Convert buffer to argv */ |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
518 fflush(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
519 |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
520 buf_pos = ftell(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
521 if (buf_pos == -1) { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
522 logerr(__func__); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
523 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
524 } |
| 4620 | 525 |
| 526 #ifndef HAVE_OPEN_MEMSTREAM | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
527 size_t buf_len = (size_t)buf_pos; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
528 if (ctx->script_buflen < buf_len) { |
| 4620 | 529 char *buf = realloc(ctx->script_buf, buf_len); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
530 if (buf == NULL) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
531 goto eexit; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
532 ctx->script_buf = buf; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
533 ctx->script_buflen = buf_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
534 } |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
535 rewind(fp); |
| 4620 | 536 if (fread(ctx->script_buf, sizeof(char), buf_len, fp) != buf_len) |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
537 goto eexit; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
538 fclose(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
539 fp = NULL; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
540 #endif |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
541 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
542 if (is_stdin) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
543 return buf_pos; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
544 |
| 4794 | 545 if (script_buftoenv(ctx, ctx->script_buf, (size_t)buf_pos) == NULL) |
| 546 goto eexit; | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
547 |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
548 return buf_pos; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
549 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
550 eexit: |
| 4010 | 551 logerr(__func__); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
552 #ifndef HAVE_OPEN_MEMSTREAM |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
553 if (fp != NULL) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
554 fclose(fp); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
555 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
556 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
557 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
558 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
559 static int |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
560 send_interface1(struct fd_list *fd, const struct interface *ifp, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
561 const char *reason) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
562 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
563 struct dhcpcd_ctx *ctx = ifp->ctx; |
|
4621
0a612323151a
script: Send the actual env len, not the buffer size to listeners.
Roy Marples <roy@marples.name>
parents:
4620
diff
changeset
|
564 long len; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
565 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
566 len = make_env(ifp->ctx, ifp, reason); |
|
4621
0a612323151a
script: Send the actual env len, not the buffer size to listeners.
Roy Marples <roy@marples.name>
parents:
4620
diff
changeset
|
567 if (len == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
568 return -1; |
|
5328
ea68407e5ac8
privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
569 return control_queue(fd, ctx->script_buf, (size_t)len); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
570 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
571 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
572 int |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
573 send_interface(struct fd_list *fd, const struct interface *ifp, int af) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
574 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
575 int retval = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
576 #ifdef INET |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
577 const struct dhcp_state *d; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
578 #endif |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
579 #ifdef DHCP6 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
580 const struct dhcp6_state *d6; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
581 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
582 |
| 5094 | 583 #ifndef AF_LINK |
| 584 #define AF_LINK AF_PACKET | |
| 585 #endif | |
| 586 | |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
587 if (af == AF_UNSPEC || af == AF_LINK) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
588 const char *reason; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
589 |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
590 switch (ifp->carrier) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
591 case LINK_UP: |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
592 reason = "CARRIER"; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
593 break; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
594 case LINK_DOWN: |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
595 reason = "NOCARRIER"; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
596 break; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
597 default: |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
598 reason = "UNKNOWN"; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
599 break; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
600 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
601 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
602 if (send_interface1(fd, ifp, reason) == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
603 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
604 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
605 retval++; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
606 } |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
607 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
608 #ifdef INET |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
609 if (af == AF_UNSPEC || af == AF_INET) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
610 if (D_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
611 d = D_CSTATE(ifp); |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
612 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
613 if (send_interface1(fd, ifp, d->reason) == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
614 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
615 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
616 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
617 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
618 #ifdef IPV4LL |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
619 if (IPV4LL_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
620 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
621 if (send_interface1(fd, ifp, "IPV4LL") == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
622 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
623 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
624 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
625 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
626 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
627 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
628 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
629 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
630 #ifdef INET6 |
|
5092
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
631 if (af == AF_UNSPEC || af == AF_INET6) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
632 if (IPV6_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
633 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
634 if (send_interface1(fd, ifp, "STATIC6") == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
635 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
636 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
637 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
638 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
639 if (RS_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
640 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
641 if (send_interface1(fd, ifp, |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
642 "ROUTERADVERT") == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
643 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
644 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
645 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
646 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
647 #ifdef DHCP6 |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
648 if (D6_STATE_RUNNING(ifp)) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
649 d6 = D6_CSTATE(ifp); |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
650 if (fd != NULL) { |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
651 if (send_interface1(fd, ifp, d6->reason) == -1) |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
652 retval = -1; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
653 } else |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
654 retval++; |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
655 } |
|
995a49ee3418
dhcpcd: dumping lease uses control socket to get the lease
Roy Marples <roy@marples.name>
parents:
5011
diff
changeset
|
656 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
657 } |
|
4349
f87c2ed9ff46
DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
658 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
659 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
660 return retval; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
661 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
662 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
663 static int |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
664 script_run(struct dhcpcd_ctx *ctx, char **argv) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
665 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
666 pid_t pid; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
667 int status = 0; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4811
diff
changeset
|
668 |
|
5123
9422e8c904d5
scripts: Run with an empty sigmask
Christos Zoulas <christos@zoulas.com>
parents:
5094
diff
changeset
|
669 pid = script_exec(argv, ctx->script_env); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
670 if (pid == -1) |
| 4010 | 671 logerr("%s: %s", __func__, argv[0]); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
672 else if (pid != 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
673 /* Wait for the script to finish */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
674 while (waitpid(pid, &status, 0) == -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
675 if (errno != EINTR) { |
| 4010 | 676 logerr("%s: waitpid", __func__); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
677 status = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
678 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
679 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
680 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
681 if (WIFEXITED(status)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
682 if (WEXITSTATUS(status)) |
| 4010 | 683 logerrx("%s: %s: WEXITSTATUS %d", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
684 __func__, argv[0], WEXITSTATUS(status)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
685 } else if (WIFSIGNALED(status)) |
| 4010 | 686 logerrx("%s: %s: %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
687 __func__, argv[0], strsignal(WTERMSIG(status))); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
688 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
689 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
690 return WEXITSTATUS(status); |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
691 } |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
692 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
693 int |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
694 script_dump(const char *env, size_t len) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
695 { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
696 const char *ep = env + len; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
697 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
698 if (len == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
699 return 0; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
700 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
701 if (*(ep - 1) != '\0') { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
702 errno = EINVAL; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
703 return -1; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
704 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
705 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
706 for (; env < ep; env += strlen(env) + 1) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
707 if (strncmp(env, "new_", 4) == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
708 env += 4; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
709 printf("%s\n", env); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
710 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
711 return 0; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
712 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
713 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
714 int |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
715 script_runreason(const struct interface *ifp, const char *reason) |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
716 { |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
717 struct dhcpcd_ctx *ctx = ifp->ctx; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
718 char *argv[2]; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
719 int status = 0; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
720 struct fd_list *fd; |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
721 long buflen; |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
722 |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
723 if (ctx->script == NULL && |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
724 TAILQ_FIRST(&ifp->ctx->control_fds) == NULL) |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
725 return 0; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
726 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
727 /* Make our env */ |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
728 if ((buflen = make_env(ifp->ctx, ifp, reason)) == -1) { |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
729 logerr(__func__); |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
730 return -1; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
731 } |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
732 |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
733 if (strncmp(reason, "DUMP", 4) == 0) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
734 return script_dump(ctx->script_buf, (size_t)buflen); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
735 |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
736 if (ctx->script == NULL) |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
737 goto send_listeners; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
738 |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
739 argv[0] = ctx->script; |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
740 argv[1] = NULL; |
| 5494 | 741 logdebugx("%s: executing: %s %s", ifp->name, argv[0], reason); |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
742 |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
743 #ifdef PRIVSEP |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
744 if (ctx->options & DHCPCD_PRIVSEP) { |
|
5255
ee23398a68db
dhcpcd: Move the script file from per interface to global context
Roy Marples <roy@marples.name>
parents:
5227
diff
changeset
|
745 if (ps_root_script(ctx, |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
746 ctx->script_buf, ctx->script_buflen) == -1) |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
747 logerr(__func__); |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
748 goto send_listeners; |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
749 } |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
750 #endif |
|
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
751 |
|
5280
a986083da0ba
Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents:
5271
diff
changeset
|
752 script_run(ctx, argv); |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
753 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
754 send_listeners: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
755 /* Send to our listeners */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
756 status = 0; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4424
diff
changeset
|
757 TAILQ_FOREACH(fd, &ctx->control_fds, next) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
758 if (!(fd->flags & FD_LISTEN)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
759 continue; |
|
5328
ea68407e5ac8
privsep: Implement a resource limited sandbox
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
760 if (control_queue(fd, ctx->script_buf, ctx->script_buflen)== -1) |
| 4010 | 761 logerr("%s: control_queue", __func__); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
762 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
763 status = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
764 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
765 |
|
4994
af9de589341f
Linux: setup mounts in chroot
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
766 return status; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
767 } |
