~jm-leddy/ubuntu/precise/ubiquity/lp929092

« back to all changes in this revision

Viewing changes to d-i/source/netcfg/dhcp.c

  • Committer: Bazaar Package Importer
  • Author(s): Evan Dandrea, Evan Dandrea, Colin Watson
  • Date: 2009-11-13 10:41:42 UTC
  • mfrom: (281.1.2 karmic-updates)
  • Revision ID: james.westby@ubuntu.com-20091113104142-ghwoqmn0bko416c2
Tags: 2.1.0
[ Evan Dandrea ]
* Run X with -nolisten tcp (LP: #462394).
* Make sure we never try to install onto the live filesystem.
* Only print the filenames being blacklisted if in debug mode.
* Provide human readable sizes in the partitions-too-small warning
  (LP: #298974).
* Mark the "Installation Complete" window as always on top
  (LP: #462178).
* Fixes from Pychecker for the KDE frontend (kde_ui):
  - Don't import datetime or math.  The timezone code is in a separate
    module now.
  - Remove some unused variables.
  - Don't assign to a variable that's going to be immediately discarded.
* Signal to GTK+ when using a right-to-left language, so that it
  composes the interface from right to left (LP: #222845).
* Signal to the slideshow when the installer is using a right-to-left
  language (LP: #446989).
* Set SUDO_UID and SUDO_GID in ubiquity-dm so ubiquity knows what user
  to drop privileges to (LP: #422254).
* Do not try to configure networking in oem-config (LP: #471498).
* Make migration-assistant import failures non-fatal to the overall
  install.
* pkgsel now provides a debconf question to avoid warning the end user
  when the language packs could not be installed (LP: #471553).
* Make sure a device exists as part of the grub target device
  validation.
* Allow the user to retry grub installation with a different device on
  failure.
* Automatic update of included source packages: apt-setup
  1:0.42ubuntu1, choose-mirror 2.29ubuntu2, clock-setup 0.100ubuntu1,
  debian-installer-utils 1.71ubuntu1, grub-installer 1.47ubuntu1, hw-
  detect 1.73ubuntu1, netcfg 1.51ubuntu1, partman-base 135ubuntu1,
  tzsetup 1:0.26ubuntu1, user-setup 1.28ubuntu1.

[ Colin Watson ]
* Add a debian/rules target to run pychecker. I've fixed several warnings,
  but there are still several left so this is not yet enabled by default.
* Fix debconf frontend:
  - Start oem-config on stopping rc, as well as when starting display
    managers.
  - Add some missing imports (ubiquity.frontend.base.Controller,
    ubiquity.plugin.Plugin, ubiquity.i18n, signal,
    ubiquity.components.install).
  - If there's a containing debconf frontend, talk to it rather than using
    debconf-communicator.
  - Set a controller in the language plugin.
  - Use spaces rather than ${!TAB} in localechooser when using the debconf
    frontend, since debconf doesn't support the latter yet.
  - Don't handle user-setup preseeding for the debconf frontend.
  - Remove unused progress_position handling.
  - Fix exception names in ubi-network and ubi-tasks.
* Require Python 2.5, so we can now use hashlib rather than md5 and avoid
  a slew of warnings.
* Add an intro message noting that we're alpha again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#define DHCP_OPTION_LEN 1236 /* pump 0.8.24 defines a max option size of 57,
25
25
                                dhcp 2.0pl5 uses 1222, dhcp3 3.0.6 uses 1236 */
26
 
#define DHCLIENT_REQUEST_DEFAULTS \
27
 
  "subnet-mask, broadcast-address, time-offset, routers, domain-name, \
28
 
   domain-name-servers, host-name"
29
 
#define DHCLIENT_REQUEST_EXTRAS "ntp-servers"
 
26
 
 
27
const char* dhclient_request_options_dhclient[] = { "subnet-mask",
 
28
                                                    "broadcast-address",
 
29
                                                    "time-offset",
 
30
                                                    "routers",
 
31
                                                    "domain-name",
 
32
                                                    "domain-name-servers",
 
33
                                                    "host-name",
 
34
                                                    "ntp-servers", /* extra */
 
35
                                                    NULL };
 
36
 
 
37
const char* dhclient_request_options_udhcpc[] = { "subnet",
 
38
                                                  "broadcast",
 
39
                                                  "router",
 
40
                                                  "domain",
 
41
                                                  "namesrv",
 
42
                                                  "hostname",
 
43
                                                  "ntpsrv", /* extra */
 
44
                                                  NULL };
30
45
 
31
46
static int dhcp_exit_status = 1;
32
47
static pid_t dhcp_pid = -1;
57
72
        }
58
73
        fclose(fp);
59
74
    }
60
 
    
61
 
#if 0
62
 
    if ((fp = file_open(RESOLV_FILE, "a"))) {
63
 
        fclose(fp);
64
 
    }
65
 
#endif
66
75
}
67
76
 
68
77
/* Returns 1 if no default route is available */
112
121
int start_dhcp_client (struct debconfclient *client, char* dhostname)
113
122
{
114
123
    FILE *dc = NULL;
115
 
    enum { DHCLIENT, DHCLIENT3, PUMP } dhcp_client;
 
124
    const char **ptr;
 
125
    char **arguments;
 
126
    int options_count;
 
127
    enum { DHCLIENT, DHCLIENT3, PUMP, UDHCPC } dhcp_client;
116
128
    
117
129
    if (access("/var/lib/dhcp3", F_OK) == 0)
118
130
        dhcp_client = DHCLIENT3;
120
132
        dhcp_client = DHCLIENT;
121
133
    else if (access("/sbin/pump", F_OK) == 0)
122
134
        dhcp_client = PUMP;
 
135
    else if (access("/sbin/udhcpc", F_OK) == 0)
 
136
        dhcp_client = UDHCPC;
123
137
    else {
124
138
        debconf_input(client, "critical", "netcfg/no_dhcp_client");
125
139
        debconf_go(client);
142
156
            
143
157
        case DHCLIENT:
144
158
            /* First, set up dhclient.conf */
145
 
            
146
159
            if ((dc = file_open(DHCLIENT_CONF, "w"))) {
147
 
                fprintf(dc, "send dhcp-class-identifier \"d-i\";\n" );
148
 
                fprintf(dc, "request " DHCLIENT_REQUEST_DEFAULTS", " \
149
 
                                       DHCLIENT_REQUEST_EXTRAS";\n" );
 
160
                fprintf(dc, "send dhcp-class-identifier \"d-i\";\n");
 
161
                fprintf(dc, "request ");
 
162
 
 
163
                for (ptr = dhclient_request_options_dhclient; *ptr; ptr++) {
 
164
                    fprintf(dc, *ptr);
 
165
 
 
166
                    /* look ahead to see if it is the last entry */
 
167
                    if (*(ptr + 1))
 
168
                        fprintf(dc, ", ");
 
169
                    else
 
170
                        fprintf(dc, ";\n");
 
171
                }
 
172
 
150
173
                if (dhostname) {
151
174
                    fprintf(dc, "send host-name \"%s\";\n", dhostname);
152
175
                }
161
184
            
162
185
            if ((dc = file_open(DHCLIENT3_CONF, "w"))) {
163
186
                fprintf(dc, "send vendor-class-identifier \"d-i\";\n" );
164
 
                fprintf(dc, "request " DHCLIENT_REQUEST_DEFAULTS", " \
165
 
                                       DHCLIENT_REQUEST_EXTRAS";\n" );
 
187
                fprintf(dc, "request ");
 
188
 
 
189
                for (ptr = dhclient_request_options_dhclient; *ptr; ptr++) {
 
190
                    fprintf(dc, *ptr);
 
191
 
 
192
                    /* look ahead to see if it is the last entry */
 
193
                    if (*(ptr + 1))
 
194
                        fprintf(dc, ", ");
 
195
                    else
 
196
                        fprintf(dc, ";\n");
 
197
                }
 
198
 
166
199
                if (dhostname) {
167
200
                    fprintf(dc, "send host-name \"%s\";\n", dhostname);
168
201
                }
171
204
            
172
205
            execlp("dhclient", "dhclient", "-1", interface, NULL);
173
206
            break;
 
207
 
 
208
        case UDHCPC:
 
209
            /* figure how many options we have */
 
210
            options_count = 0;
 
211
            for (ptr = dhclient_request_options_udhcpc; *ptr; ptr++)
 
212
                options_count++;
 
213
 
 
214
            /* alloc the required memory for arguments:
 
215
               double of number of options since we need -O for each
 
216
               one plus 5 fixed ones plus 2 that are optional
 
217
               depending on hostname being set or not. */
 
218
            arguments = malloc((options_count * 2 + 8) * sizeof(char **));
 
219
 
 
220
            /* set the command options */
 
221
            options_count = 0;
 
222
            arguments[options_count++] = "udhcpc";
 
223
            arguments[options_count++] = "-i";
 
224
            arguments[options_count++] = interface;
 
225
            arguments[options_count++] = "-V";
 
226
            arguments[options_count++] = "d-i";
 
227
            for (ptr = dhclient_request_options_udhcpc; *ptr; ptr++) {
 
228
                arguments[options_count++] = "-O";
 
229
                arguments[options_count++] = *ptr;
 
230
            }
 
231
 
 
232
            if (dhostname) {
 
233
                arguments[options_count++] = "-H";
 
234
                arguments[options_count++] = dhostname;
 
235
            }
 
236
 
 
237
            arguments[options_count] = NULL;
 
238
 
 
239
            execvp("udhcpc", arguments);
 
240
            free(arguments);
 
241
            break;
174
242
        }
175
243
        if (errno != 0)
176
244
            di_error("Could not exec dhcp client: %s", strerror(errno));