mds/net-misc/dhcp/files/dhcp-4.0.1-dhclient-stdin-conf.patch
2009-07-07 09:58:13 +00:00

115 lines
2.9 KiB
Diff

diff -uNr dhcp-4.0.1.ORIG/client/clparse.c dhcp-4.0.1/client/clparse.c
--- dhcp-4.0.1.ORIG/client/clparse.c 2009-03-30 13:54:47.000000000 +0100
+++ dhcp-4.0.1/client/clparse.c 2009-03-30 13:58:02.000000000 +0100
@@ -174,6 +174,10 @@
#endif
}
+ /* Read any extra configuration from stdin */
+ read_client_conf_stdin ((struct interface_info *)0,
+ &top_level_config);
+
/* Set up state and config structures for clients that don't
have per-interface configuration statements. */
config = (struct client_config *)0;
@@ -203,23 +207,13 @@
return status;
}
-int read_client_conf_file (const char *name, struct interface_info *ip,
+int read_client_conf_actual (struct parse *cfile, struct interface_info *ip,
struct client_config *client)
{
- int file;
- struct parse *cfile;
const char *val;
int token;
isc_result_t status;
- if ((file = open (name, O_RDONLY)) < 0)
- return uerr2isc (errno);
-
- cfile = NULL;
- status = new_parse(&cfile, file, NULL, 0, path_dhclient_conf, 0);
- if (status != ISC_R_SUCCESS || cfile == NULL)
- return status;
-
do {
token = peek_token (&val, (unsigned *)0, cfile);
if (token == END_OF_FILE)
@@ -230,10 +224,74 @@
status = (cfile -> warnings_occurred
? ISC_R_BADPARSE
: ISC_R_SUCCESS);
+ return status;
+}
+
+int read_client_conf_file (const char *name, struct interface_info *ip,
+ struct client_config *client)
+{
+ int file;
+ struct parse *cfile;
+ isc_result_t status;
+
+ if ((file = open (name, O_RDONLY)) < 0)
+ return uerr2isc (errno);
+
+ cfile = (struct parse *)0;
+ new_parse (&cfile, file, (char *)0, 0, path_dhclient_conf, 0);
+ status = read_client_conf_actual(cfile, ip, client);
end_parse (&cfile);
return status;
}
+int read_client_conf_stdin (struct interface_info *ip,
+ struct client_config *client)
+{
+ int file;
+ char *buffer = NULL, *p;
+ unsigned buflen, len = 0;
+ struct parse *cfile;
+ size_t bytes;
+ isc_result_t status;
+
+ file = fileno(stdin);
+ if (isatty (file))
+ return ISC_R_NOTFOUND;
+ if (fcntl (file, F_SETFL, O_NONBLOCK) < 0)
+ log_fatal ("could not set stdin to non blocking!");
+
+ buflen = BUFSIZ;
+ buffer = malloc (BUFSIZ + 1);
+ p = buffer;
+ do {
+ bytes = read (file, p, BUFSIZ);
+ if (bytes == 0)
+ break;
+ if (bytes == -1)
+ log_fatal ("failed to read stdin!");
+ if (bytes >= BUFSIZ) {
+ buflen += BUFSIZ;
+ len += BUFSIZ;
+ buffer = realloc (buffer, buflen + 1);
+ if (!buffer)
+ log_fatal ("not enough buffer to read stdin!");
+ p = buffer + len;
+ } else {
+ len += bytes;
+ break;
+ }
+ } while(1);
+ buffer[len] = '\0';
+
+ cfile = (struct parse *)0;
+ status = new_parse (&cfile, -1, buffer, len, "stdin", 0);
+ if (status == ISC_R_SUCCESS) {
+ status = read_client_conf_actual (cfile, ip, client);
+ end_parse (&cfile);
+ }
+ free(buffer);
+ return status;
+}
/* lease-file :== client-lease-statements END_OF_FILE
client-lease-statements :== <nil>