dhcp-agent-commits Mailing List for dhcp-agent (Page 22)
Status: Alpha
Brought to you by:
actmodern
You can subscribe to this list here.
2002 |
Jan
|
Feb
(33) |
Mar
|
Apr
|
May
(19) |
Jun
(61) |
Jul
(12) |
Aug
|
Sep
(5) |
Oct
(31) |
Nov
(24) |
Dec
(56) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(9) |
Feb
|
Mar
(16) |
Apr
(4) |
May
(68) |
Jun
(70) |
Jul
(100) |
Aug
(54) |
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(7) |
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(4) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(8) |
Oct
(5) |
Nov
(6) |
Dec
(4) |
2008 |
Jan
(9) |
Feb
(20) |
Mar
(32) |
Apr
(18) |
May
(19) |
Jun
(12) |
Jul
(23) |
Aug
(7) |
Sep
(15) |
Oct
(22) |
Nov
(50) |
Dec
(68) |
2009 |
Jan
(63) |
Feb
(23) |
Mar
(43) |
Apr
(50) |
May
(110) |
Jun
(103) |
Jul
(71) |
Aug
(26) |
Sep
(16) |
Oct
(31) |
Nov
(8) |
Dec
(13) |
2010 |
Jan
(6) |
Feb
(6) |
Mar
(36) |
Apr
(57) |
May
(67) |
Jun
(70) |
Jul
(44) |
Aug
(46) |
Sep
(27) |
Oct
(2) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
From: <act...@us...> - 2002-12-31 10:31:08
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv20100 Modified Files: dhcp-client.c Log Message: fixed erroneous messages Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-client.c 29 Dec 2002 05:17:49 -0000 1.19 --- dhcp-client.c 31 Dec 2002 10:30:59 -0000 1.20 *************** *** 296,300 **** if(file_get_pid(interface, &pid)) { ERROR_MESSAGE ! ("could not get PID for client running on interface %s. Maybe it's not running?"); return; } --- 296,300 ---- if(file_get_pid(interface, &pid)) { ERROR_MESSAGE ! ("could not get PID for client running on interface %s. Maybe it's not running?", interface); return; } *************** *** 464,468 **** if(file_create_pid(interface)) { ! ERROR_MESSAGE("could not create PID file for interface: %s"); client_states[STATE_DO_SHUTDOWN] (NULL); } --- 464,468 ---- if(file_create_pid(interface)) { ! ERROR_MESSAGE("could not create PID file for interface: %s", interface); client_states[STATE_DO_SHUTDOWN] (NULL); } |
From: <act...@us...> - 2002-12-30 21:54:40
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv28639 Modified Files: dhcp-client-states.c Log Message: more fixes to checks Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** dhcp-client-states.c 30 Dec 2002 20:20:54 -0000 1.22 --- dhcp-client-states.c 30 Dec 2002 21:54:37 -0000 1.23 *************** *** 229,239 **** /* is rawnet happy with the packet? */ ! if(((!rawnet_is_valid(dc->rawnet)) || /* is it a DHCP packet? */ ! (dc->rawnet->type != RAWNET_DHCP) || /* does the XID match up? */ ! (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid) || /* is it from a server? */ --- 229,239 ---- /* is rawnet happy with the packet? */ ! if(((!rawnet_is_valid(dc->rawnet)) "&& /* is it a DHCP packet? */ ! (dc->rawnet->type != RAWNET_DHCP) && /* does the XID match up? */ ! (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid) && /* is it from a server? */ |
From: <act...@us...> - 2002-12-30 20:20:58
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11986 Modified Files: dhcp-client-states.c Log Message: fixed bug in client_check_request Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** dhcp-client-states.c 29 Dec 2002 05:09:55 -0000 1.21 --- dhcp-client-states.c 30 Dec 2002 20:20:54 -0000 1.22 *************** *** 271,277 **** dhcp_client_control_t *dc = arg; ! if(client_check_dhcp(dc) || ! dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM) || ! dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPNAK_TM)) return 1; else --- 271,277 ---- dhcp_client_control_t *dc = arg; ! if(client_check_dhcp(dc) && ! (dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPACK_TM) || ! dhcp_is_type(dc->rawnet->dhcp_p, DHCP_DHCPNAK_TM))) return 1; else |
From: <act...@us...> - 2002-12-30 06:29:22
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11100/src Modified Files: dhcp-stringbuffer.c Log Message: more stringbuffer fun Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-stringbuffer.c 30 Dec 2002 00:45:03 -0000 1.10 --- dhcp-stringbuffer.c 30 Dec 2002 06:29:19 -0000 1.11 *************** *** 193,205 **** } - /* FIXME: use memcpy() */ /* remove whitespace (including tabs) */ stringbuffer_t *stringbuffer_trim_whitespace(stringbuffer_t *sb) { - char *ptr, *curptr; - char *end, *begin; char *newbuf; ! int len; ! int i; if(sb->len == 0) /* empty string. */ --- 193,202 ---- } /* remove whitespace (including tabs) */ stringbuffer_t *stringbuffer_trim_whitespace(stringbuffer_t *sb) { char *newbuf; ! int new_len; ! int i, j; if(sb->len == 0) /* empty string. */ *************** *** 207,233 **** /* find beginning of string after tabs and whitespaces. */ ! begin = &sb->buf[0]; ! for(i = 0; i < sb->len && (*begin == ' ' || *begin == '\t'); begin++); ! if(*begin != '\0') { /* we do have whitespace in the beginning so find the end. */ ! for(end = &sb->buf[sb->len]; *end == ' ' || *end == '\t'; end--); ! len = sb->len; /* save old length. */ ! /* create a new string */ ! newbuf = allocate_string(len); ! ptr = newbuf; ! for(curptr = begin; curptr != end; curptr++) { ! *ptr = *curptr; ! ptr++; ! } ! *ptr = 0; xfree(sb->buf); sb->buf = newbuf; ! sb->len = strlen(newbuf); ! sb->capacity = len; --- 204,232 ---- /* find beginning of string after tabs and whitespaces. */ ! for(i = 0; i < sb->len && (sb->buf[i] == ' ' || sb->buf[i] == '\t'); i++); ! if(sb->buf[i] != '\0') { /* we do have whitespace in the beginning so find the end. */ ! for(j = (sb->len -1);(sb->buf[j] == ' ' || sb->buf[j] == '\t'); j--); ! /* increment j since it's on the non whitespace character. */ ! j++; ! /* create a new string. */ ! new_len = j - i; ! newbuf = allocate_string(new_len); ! ! /* copy in. */ ! memcpy(newbuf, &sb->buf[i], (j - i) * sizeof(char)); ! newbuf[new_len] = 0; + /* free up old. */ xfree(sb->buf); + + /* set new. */ sb->buf = newbuf; ! sb->len = new_len; ! sb->capacity = new_len; *************** *** 246,254 **** { char *ptr, *ptrend = NULL; ptr = sb->buf; ! while((ptr = strchr(ptr, '\n')) != NULL) { ! ptrend = ptr; ! ptr++; } --- 245,255 ---- { char *ptr, *ptrend = NULL; + int i; ptr = sb->buf; ! for(i = 0;i < sb->len;i++) { ! ! if(ptr[i] == c) ! ptrend = &ptr[i]; } *************** *** 298,307 **** void stringbuffer_replace_c(stringbuffer_t *sb, char c, char replace) { ! char *ptr; ! for(ptr = sb->buf; *ptr != 0; ptr++) { ! if(*ptr == c) ! *ptr = replace; } } --- 299,310 ---- void stringbuffer_replace_c(stringbuffer_t *sb, char c, char replace) { ! int i; ! for(i = 0;i < sb->len;i++) { ! if(sb->buf[i] == c) ! sb->buf[i] = replace; } + + return; } *************** *** 372,376 **** stringbuffer_t *aligned_string; int len, i; - stringbuffer_zap_newline(sb); --- 375,378 ---- |
From: <act...@us...> - 2002-12-30 06:29:22
|
Update of /cvsroot/dhcp-agent/dhcp-agent/tests In directory sc8-pr-cvs1:/tmp/cvs-serv11100/tests Modified Files: .cvsignore tests-stringbuffer.c Log Message: more stringbuffer fun Index: .cvsignore =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/tests/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 30 Dec 2002 00:47:52 -0000 1.1 --- .cvsignore 30 Dec 2002 06:29:20 -0000 1.2 *************** *** 2,4 **** stamp-h1 .deps .libs ! test-stringbuffer --- 2,4 ---- stamp-h1 .deps .libs ! stringbuffertest Index: tests-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/tests/tests-stringbuffer.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tests-stringbuffer.c 30 Dec 2002 00:47:52 -0000 1.1 --- tests-stringbuffer.c 30 Dec 2002 06:29:20 -0000 1.2 *************** *** 391,402 **** } /* array of test routines. */ static test_table tests[] = { ! { "create/destroy", test_create_destroy }, ! { "append/clear", test_append_clear }, ! { "aprintf/clear", test_aprintf_clear }, ! { "replace_c", test_replace_c }, ! { "replace", test_replace }, }; --- 391,463 ---- } + static int test_trim_whitespace(const char *name) + { + stringbuffer_t *sb; + + sb = stringbuffer_create(); + + /* test with leading and trailing white space. */ + + stringbuffer_aprintf(sb, " \t%s\t ", BAR_STRING); + stringbuffer_trim_whitespace(sb); + + if(test_util_string_is_set(sb, BAR_STRING, name)) + return 1; + + stringbuffer_clear(sb); + + /* test with just leading whitespace. */ + + stringbuffer_aprintf(sb, " \t%s", BAR_STRING); + stringbuffer_trim_whitespace(sb); + + if(test_util_string_is_set(sb, BAR_STRING, name)) + return 1; + + stringbuffer_clear(sb); + + /* test with just trailing whitespace. */ + + stringbuffer_aprintf(sb, "%s\t ", BAR_STRING); + stringbuffer_trim_whitespace(sb); + + if(test_util_string_is_set(sb, BAR_STRING, name)) + return 1; + + stringbuffer_clear(sb); + + /* test with only whitespace. */ + + stringbuffer_aprintf(sb, " \t "); + stringbuffer_trim_whitespace(sb); + + if(test_util_string_is_set(sb, "", name)) + return 1; + + stringbuffer_clear(sb); + + /* test with nothing :-). */ + + stringbuffer_aprintf(sb, ""); + stringbuffer_trim_whitespace(sb); + + if(test_util_string_is_set(sb, "", name)) + return 1; + + stringbuffer_clear(sb); + + stringbuffer_destroy(sb); + return 0; + } + /* array of test routines. */ static test_table tests[] = { ! { "create/destroy", test_create_destroy }, ! { "append/clear", test_append_clear }, ! { "aprintf/clear", test_aprintf_clear }, ! { "replace_c", test_replace_c }, ! { "replace", test_replace }, ! { "trim_whitespace", test_trim_whitespace }, }; |
From: <act...@us...> - 2002-12-30 03:41:55
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv15845 Modified Files: dhcp-client-cache.c dhcp-tokenizer.c Log Message: parser now properly handles escapes; cache now escapes Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client-cache.c 23 Dec 2002 01:21:52 -0000 1.11 --- dhcp-client-cache.c 30 Dec 2002 03:41:51 -0000 1.12 *************** *** 322,326 **** --- 322,328 ---- char *val; dhcp_option_t *opt; + stringbuffer_t *sb; + sb = stringbuffer_create(); name = get_fname_tmp(cc); fp = file_create_and_truncate_safe(name, "a"); *************** *** 353,360 **** } ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, val, dhcp_option_printable_string_get(opt->tag)); xfree(val); } fclose(fp); return 0; --- 355,368 ---- } ! stringbuffer_clear(sb); ! stringbuffer_append(sb, val); ! stringbuffer_replace(sb, "\\", "\\\\"); ! stringbuffer_replace(sb, "\"", "\\\""); ! ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, stringbuffer_getstring(sb), dhcp_option_printable_string_get(opt->tag)); xfree(val); } + stringbuffer_destroy(sb); fclose(fp); return 0; Index: dhcp-tokenizer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-tokenizer.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-tokenizer.c 23 Dec 2002 00:51:25 -0000 1.2 --- dhcp-tokenizer.c 30 Dec 2002 03:41:52 -0000 1.3 *************** *** 82,86 **** { if(c == '\\') ! return 0; if(isalnum(c) || ispunct(c)) --- 82,86 ---- { if(c == '\\') ! return 1; if(isalnum(c) || ispunct(c)) *************** *** 147,166 **** case '\\': - c2 = getc(tokenizer->fp); - if(c2 != '\\') { ! ungetc(c2, tokenizer->fp); if(tokenize_gobble_line(tokenizer) != TOKEN_NEWLINE) return TOKEN_ERROR; else break; ! } else ! ungetc(c2, tokenizer->fp); ! /* otherwise put it back and fall through. */ ! ungetc(c, tokenizer->fp); - /* fall through */ default: if(is_valid_string_char(c) || c == ' ' || c == '\t') --- 147,165 ---- case '\\': ! c2 = getc(tokenizer->fp); + if(c2 == '\n' || c2 == '\r' || c2 == ' ' || c2 == '\t') { if(tokenize_gobble_line(tokenizer) != TOKEN_NEWLINE) return TOKEN_ERROR; else break; ! } ! /* anything else means insert c2 without handling it specially*/ ! ! stringbuffer_append_c(tokenizer->data_buff, (char)c2); ! break; default: if(is_valid_string_char(c) || c == ' ' || c == '\t') *************** *** 199,214 **** case '\\': c2 = getc(tokenizer->fp); - if(c2 != '\\') { ! ungetc(c2, tokenizer->fp); - if(tokenize_gobble_line(tokenizer) != TOKEN_NEWLINE) - return TOKEN_ERROR; - else - break; - } else ungetc(c2, tokenizer->fp); - /* fall through. */ default: --- 198,212 ---- case '\\': c2 = getc(tokenizer->fp); ! if(c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') { ungetc(c2, tokenizer->fp); + return TOKEN_STRING; + } else { + + stringbuffer_append_c(tokenizer->data_buff, (char)c2); + break; + } default: |
From: <act...@us...> - 2002-12-30 00:48:19
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv13278 Modified Files: UPGRADING Log Message: added some upgrade notes Index: UPGRADING =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/UPGRADING,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** UPGRADING 29 Oct 2002 17:11:02 -0000 1.1.1.1 --- UPGRADING 30 Dec 2002 00:48:16 -0000 1.2 *************** *** 2,6 **** ------------------ ! From dhcp-0.36 -------------- --- 2,34 ---- ------------------ ! Generally speaking "upgrading" at this point in the suite's ! development stage isn't recommended. Get rid of the old ! installation with make uninstall and reinstall from the new one. ! ! From dhcp-agent-0.37 ! -------------------- ! ! A lot has changed. Actually enough that you should probably do the following: ! ! If you already have a source tarball of the distribution you can ! configure it with the same prefix (or the default one) and do a ! make uninstall. You will also need to delete /etc/dhcpclient ! ! If you don't have a source tarball but installed everything in ! /usr/local you can do the following: ! ! rm -f /usr/local/bin/dhcpclient /usr/local/bin/dhcpsniff ! rm -f /usr/local/man/man1/dhcpclient.1 /usr/local/man/man1/dhcpsniff.1 ! ! Also delete the /etc/dhcpclient directory since it is no longer used. ! ! New binaries have a hypen in between dhcp and their name. So: ! ! dhcpclient is dhcp-client ! dhcpsniff is dhcp-sniff ! ! The same applies to the man pages. ! ! From dhcp-agent-0.36 -------------- |
From: <act...@us...> - 2002-12-30 00:47:54
|
Update of /cvsroot/dhcp-agent/dhcp-agent/tests In directory sc8-pr-cvs1:/tmp/cvs-serv13118/tests Added Files: .cvsignore Makefile.am tests-stringbuffer.c tests.h Log Message: added tests --- NEW FILE: .cvsignore --- Makefile.in Makefile stamp-h1 .deps .libs test-stringbuffer --- NEW FILE: Makefile.am --- # $Header: /cvsroot/dhcp-agent/dhcp-agent/tests/Makefile.am,v 1.1 2002/12/30 00:47:52 actmodern Exp $ # # Tests Makefile.am AUTOMAKE_OPTIONS = foreign AM_CFLAGS = -Wall -Werror check_PROGRAMS = stringbuffertest INCLUDES = -I../src stringbuffertest_SOURCES = tests-stringbuffer.c tests.h LDADD = ../src/libdhcputil.la TESTS = stringbuffertest --- NEW FILE: tests-stringbuffer.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/tests/tests-stringbuffer.c,v 1.1 2002/12/30 00:47:52 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * stringbuffer test code. we need more tests too :) * */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "tests.h" #define TEST_NAME "stringbuffer" /* test strings. */ /* two basic strings for appending. */ #define BAR_STRING "This is my source code, there are many others like it, but this one is mine." #define FOO_STRING "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890" /* the same strings appended 5 times and appended 10 times */ #define FOO_STRING_X10 "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890" #define FOO_STRING_X5 "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890" #define BAR_STRING_X5 "This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine." #define BAR_STRING_X10 "This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine.This is my source code, there are many others like it, but this one is mine." /* the same strings appended 5 and 10 times only with a " : " in between to test aprintf capability */ #define BAR_STRING_X5_PRINTF "This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : " #define BAR_STRING_X10_PRINTF "This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : This is my source code, there are many others like it, but this one is mine. : " #define FOO_STRING_X5_PRINTF "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : " #define FOO_STRING_X10_PRINTF "abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : abcdefghijklmnopqrstuvwxABCDEFGHIKLMNOPQRSTUVWXZ!@#$%^&*()_+1234567890 : " /* two strings to replace. */ #define REPLACE_FOO_1 "foo bar foo bar foo bar foo bar foo bar" #define REPLACE_FOO_2 "foo foo foo foo foo foo foo foo foo foo" #define REPLACE_BAR_1 "bar foo bar foo bar foo bar foo bar foo" #define REPLACE_BAR_2 "bar bar bar bar bar bar bar bar bar bar" #define REPLACE_FOO "foo" #define REPLACE_BAR "bar" /* utility routines. */ static int test_util_string_is_set(stringbuffer_t *sb, const char *string, const char *name) { const char *ptr; int len; /* see if it returns properly. */ ptr = stringbuffer_getstring(sb); if(strcmp(ptr, string)) { TEST_ERROR(name, "string did not match properly : string comparison wrong"); return 1; } len = stringbuffer_getlen(sb); if(len != strlen(ptr)) { TEST_ERROR(name, "string did not match properly : string length wrong"); return 1; } return 0; } /* test routines. */ static int test_create_destroy(const char *name) { stringbuffer_t *sb; /* just create and destroy. we cannot catch an error here * but we may crash if something is up. */ sb = stringbuffer_create(); stringbuffer_destroy(sb); return 0; } static int test_append_clear(const char *name) { stringbuffer_t *sb; int i; sb = stringbuffer_create(); /* * * * * * * * * * * * * * * * * Append BAR_STRING and test. * * * * * * * * * * * * * * * * */ /* append bar string. */ stringbuffer_append(sb, BAR_STRING); /* check. */ if(test_util_string_is_set(sb, BAR_STRING, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; stringbuffer_clear(sb); for(i = 0;i < 5;i ++) /* do 5 X. */ stringbuffer_append(sb, BAR_STRING); if(test_util_string_is_set(sb, BAR_STRING_X5, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; for(i = 0;i < 10;i ++) /* do 10 X. */ stringbuffer_append(sb, BAR_STRING); if(test_util_string_is_set(sb, BAR_STRING_X10, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; /* * * * * * * * * * * * * * * * * Append FOO_STRING and test. * * * * * * * * * * * * * * * * */ /* append bar string. */ stringbuffer_append(sb, FOO_STRING); /* check. */ if(test_util_string_is_set(sb, FOO_STRING, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; stringbuffer_clear(sb); for(i = 0;i < 5;i ++) /* do 5 X. */ stringbuffer_append(sb, FOO_STRING); if(test_util_string_is_set(sb, FOO_STRING_X5, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; for(i = 0;i < 10;i ++) /* do 10 X. */ stringbuffer_append(sb, FOO_STRING); if(test_util_string_is_set(sb, FOO_STRING_X10, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; /* done. */ stringbuffer_destroy(sb); return 0; } static int test_aprintf_clear(const char *name) { stringbuffer_t *sb; int i; sb = stringbuffer_create(); /* * * * * * * * * * * * * * * * * Append BAR_STRING and test. * * * * * * * * * * * * * * * * */ /* append bar string. */ stringbuffer_aprintf(sb, "%s", BAR_STRING); /* check. */ if(test_util_string_is_set(sb, BAR_STRING, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; stringbuffer_clear(sb); for(i = 0;i < 5;i ++) /* do 5 X. */ stringbuffer_aprintf(sb, "%s : ", BAR_STRING); if(test_util_string_is_set(sb, BAR_STRING_X5_PRINTF, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; for(i = 0;i < 10;i ++) /* do 10 X. */ stringbuffer_aprintf(sb, "%s : ", BAR_STRING); if(test_util_string_is_set(sb, BAR_STRING_X10_PRINTF, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; /* * * * * * * * * * * * * * * * * Append FOO_STRING and test. * * * * * * * * * * * * * * * * */ /* append bar string. */ stringbuffer_append(sb, FOO_STRING); /* check. */ if(test_util_string_is_set(sb, FOO_STRING, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; stringbuffer_clear(sb); for(i = 0;i < 5;i ++) /* do 5 X. */ stringbuffer_aprintf(sb, "%s : ", FOO_STRING); if(test_util_string_is_set(sb, FOO_STRING_X5_PRINTF, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; for(i = 0;i < 10;i ++) /* do 10 X. */ stringbuffer_aprintf(sb, "%s : ", FOO_STRING); if(test_util_string_is_set(sb, FOO_STRING_X10_PRINTF, name)) return 1; stringbuffer_clear(sb); /* check to see if it matches the empty string. */ if(test_util_string_is_set(sb, "", name)) return 1; /* done. */ stringbuffer_destroy(sb); return 0; } static int test_replace_c(const char *name) { stringbuffer_t *sb; sb = stringbuffer_create(); /* * * * * * * * * * * * * * * * * * using replace_c only change * * foo to brr * * * * * * * * * * * * * * * * * */ stringbuffer_append(sb, REPLACE_FOO); stringbuffer_replace_c(sb, 'f', 'b'); stringbuffer_replace_c(sb, 'o', 'r'); if(test_util_string_is_set(sb, "brr", name)) return 1; stringbuffer_destroy(sb); return 0; } static int test_replace(const char *name) { stringbuffer_t *sb; sb = stringbuffer_create(); /* * * * * * * * * * * * * * * * * * replace two simple sequences. * * * * * * * * * * * * * * * * * */ stringbuffer_append(sb, REPLACE_FOO_1); stringbuffer_replace(sb, "bar", "foo"); if(test_util_string_is_set(sb, REPLACE_FOO_2, name)) return 1; stringbuffer_clear(sb); stringbuffer_append(sb, REPLACE_BAR_1); stringbuffer_replace(sb, "foo", "bar"); if(test_util_string_is_set(sb, REPLACE_BAR_2, name)) return 1; stringbuffer_clear(sb); /* * * * * * * * * * * * * * * * * * * * * replace one string with one string * * * * * * * * * * * * * * * * * * * * */ stringbuffer_append(sb, REPLACE_FOO); stringbuffer_replace(sb, REPLACE_FOO, REPLACE_BAR); if(test_util_string_is_set(sb, REPLACE_BAR, name)) return 1; stringbuffer_clear(sb); /* * * * * * * * * * * * * * * * * * * * replace one string with itself. * * * * * * * * * * * * * * * * * * * */ stringbuffer_append(sb, REPLACE_FOO); stringbuffer_replace(sb, REPLACE_FOO, REPLACE_FOO); if(test_util_string_is_set(sb, REPLACE_FOO, name)) return 1; stringbuffer_clear(sb); /* * * * * * * * * * * * * * * * * * * * * * replace two charactes in "foo" to be * * "brr" with replace * * * * * * * * * * * * * * * * * * * * * */ stringbuffer_append(sb, REPLACE_FOO); stringbuffer_replace(sb, "f", "b"); stringbuffer_replace(sb, "o", "r"); if(test_util_string_is_set(sb, "brr", name)) return 1; stringbuffer_clear(sb); /* done. */ stringbuffer_destroy(sb); return 0; } /* array of test routines. */ static test_table tests[] = { { "create/destroy", test_create_destroy }, { "append/clear", test_append_clear }, { "aprintf/clear", test_aprintf_clear }, { "replace_c", test_replace_c }, { "replace", test_replace }, }; /* main: loops. */ int main(int argc, char *argv[]) { DO_TESTS(tests); exit(TESTS_EXIT_SUCCESS); } --- NEW FILE: tests.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/tests/tests.h,v 1.1 2002/12/30 00:47:52 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef TESTS_H #define TESTS_H /* types */ /* test function. */ typedef int (*test_t)(const char *name); typedef struct { const char *name; test_t test_func; } test_table; /* exit values. */ #define TESTS_EXIT_FAILURE 1 #define TESTS_EXIT_SUCCESS 0 #define TESTS_EXIT_IGNORE 77 /* macros. */ #define TEST_ERROR(name, x) { fprintf(stderr, "test error (%s):\n", name); fprintf(stderr, "%s\n", x); } #define TEST_MSG(x) { fprintf(stdout, "%s\n", x); } #define TEST_NELMS(x) (sizeof(x)/sizeof(x[0])) #define DO_TESTS(x) { \ int i; \ for(i = 0;i < TEST_NELMS(x);i++) { \ if(x[i].test_func(x[i].name)) \ exit(TESTS_EXIT_FAILURE); \ } \ } #endif /* TESTS_H */ |
From: <act...@us...> - 2002-12-30 00:47:54
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv13118 Modified Files: configure.ac Makefile.am Log Message: added tests Index: configure.ac =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure.ac,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** configure.ac 19 Dec 2002 18:00:26 -0000 1.1 --- configure.ac 30 Dec 2002 00:47:51 -0000 1.2 *************** *** 165,169 **** AM_CONFIG_HEADER(config.h) ! AC_OUTPUT([Makefile src/Makefile man/Makefile]) echo --- 165,169 ---- AM_CONFIG_HEADER(config.h) ! AC_OUTPUT([Makefile src/Makefile man/Makefile tests/Makefile]) echo Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 19 Dec 2002 17:57:59 -0000 1.2 --- Makefile.am 30 Dec 2002 00:47:51 -0000 1.3 *************** *** 5,9 **** AUTOMAKE_OPTIONS = foreign ! SUBDIRS = src man EXTRA_DIST = CAVEATS LICENSE README THANKS TODO UPGRADING conf --- 5,9 ---- AUTOMAKE_OPTIONS = foreign ! SUBDIRS = src man tests EXTRA_DIST = CAVEATS LICENSE README THANKS TODO UPGRADING conf |
From: <act...@us...> - 2002-12-30 00:45:59
|
Update of /cvsroot/dhcp-agent/dhcp-agent/tests In directory sc8-pr-cvs1:/tmp/cvs-serv12487/tests Log Message: Directory /cvsroot/dhcp-agent/dhcp-agent/tests added to the repository |
From: <act...@us...> - 2002-12-30 00:45:06
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv12261/src Modified Files: Makefile.am dhcp-libutil.h dhcp-stringbuffer.c Log Message: stringbuffer able to do full string replacements Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Makefile.am 22 Dec 2002 08:31:29 -0000 1.12 --- Makefile.am 30 Dec 2002 00:45:03 -0000 1.13 *************** *** 1,3 **** ! # $Header # # Main source Makefile.am --- 1,3 ---- ! # $Header$ # # Main source Makefile.am Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** dhcp-libutil.h 29 Dec 2002 05:31:35 -0000 1.21 --- dhcp-libutil.h 30 Dec 2002 00:45:03 -0000 1.22 *************** *** 217,220 **** --- 217,221 ---- extern void stringbuffer_copy(stringbuffer_t *dest, stringbuffer_t *src); extern void stringbuffer_replace_c(stringbuffer_t *sb, char c, char replace); + extern void stringbuffer_replace(stringbuffer_t *sb, const char *string, const char *replace); extern void stringbuffer_align(stringbuffer_t *sb, int begin, int end); extern void stringbuffer_avprintf_align(stringbuffer_t *sb, int start, int end, const char *fmt, va_list ap); Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-stringbuffer.c 23 Dec 2002 00:51:25 -0000 1.9 --- dhcp-stringbuffer.c 30 Dec 2002 00:45:03 -0000 1.10 *************** *** 306,309 **** --- 306,369 ---- } + /* replace in stringbuffer occurances of c with replace */ + void stringbuffer_replace(stringbuffer_t *sb, const char *string, const char *replace) + { + char *ptr; + int i; + int str_len = strlen(string); + stringbuffer_t *sb_replace; + + if(string[0] == 0) + return; /* nothing to replace. */ + + sb_replace = stringbuffer_create(); + ptr = sb->buf; + + for(i = 0; i < sb->len; i++) { + + if((sb->len - i) < str_len) { + + /* copy in. */ + stringbuffer_copy(sb, sb_replace); + + /* append what's left. */ + stringbuffer_append(sb, &ptr[i]); + + /* free up. */ + stringbuffer_destroy(sb_replace); + + /* we're done. */ + return; + } + + if(ptr[i] == string[0]) { + + /* we know that we have at least enough to complete string. */ + if(!memcmp(&ptr[i], string, str_len)) { + + /* we have a match, replace. */ + stringbuffer_append(sb_replace, replace); + i += (str_len - 1); + continue; + } + } + + stringbuffer_append_c(sb_replace, ptr[i]); + } + + /* we're done: we should only get here if the last string to + be replaced ended the string itself. */ + + /* copy in. */ + stringbuffer_copy(sb, sb_replace); + + /* free up. */ + stringbuffer_destroy(sb_replace); + + /* we're done. */ + return; + + } + /* align a stringbuffer on begin and end columns. */ void stringbuffer_align(stringbuffer_t *sb, int begin, int end) |
From: <act...@us...> - 2002-12-30 00:44:18
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv12071 Modified Files: README Log Message: updated docs Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** README 15 Dec 2002 00:20:00 -0000 1.3 --- README 30 Dec 2002 00:44:15 -0000 1.4 *************** *** 17,22 **** client on a production machine. ! Portability and Caveats ! ----------------------- Although the current distribution is in alpha state, we are --- 17,22 ---- client on a production machine. ! Portability ! ----------- Although the current distribution is in alpha state, we are *************** *** 24,27 **** --- 24,28 ---- successfully on: + Linux 2.4.x (Heavily pillaged Slackware 8.1) Linux 2.2.x (Heavily pillaged Slackware 8.0) FreeBSD-4.6 (Stock installation with dhclient killed) |
From: <act...@us...> - 2002-12-30 00:44:00
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv11984 Modified Files: THANKS Log Message: more thanks Index: THANKS =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/THANKS,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** THANKS 29 Oct 2002 17:11:02 -0000 1.1.1.1 --- THANKS 30 Dec 2002 00:43:57 -0000 1.2 *************** *** 19,20 **** --- 19,22 ---- -- Chris Keelan for some spare PC133 RAM. + + -- Marco Rodrigues for building me a serial console to my sparc5 box. |
From: <act...@us...> - 2002-12-29 05:33:03
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv10081 Modified Files: TODO Log Message: updated TODO Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TODO 19 Dec 2002 17:57:16 -0000 1.4 --- TODO 29 Dec 2002 05:33:01 -0000 1.5 *************** *** 107,112 **** through the table can be shortened by direct indexing. - -- delete resolv in dhcp-util.c since we're not using it. - -- purge_list only accepts one destructor. we need a way of destroying a list with differnet data types. --- 107,110 ---- *************** *** 116,117 **** --- 114,117 ---- -- check for race condition -- even if it is tiny -- in client_wait + + -- make a distinction between SELECT and INIT-REBOOT. right now we have a single client_request_ack routine |
From: <act...@us...> - 2002-12-29 05:31:39
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9833 Modified Files: dhcp-libutil.h dhcp-util.c Log Message: removed resolv() Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-libutil.h 29 Dec 2002 05:09:55 -0000 1.20 --- dhcp-libutil.h 29 Dec 2002 05:31:35 -0000 1.21 *************** *** 184,188 **** extern struct timeval timeval_diff(struct timeval begin, struct timeval end); extern const char *getprogname(void); - extern int resolv(char *address, uint32_t *addr); extern ip_addr_t *string_ip_to_ip_addr(const char *string_ip); extern eth_addr_t *string_eth_addr_to_eth_addr(const char *eth_ip); --- 184,187 ---- Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-util.c 23 Dec 2002 00:51:25 -0000 1.11 --- dhcp-util.c 29 Dec 2002 05:31:36 -0000 1.12 *************** *** 468,497 **** } - /* Returns 0 on success or -1 if error. - * Fills in addr with 32-bit ipv4 address */ - - extern int h_errno; - - int resolv(char *address, uint32_t *addr) - { - struct hostent *host; - - *(addr) = inet_addr(address); - - if(*(addr) == INADDR_NONE) { - - host = gethostbyname(address); - - if(host == NULL) { - ERROR_MESSAGE("rawnet: unable to resolv host: %s", hstrerror(h_errno)); - return -1; - } - - memcpy(&addr, (int *)*&host->h_addr, sizeof(addr)); - } - - return 0; - } - void set_interactive(uint8_t interactive_arg) { --- 468,471 ---- |
From: <act...@us...> - 2002-12-29 05:17:52
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv6637 Modified Files: dhcp-client.c dhcp-files.c Log Message: fixed file_permissions_are() Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-client.c 29 Dec 2002 05:09:55 -0000 1.18 --- dhcp-client.c 29 Dec 2002 05:17:49 -0000 1.19 *************** *** 348,354 **** if(mkdir(work_dir, S_IRWXU) < 0) { FATAL_MESSAGE("cannot create work directory", strerror(errno)); - } else if(!file_permissions_are(work_dir, S_IRWXU)) { - FATAL_MESSAGE("wrong permissions on work directory: %s (use rwx only for owner)", work_dir); } } --- 348,356 ---- if(mkdir(work_dir, S_IRWXU) < 0) { FATAL_MESSAGE("cannot create work directory", strerror(errno)); } + } + + if(!file_permissions_are(work_dir, S_IRWXU)) { + FATAL_MESSAGE("wrong permissions on work directory: %s (use rwx only for owner)", work_dir); } Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-files.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-files.c 23 Dec 2002 01:21:52 -0000 1.7 --- dhcp-files.c 29 Dec 2002 05:17:49 -0000 1.8 *************** *** 116,123 **** ERROR_MESSAGE("could not stat file %s", fname); return -1; ! } else if(st.st_mode != mode) ! return 0; /* mode matches. */ else ! return 1; /* mode does not match. */ } --- 116,125 ---- ERROR_MESSAGE("could not stat file %s", fname); return -1; ! } ! ! if((st.st_mode&(S_IRWXU|S_IRWXG|S_IRWXO)) == mode) ! return 1; /* mode matches. */ else ! return 0; /* mode does not match. */ } |
From: <act...@us...> - 2002-12-29 05:09:58
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv5247 Modified Files: dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-interface.c dhcp-librawnet.h dhcp-libutil.h dhcp-rawnet.c dhcp-sniff.c dhcp-sysconf.c dhcp-timer.c Log Message: fixed problem with forking out and losing data Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client-control.c 27 Dec 2002 02:53:45 -0000 1.12 --- dhcp-client-control.c 29 Dec 2002 05:09:55 -0000 1.13 *************** *** 123,127 **** /* create client control object */ ! dhcp_client_control_t *dhcp_client_control_create(char *interface, int promiscuous) { dhcp_client_control_t *dc; --- 123,127 ---- /* create client control object */ ! dhcp_client_control_t *dhcp_client_control_create(char *interface, int promiscuous, int clear_interface) { dhcp_client_control_t *dc; *************** *** 139,143 **** dc->interface = xstrdup(interface); dc->cache = client_cache_create(dc->interface); - dc->timer = create_timer(); dc->conf = create_client_conf(dc->interface); --- 139,142 ---- *************** *** 173,177 **** if((dc->rawnet = rawnet_create(interface, stringbuffer_getstring(filter), sport, dport, ! promiscuous)) == NULL) { ERROR_MESSAGE("could not acquire rawnet handler."); dhcp_client_control_destroy(dc); --- 172,176 ---- if((dc->rawnet = rawnet_create(interface, stringbuffer_getstring(filter), sport, dport, ! promiscuous, clear_interface)) == NULL) { ERROR_MESSAGE("could not acquire rawnet handler."); dhcp_client_control_destroy(dc); *************** *** 213,216 **** --- 212,220 ---- dc->client_id = create_client_id(interface_addr); dc->discover_offer_retries = 0; /* reset discover offer. */ + + /* create state context */ + + dc->context = dhcp_client_control_context_create(); + return dc; } *************** *** 242,248 **** client_conf_destroy(dc->conf); - if(dc->timer) - destroy_timer(dc->timer); - if(dc->interface) xfree(dc->interface); --- 246,249 ---- *************** *** 257,260 **** --- 258,308 ---- } + /* Context information. This serves one purpose. It lets us + * destroy the control, recreate it and copy back information we + * cannot cache anywhere. */ + + dhcp_client_control_context_t *dhcp_client_control_context_create(void) + { + dhcp_client_control_context_t *context = xcalloc(sizeof(dhcp_client_control_context_t)); + + context->timer = create_timer(); + + return context; + } + + void dhcp_client_control_destroy_context(dhcp_client_control_context_t *context) + { + if(context->timer) + destroy_timer(context->timer); + + xfree(context); + + return; + } + + dhcp_client_control_context_t *dhcp_client_control_copy_context(dhcp_client_control_t *dc) + { + dhcp_client_control_context_t *context; + + context = dhcp_client_control_context_create(); + + /* copy individual fields over. */ + memcpy(&context->sip_addr, &dc->context->sip_addr, IP_ADDR_LEN); + memcpy(&context->shw_addr, &dc->context->shw_addr, ETH_ADDR_LEN); + + /* copy over the timer. */ + context->timer = timer_copy(dc->context->timer); + + return context; + } + + void dhcp_client_control_set_context(dhcp_client_control_t *dc, dhcp_client_control_context_t *context) + { + dhcp_client_control_destroy_context(dc->context); + dc->context = context; + + return; + } + /* Utility routine to bring down interface. we need this because * we have to be explicit about bringing down the interface. We *************** *** 275,279 **** void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr) { ! memcpy(&dc->sip_addr, &ip_addr, sizeof(ip_addr_t)); return; --- 323,327 ---- void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr) { ! memcpy(&dc->context->sip_addr, &ip_addr, sizeof(ip_addr_t)); return; *************** *** 282,286 **** void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr) { ! memcpy(&dc->shw_addr, ð_addr, sizeof(eth_addr_t)); return; --- 330,334 ---- void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr) { ! memcpy(&dc->context->shw_addr, ð_addr, sizeof(eth_addr_t)); return; *************** *** 291,299 **** ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc) { ! return dc->sip_addr; } eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc) { ! return dc->shw_addr; } --- 339,347 ---- ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc) { ! return dc->context->sip_addr; } eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc) { ! return dc->context->shw_addr; } Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-client-states.c 27 Dec 2002 02:53:45 -0000 1.20 --- dhcp-client-states.c 29 Dec 2002 05:09:55 -0000 1.21 *************** *** 309,312 **** --- 309,313 ---- } + /* setup our timers. */ static void client_setup_timers(dhcp_client_control_t *dc) { *************** *** 320,324 **** } ! reinitialize_timer(dc->timer); do_sysconf(timer_options, dc, 0); cache_entry_purge_list(timer_options); --- 321,325 ---- } ! reinitialize_timer(dc->context->timer); do_sysconf(timer_options, dc, 0); cache_entry_purge_list(timer_options); *************** *** 336,340 **** * safe. we shouldn't overflow. */ ! next_timer = timer_peek_next_timer(dc->timer); if(next_timer < RECOMMENDED_MAX_SECS_WAIT) { --- 337,341 ---- * safe. we shouldn't overflow. */ ! next_timer = timer_peek_next_timer(dc->context->timer); if(next_timer < RECOMMENDED_MAX_SECS_WAIT) { *************** *** 550,554 **** options = client_build_release_option_list(dc); ! build_dhcp_release(dc->rawnet, dc->xid, options, dc->sip_addr, dc->shw_addr); if(rawnet_send_packet(dc->rawnet) < 0) { --- 551,555 ---- options = client_build_release_option_list(dc); ! build_dhcp_release(dc->rawnet, dc->xid, options, dc->context->sip_addr, dc->context->shw_addr); if(rawnet_send_packet(dc->rawnet) < 0) { *************** *** 619,627 **** * which is not a timer interrupt. */ ! next_timer = timer_peek_next_timer(dc->timer); time_before = time(NULL); /* now fire off the next timer. */ ! if(timer_set_next(dc->timer)) { FATAL_MESSAGE ("no timers set. we should have at least one for lease expiry sent to us from the server."); --- 620,628 ---- * which is not a timer interrupt. */ ! next_timer = timer_peek_next_timer(dc->context->timer); time_before = time(NULL); /* now fire off the next timer. */ ! if(timer_set_next(dc->context->timer)) { FATAL_MESSAGE ("no timers set. we should have at least one for lease expiry sent to us from the server."); *************** *** 664,668 **** * we at most lag by one second which is not bad. */ ! timer_add_trigger(dc->timer, next_timer, timer_get_current_id(dc->timer)); } } --- 665,669 ---- * we at most lag by one second which is not bad. */ ! timer_add_trigger(dc->context->timer, next_timer, timer_get_current_id(dc->context->timer)); } } *************** *** 719,723 **** options = client_build_renew_option_list(dc); ! build_dhcp_request_unicast(dc->rawnet, dc->xid, dc->secs, options, dc->sip_addr, dc->shw_addr); /* find out how much time we have until the next timer. --- 720,724 ---- options = client_build_renew_option_list(dc); ! build_dhcp_request_unicast(dc->rawnet, dc->xid, dc->secs, options, dc->context->sip_addr, dc->context->shw_addr); /* find out how much time we have until the next timer. *************** *** 804,805 **** --- 805,813 ---- } + /* utility state: call this if reinitializing our client control + * useful when recreating the control (e.g. after a fork). */ + int client_reinitialize(dhcp_client_control_t *dc) + { + client_setup_timers(dc); + return 0; + } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-client.c 23 Dec 2002 01:21:52 -0000 1.17 --- dhcp-client.c 29 Dec 2002 05:09:55 -0000 1.18 *************** *** 89,93 **** /* global vars affecting other code. */ - int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ char *work_dir = CLIENT_WORK_DIR; /* our default working directory */ --- 89,92 ---- *************** *** 192,196 **** static int do_client_dhcp_loop(int only_setup, dhcp_client_control_t *dc, int state) { - unsigned char have_setup = 0; while(1) { --- 191,194 ---- *************** *** 231,235 **** /* if alarm then check for timer type so we can set our state accordingly. */ ! switch (timer_get_current_id(dc->timer)) { case TIMER_RENEW: --- 229,233 ---- /* if alarm then check for timer type so we can set our state accordingly. */ ! switch (timer_get_current_id(dc->context->timer)) { case TIMER_RENEW: *************** *** 258,262 **** * return here. */ ! if(have_setup && only_setup) { return state; } --- 256,260 ---- * return here. */ ! if((state == STATE_WAIT) && only_setup) { return state; } *************** *** 365,368 **** --- 363,367 ---- { dhcp_client_control_t *dc; + dhcp_client_control_context_t *dc_context; int state; *************** *** 399,403 **** setup_interrupt_handlers(); /* setup signal handling */ ! if((dc = dhcp_client_control_create(interface, promiscuous)) == NULL) { ERROR_MESSAGE("encountered a fatal error. I'm exiting."); client_states[STATE_DO_SHUTDOWN] (dc); --- 398,402 ---- setup_interrupt_handlers(); /* setup signal handling */ ! if((dc = dhcp_client_control_create(interface, promiscuous, 1)) == NULL) { ERROR_MESSAGE("encountered a fatal error. I'm exiting."); client_states[STATE_DO_SHUTDOWN] (dc); *************** *** 422,437 **** * ... otherwise ... */ dhcp_client_control_destroy(dc); ! interactive = 0; go_background(work_dir); setup_interrupt_handlers(); /* setup signal handling, * we lose them after we fork in go_background. */ ! if((dc = dhcp_client_control_create(interface, promiscuous)) == NULL) { ERROR_MESSAGE("encountered a fatal error. I'm exiting.", interface); client_states[STATE_DO_SHUTDOWN] (NULL); } if(file_create_pid(interface)) { ERROR_MESSAGE("could not create PID file for interface: %s"); --- 421,464 ---- * ... otherwise ... */ + /* We need to destroy our client control object before + * backgrounding ourselves. Since we close file + * descriptors and enter a different process space. + * + * This accumilates to losing a _lot_ of things: + * + * (1) Any raw network devices, or anything else which + * has a descriptor open is now closed. + * + * (2) Our signal handlers are gone. + * + * (3) Our concept of timers is gone. + * + * The only thing we keep is our state which ought to be + * STATE_WAIT + * + * Unfortunately destroying the control means valuable + * data like timers, and addresses are lost. we can + * however make a copy of this information and just label + * it a context. This way we set it after recreating the + * control + */ + + dc_context = dhcp_client_control_copy_context(dc); dhcp_client_control_destroy(dc); ! set_interactive(0); go_background(work_dir); setup_interrupt_handlers(); /* setup signal handling, * we lose them after we fork in go_background. */ ! /* set clear_interface to 0 on create call because by now we're configured fine. */ ! if((dc = dhcp_client_control_create(interface, promiscuous, 0)) == NULL) { ERROR_MESSAGE("encountered a fatal error. I'm exiting.", interface); client_states[STATE_DO_SHUTDOWN] (NULL); } + /* set old context information. */ + dhcp_client_control_set_context(dc, dc_context); + if(file_create_pid(interface)) { ERROR_MESSAGE("could not create PID file for interface: %s"); *************** *** 441,444 **** --- 468,474 ---- if(fake_hw_addr) /* Marla, you liar, you big tourist, I need this. Now get out! */ dhcp_client_control_use_fake_hw_addr(dc, fake_hw_addr); + + /* call reinitialize for things like resetting the timer. */ + client_reinitialize(dc); } Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client.h 27 Dec 2002 02:53:45 -0000 1.10 --- dhcp-client.h 29 Dec 2002 05:09:55 -0000 1.11 *************** *** 28,31 **** --- 28,40 ---- /* data structures. */ + typedef struct { + + /* use these for unicasting. */ + ip_addr_t sip_addr; /* server or relay agent ip address */ + eth_addr_t shw_addr; /* server or relay agent hardware address. */ + timer_keeper_t *timer; /* timer for rebind/renew. */ + + } dhcp_client_control_context_t; + /* client control object. */ typedef struct { *************** *** 39,43 **** time_t started; /* the amount of milliseconds since we started. */ time_t secs; /* secs -- used to save secs value. */ - timer_keeper_t *timer; /* timer for rebind/renew. */ char *interface; /* interface name. */ --- 48,51 ---- *************** *** 46,62 **** int discover_offer_retries; /* counter for retries on discover_offer */ - /* use these for unicasting. */ - ip_addr_t sip_addr; /* server or relay agent ip address */ - eth_addr_t shw_addr; /* server or relay agent hardware address. */ - - /* use these when filling in dhcp headers. */ - ip_addr_t yiaddr; /* our assigned ip address. */ - ip_addr_t siaddr; /* server ip address. */ - ip_addr_t giaddr; /* relay agent ip address. */ - ip_addr_t ciaddr; /* client ip address. */ - /* use this for validation purposes. */ uint16_t server_port; /* port to expect UDP packets from. */ } dhcp_client_control_t; --- 54,65 ---- int discover_offer_retries; /* counter for retries on discover_offer */ /* use this for validation purposes. */ uint16_t server_port; /* port to expect UDP packets from. */ + /* context information: this information is stateful so keep it seperate + * so it may be saved in case we need to recreate our control object. */ + + dhcp_client_control_context_t *context; + } dhcp_client_control_t; *************** *** 100,106 **** extern int client_fatal_error(dhcp_client_control_t *dc); extern int client_do_shutdown(dhcp_client_control_t *dc); /* client control. */ ! extern dhcp_client_control_t *dhcp_client_control_create(char *interface, int promiscuous); extern dhcp_client_control_t *dhcp_client_control_create_dummy(char *interface); extern void dhcp_client_control_destroy(dhcp_client_control_t *dc); --- 103,110 ---- extern int client_fatal_error(dhcp_client_control_t *dc); extern int client_do_shutdown(dhcp_client_control_t *dc); + extern int client_reinitialize(dhcp_client_control_t *dc); /* client control. */ ! extern dhcp_client_control_t *dhcp_client_control_create(char *interface, int promiscuous, int clear_interface); extern dhcp_client_control_t *dhcp_client_control_create_dummy(char *interface); extern void dhcp_client_control_destroy(dhcp_client_control_t *dc); *************** *** 119,122 **** --- 123,133 ---- extern ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc); extern eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc); + + /* context information. */ + + extern dhcp_client_control_context_t *dhcp_client_control_context_create(void); + extern void dhcp_client_control_destroy_context(dhcp_client_control_context_t *context); + extern dhcp_client_control_context_t *dhcp_client_control_copy_context(dhcp_client_control_t *dc); + extern void dhcp_client_control_set_context(dhcp_client_control_t *dc, dhcp_client_control_context_t *context); #endif /* DHCP_CLIENT_H */ Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-interface.c 27 Dec 2002 02:53:45 -0000 1.4 --- dhcp-interface.c 29 Dec 2002 05:09:55 -0000 1.5 *************** *** 107,117 **** if(set_addr) /* set an address as we bring this up. */ { ! if(addr == 0) { ! ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_NONE; ! } else { ! ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry->intf_addr.addr_bits); ! memcpy(&ic->interface_entry->intf_addr.addr_ip, &addr, IP_ADDR_LEN); ! } } --- 107,115 ---- if(set_addr) /* set an address as we bring this up. */ { ! ! ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry->intf_addr.addr_bits); ! memcpy(&ic->interface_entry->intf_addr.addr_ip, &addr, IP_ADDR_LEN); ! } *************** *** 126,132 **** if(interface_set_info(ic)) { ! ERROR_MESSAGE("could not bring up interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); ! return -1; } --- 124,136 ---- if(interface_set_info(ic)) { ! ! /* setting 0 address under Linux with dnet currently ! * fails. so we'll ignore the error for now. FIXME: ! * update when dnet is fixed. (the address is set to 0 ! * but dnet doesn't get further than netmask settings. */ ! ! /* ERROR_MESSAGE("could not bring up interface %s : %s", ! ic->interface_entry->intf_name, strerror(errno)); ! return -1; */ } *************** *** 144,147 **** --- 148,152 ---- } + ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_NONE; ic->interface_entry->intf_flags &= ~INTF_FLAG_UP; Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-librawnet.h 27 Dec 2002 02:53:21 -0000 1.7 --- dhcp-librawnet.h 29 Dec 2002 05:09:55 -0000 1.8 *************** *** 315,319 **** /* rawnet routines. */ extern rawnet_t *rawnet_create(const char *device, const char *filter, int sport, int dport, ! int promiscuous); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net, struct timeval *tm); --- 315,319 ---- /* rawnet routines. */ extern rawnet_t *rawnet_create(const char *device, const char *filter, int sport, int dport, ! int promiscuous, int clear_address); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net, struct timeval *tm); *************** *** 333,337 **** int (*check) (void *arg), time_t max_timeout); ! extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu); extern int rawnet_interface_down(rawnet_t *net); extern list_t *rawnet_list_active_interfaces(void); --- 333,337 ---- int (*check) (void *arg), time_t max_timeout); ! extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu, int clear_address); extern int rawnet_interface_down(rawnet_t *net); extern list_t *rawnet_list_active_interfaces(void); Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-libutil.h 23 Dec 2002 01:21:52 -0000 1.19 --- dhcp-libutil.h 29 Dec 2002 05:09:55 -0000 1.20 *************** *** 246,249 **** --- 246,250 ---- extern void reinitialize_timer(timer_keeper_t *timer); extern uint32_t timer_peek_next_timer(timer_keeper_t *timer); + extern timer_keeper_t *timer_copy(timer_keeper_t *timer); /* var file. */ Index: dhcp-rawnet.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-rawnet.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-rawnet.c 27 Dec 2002 02:53:45 -0000 1.4 --- dhcp-rawnet.c 29 Dec 2002 05:09:55 -0000 1.5 *************** *** 95,107 **** /* bring up interface, and assign ourselves the address passed. */ ! int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu) { ! if(interface_up(net->intf_handle, addr, netmask, mtu, 1)) { ERROR_MESSAGE("could not bring interface up."); return -1; } ! memcpy(&net->cip_addr, &addr, IP_ADDR_LEN); /* set our IP address. */ return 0; } --- 95,108 ---- /* bring up interface, and assign ourselves the address passed. */ ! int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu, int set_address) { ! if(interface_up(net->intf_handle, addr, netmask, mtu, set_address)) { ERROR_MESSAGE("could not bring interface up."); return -1; } ! /* now set our address, whether we set it earlier or not. */ ! rawnet_get_ip_addr(net, &net->cip_addr); return 0; } *************** *** 191,195 **** rawnet_t *rawnet_create(const char *device, const char *filter, ! int dhcp_src_port, int dhcp_dst_port, int promiscuous) { rawnet_t *net; --- 192,196 ---- rawnet_t *rawnet_create(const char *device, const char *filter, ! int dhcp_src_port, int dhcp_dst_port, int promiscuous, int clear_address) { rawnet_t *net; *************** *** 225,229 **** /* interface down */ /* bring it up with dum values. */ ! if(rawnet_interface_up(net, 0, 0, -1)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); --- 226,240 ---- /* interface down */ /* bring it up with dum values. */ ! if(rawnet_interface_up(net, 0, 0, -1, clear_address)) { ! ERROR_MESSAGE("error trying to bring device up: %s", device); ! rawnet_destroy(net); ! return NULL; ! } ! } else if(clear_address) { ! ! /* interface down but we've been told to clear its address, ! * so our caller wants us to initialize it either way. */ ! ! if(rawnet_interface_up(net, 0, 0, -1, clear_address)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sniff.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-sniff.c 23 Dec 2002 00:51:25 -0000 1.4 --- dhcp-sniff.c 29 Dec 2002 05:09:55 -0000 1.5 *************** *** 118,128 **** /* It's ok not to set ports since we're not writing any packets. */ ! net = rawnet_create(interface_name, stringbuffer_getstring(filter), 0, 0, 1); ! ! stringbuffer_destroy(filter); ! if(net == NULL) { FATAL_MESSAGE("unable to access raw network"); } INFO_MESSAGE("opened %s for packet capturing", interface_name); --- 118,126 ---- /* It's ok not to set ports since we're not writing any packets. */ ! net = rawnet_create(interface_name, stringbuffer_getstring(filter), 0, 0, 1, 0); if(net == NULL) { FATAL_MESSAGE("unable to access raw network"); } + stringbuffer_destroy(filter); INFO_MESSAGE("opened %s for packet capturing", interface_name); Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-sysconf.c 23 Dec 2002 01:21:52 -0000 1.10 --- dhcp-sysconf.c 29 Dec 2002 05:09:55 -0000 1.11 *************** *** 221,225 **** uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_IP_LEASE); return 0; } --- 221,225 ---- uint32_t *secs = value; ! timer_add_trigger(dc->context->timer, *secs, TIMER_IP_LEASE); return 0; } *************** *** 229,233 **** uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_REBIND); return 0; } --- 229,233 ---- uint32_t *secs = value; ! timer_add_trigger(dc->context->timer, *secs, TIMER_REBIND); return 0; } *************** *** 237,241 **** uint32_t *secs = value; ! timer_add_trigger(dc->timer, *secs, TIMER_RENEW); return 0; } --- 237,241 ---- uint32_t *secs = value; ! timer_add_trigger(dc->context->timer, *secs, TIMER_RENEW); return 0; } *************** *** 426,430 **** } ! if(rawnet_interface_up(dc->rawnet, addr, netmask, (int)mtu)) { ERROR_MESSAGE("could not bring interface up: %s", rawnet_get_device_name(dc->rawnet)); return -1; --- 426,430 ---- } ! if(rawnet_interface_up(dc->rawnet, addr, netmask, (int)mtu, 1)) { ERROR_MESSAGE("could not bring interface up: %s", rawnet_get_device_name(dc->rawnet)); return -1; Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-timer.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-timer.c 19 Dec 2002 17:20:36 -0000 1.7 --- dhcp-timer.c 29 Dec 2002 05:09:55 -0000 1.8 *************** *** 175,176 **** --- 175,202 ---- return trigger->seconds; } + + /* make a copy of a timer: achtung this doesn't fiddle with any + * timers already set. */ + timer_keeper_t *timer_copy(timer_keeper_t *timer) + { + timer_keeper_t *timer_copy; + timer_trigger_t *trigger; + list_t *list_ptr; + + timer_copy = create_timer(); + + /* now copy over individual triggers by recreating them. */ + + for(list_ptr = timer->triggers; list_ptr; + list_ptr = list_ptr->next) { + + trigger = list_ptr->data; + timer_copy->triggers = add_to_list(timer_copy->triggers, + create_trigger(trigger->seconds, trigger->id)); + } + + timer_copy->triggers = sort_list(timer_copy->triggers, compare_triggers_shortest); + return timer_copy; + } + + |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9562 Modified Files: dhcp-client-control.c dhcp-client-states.c dhcp-client.h dhcp-eth.c dhcp-interface.c dhcp-interface.h dhcp-ip.c dhcp-print.c dhcp-rawnet.c Log Message: now force clearing the ip address on the interface -- dhcp-sniff is thus broken Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-client-control.c 24 Dec 2002 03:03:28 -0000 1.11 --- dhcp-client-control.c 27 Dec 2002 02:53:45 -0000 1.12 *************** *** 289,298 **** /* get the server address. */ ! ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr) { return dc->sip_addr; } ! eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr) { return dc->shw_addr; --- 289,298 ---- /* get the server address. */ ! ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc) { return dc->sip_addr; } ! eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc) { return dc->shw_addr; Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-client-states.c 24 Dec 2002 03:03:28 -0000 1.19 --- dhcp-client-states.c 27 Dec 2002 02:53:45 -0000 1.20 *************** *** 176,185 **** /* get the mac address, and ip address from the packet. */ ! ip_addr = ip_get_source_addr(dc->rawnet->ip_p); ! eth_addr = eth_get_src_address(dc->rawnet->ether_p); ! ! /* make the strings of the addresses. */ ! eth_addr_string = eth_addr_to_string(eth_addr); ! ip_addr_string = ip_addr_to_string(ip_addr); /* build our received options array. */ --- 176,181 ---- /* get the mac address, and ip address from the packet. */ ! ip_addr = ip_get_src_addr(dc->rawnet->ip_p); ! eth_addr = eth_get_src_addr(dc->rawnet->ether_p); /* build our received options array. */ *************** *** 206,209 **** --- 202,210 ---- if(required_options[i] && !received_options[i]) { + + /* make the strings of the addresses. */ + eth_addr_string = eth_addr_to_string(eth_addr); + ip_addr_string = ip_addr_to_string(ip_addr); + WARN_MESSAGE("ignoring offer from server (%s : %s) : failed to supply required option: %s", ip_addr_string, eth_addr_string, dhcp_option_printable_string_get(i)); *************** *** 216,221 **** } - xfree(ip_addr_string); - xfree(eth_addr_string); return 1; } --- 217,220 ---- *************** *** 410,418 **** INFO_MESSAGE("attempting DHCP DISCOVER"); options = client_build_discover_option_list(dc); ! /* when we begin transmitting discover_offer we setup our secs field. ! * this is because relay agents and dhcp servers use this to see how ! * bad off we are. */ dhcp_client_reset_secs(dc); --- 409,418 ---- INFO_MESSAGE("attempting DHCP DISCOVER"); + /* build discovery option list. */ options = client_build_discover_option_list(dc); ! /* when we begin transmitting discover_offer we setup our ! * secs field. this is because relay agents and dhcp servers ! * can use this to see how bad off we are. */ dhcp_client_reset_secs(dc); *************** *** 448,451 **** --- 448,458 ---- } + /* get the actual physical addresses of whoever gave us this + * information. we don't really need to make any assumptions + * here since we could be talking to a relay agent. */ + + dhcp_client_set_server_ip_address(dc, ip_get_src_addr(dc->rawnet->ip_p)); + dhcp_client_set_server_hw_address(dc, eth_get_src_addr(dc->rawnet->ether_p)); + /* Check for two options before inserting them ourselves. * The server may have decided to be nice to us. */ *************** *** 495,499 **** * down and later purged. */ ! build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); retval = --- 502,506 ---- * down and later purged. */ ! build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, 0, 0, options); retval = *************** *** 524,529 **** /* save hardware and ip address of server. we need these later. */ ! dhcp_client_set_server_ip_address(dc, ip_get_source_addr(dc->rawnet->ip_p)); ! dhcp_client_set_server_hw_address(dc, eth_get_src_address(dc->rawnet->ether_p)); return STATE_SETUP; --- 531,536 ---- /* save hardware and ip address of server. we need these later. */ ! dhcp_client_set_server_ip_address(dc, ip_get_src_addr(dc->rawnet->ip_p)); ! dhcp_client_set_server_hw_address(dc, eth_get_src_addr(dc->rawnet->ether_p)); return STATE_SETUP; *************** *** 761,765 **** options = client_build_rebind_option_list(dc); ! build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); retval = --- 768,772 ---- options = client_build_rebind_option_list(dc); ! build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, 0, 0, options); retval = *************** *** 789,794 **** /* since we did a rebind our server's ip address and mac address may be different. */ ! dhcp_client_set_server_ip_address(dc, ip_get_source_addr(dc->rawnet->ip_p)); ! dhcp_client_set_server_hw_address(dc, eth_get_src_address(dc->rawnet->ether_p)); } --- 796,801 ---- /* since we did a rebind our server's ip address and mac address may be different. */ ! dhcp_client_set_server_ip_address(dc, ip_get_src_addr(dc->rawnet->ip_p)); ! dhcp_client_set_server_hw_address(dc, eth_get_src_addr(dc->rawnet->ether_p)); } Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client.h 24 Dec 2002 03:03:29 -0000 1.9 --- dhcp-client.h 27 Dec 2002 02:53:45 -0000 1.10 *************** *** 46,51 **** int discover_offer_retries; /* counter for retries on discover_offer */ ! ip_addr_t sip_addr; /* server's ip address. */ ! eth_addr_t shw_addr; /* server's hardware address. */ uint16_t server_port; /* port to expect UDP packets from. */ --- 46,60 ---- int discover_offer_retries; /* counter for retries on discover_offer */ ! /* use these for unicasting. */ ! ip_addr_t sip_addr; /* server or relay agent ip address */ ! eth_addr_t shw_addr; /* server or relay agent hardware address. */ ! ! /* use these when filling in dhcp headers. */ ! ip_addr_t yiaddr; /* our assigned ip address. */ ! ip_addr_t siaddr; /* server ip address. */ ! ip_addr_t giaddr; /* relay agent ip address. */ ! ip_addr_t ciaddr; /* client ip address. */ ! ! /* use this for validation purposes. */ uint16_t server_port; /* port to expect UDP packets from. */ *************** *** 105,110 **** --- 114,122 ---- extern void dhcp_client_interface_down(dhcp_client_control_t *dc); + extern void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr); extern void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr); + extern ip_addr_t dhcp_client_get_server_ip_address(dhcp_client_control_t *dc); + extern eth_addr_t dhcp_client_get_server_hw_address(dhcp_client_control_t *dc); #endif /* DHCP_CLIENT_H */ Index: dhcp-eth.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-eth.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-eth.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-eth.c 27 Dec 2002 02:53:45 -0000 1.4 *************** *** 48,57 **** } ! eth_addr_t eth_get_src_address(eth_obj * eth) { return (eth->header.eth_src); } ! eth_addr_t eth_get_dst_address(eth_obj * eth) { return (eth->header.eth_dst); --- 48,57 ---- } ! eth_addr_t eth_get_src_addr(eth_obj * eth) { return (eth->header.eth_src); } ! eth_addr_t eth_get_dst_addr(eth_obj * eth) { return (eth->header.eth_dst); *************** *** 63,67 **** } ! void eth_set_src_address(eth_obj * eth, eth_addr_t addr) { memcpy(ð->header.eth_src.data, &addr.data, ETH_ADDR_LEN); --- 63,67 ---- } ! void eth_set_src_addr(eth_obj * eth, eth_addr_t addr) { memcpy(ð->header.eth_src.data, &addr.data, ETH_ADDR_LEN); *************** *** 69,73 **** } ! void eth_set_dst_address(eth_obj * eth, eth_addr_t addr) { memcpy(ð->header.eth_dst.data, &addr.data, ETH_ADDR_LEN); --- 69,73 ---- } ! void eth_set_dst_addr(eth_obj * eth, eth_addr_t addr) { memcpy(ð->header.eth_dst.data, &addr.data, ETH_ADDR_LEN); Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-interface.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-interface.c 27 Dec 2002 02:53:45 -0000 1.4 *************** *** 98,102 **** /* bring an interface up */ ! int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu) { if(interface_get_info(ic)) { --- 98,102 ---- /* bring an interface up */ ! int interface_up(interface_control_t *ic, ip_addr_t addr, uint32_t netmask, int mtu, uint8_t set_addr) { if(interface_get_info(ic)) { *************** *** 106,115 **** } ! /* Set address if needed. */ ! ! if(addr != 0) { ! ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry->intf_addr.addr_bits); ! memcpy(&ic->interface_entry->intf_addr.addr_ip, &addr, IP_ADDR_LEN); } --- 106,117 ---- } ! if(set_addr) /* set an address as we bring this up. */ { ! if(addr == 0) { ! ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_NONE; ! } else { ! ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, &ic->interface_entry->intf_addr.addr_bits); ! memcpy(&ic->interface_entry->intf_addr.addr_ip, &addr, IP_ADDR_LEN); ! } } Index: dhcp-interface.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-interface.h 16 Nov 2002 00:23:43 -0000 1.2 --- dhcp-interface.h 27 Dec 2002 02:53:45 -0000 1.3 *************** *** 28,32 **** extern interface_control_t *create_interface_control(char *name); extern void destroy_interface_control(interface_control_t *ic); ! extern int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu); extern int interface_down(interface_control_t *ic); extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); --- 28,32 ---- extern interface_control_t *create_interface_control(char *name); extern void destroy_interface_control(interface_control_t *ic); ! extern int interface_up(interface_control_t *ic, ip_addr_t addr, uint32_t netmask, int mtu, uint8_t set_addr); extern int interface_down(interface_control_t *ic); extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); Index: dhcp-ip.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-ip.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-ip.c 19 Dec 2002 03:11:45 -0000 1.4 --- dhcp-ip.c 27 Dec 2002 02:53:45 -0000 1.5 *************** *** 48,57 **** } ! ip_addr_t ip_get_source_addr(ip_obj * ip) { return (ip->header.ip_src); } ! ip_addr_t ip_get_dest_addr(ip_obj * ip) { return (ip->header.ip_dst); --- 48,57 ---- } ! ip_addr_t ip_get_src_addr(ip_obj * ip) { return (ip->header.ip_src); } ! ip_addr_t ip_get_dst_addr(ip_obj * ip) { return (ip->header.ip_dst); *************** *** 68,72 **** } ! void ip_set_source_addr(ip_obj * ip, uint32_t ip_src) { ip->header.ip_src = ip_src; --- 68,72 ---- } ! void ip_set_src_addr(ip_obj * ip, uint32_t ip_src) { ip->header.ip_src = ip_src; *************** *** 74,78 **** } ! void ip_set_dest_addr(ip_obj * ip, uint32_t ip_dst) { ip->header.ip_dst = ip_dst; --- 74,78 ---- } ! void ip_set_dst_addr(ip_obj * ip, uint32_t ip_dst) { ip->header.ip_dst = ip_dst; Index: dhcp-print.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-print.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-print.c 16 Dec 2002 07:20:42 -0000 1.4 --- dhcp-print.c 27 Dec 2002 02:53:45 -0000 1.5 *************** *** 699,706 **** struct in_addr in; ! in.s_addr = ip_get_source_addr(ip); printf("srcip: %s ", inet_ntoa(in)); ! in.s_addr = ip_get_dest_addr(ip); printf("dstip: %s ", inet_ntoa(in)); return; --- 699,706 ---- struct in_addr in; ! in.s_addr = ip_get_src_addr(ip); printf("srcip: %s ", inet_ntoa(in)); ! in.s_addr = ip_get_dst_addr(ip); printf("dstip: %s ", inet_ntoa(in)); return; *************** *** 714,722 **** printf("-------------------------------IP HDR--------------------------------\n"); ! in.s_addr = ip_get_source_addr(ip); printf("Source: %-17s", inet_ntoa(in)); printf(" "); ! in.s_addr = ip_get_dest_addr(ip); printf("Destination: %-17s\n", inet_ntoa(in)); --- 714,722 ---- printf("-------------------------------IP HDR--------------------------------\n"); ! in.s_addr = ip_get_src_addr(ip); printf("Source: %-17s", inet_ntoa(in)); printf(" "); ! in.s_addr = ip_get_dst_addr(ip); printf("Destination: %-17s\n", inet_ntoa(in)); *************** *** 763,768 **** eth_addr_t dst_eth_addr; ! src_eth_addr = eth_get_src_address(eth); ! dst_eth_addr = eth_get_dst_address(eth); printf("smac: %x:%x:%x:%x:%x:%x ", src_eth_addr.data[0], src_eth_addr.data[1], --- 763,768 ---- eth_addr_t dst_eth_addr; ! src_eth_addr = eth_get_src_addr(eth); ! dst_eth_addr = eth_get_dst_addr(eth); printf("smac: %x:%x:%x:%x:%x:%x ", src_eth_addr.data[0], src_eth_addr.data[1], *************** *** 777,782 **** { eth_addr_t src_eth_addr, dst_eth_addr; ! src_eth_addr = eth_get_src_address(eth); ! dst_eth_addr = eth_get_dst_address(eth); printf("--------------------------Ethernet Header-----------------------------\n"); --- 777,782 ---- { eth_addr_t src_eth_addr, dst_eth_addr; ! src_eth_addr = eth_get_src_addr(eth); ! dst_eth_addr = eth_get_dst_addr(eth); printf("--------------------------Ethernet Header-----------------------------\n"); Index: dhcp-rawnet.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-rawnet.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-rawnet.c 16 Nov 2002 00:23:44 -0000 1.3 --- dhcp-rawnet.c 27 Dec 2002 02:53:45 -0000 1.4 *************** *** 98,102 **** { ! if(interface_up(net->intf_handle, addr, netmask, mtu)) { ERROR_MESSAGE("could not bring interface up."); return -1; --- 98,102 ---- { ! if(interface_up(net->intf_handle, addr, netmask, mtu, 1)) { ERROR_MESSAGE("could not bring interface up."); return -1; *************** *** 225,229 **** /* interface down */ /* bring it up with dum values. */ ! if(rawnet_interface_up(net, 0, 0xffffff, -1)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); --- 225,229 ---- /* interface down */ /* bring it up with dum values. */ ! if(rawnet_interface_up(net, 0, 0, -1)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); |
From: <act...@us...> - 2002-12-27 02:53:24
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9499 Modified Files: dhcp-packet-build.c dhcp-librawnet.h Log Message: renamed dest/source in functions to be more standard Index: dhcp-packet-build.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-packet-build.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-packet-build.c 16 Nov 2002 00:23:43 -0000 1.3 --- dhcp-packet-build.c 27 Dec 2002 02:53:21 -0000 1.4 *************** *** 142,147 **** eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr, uint16_t type) { ! eth_set_dst_address(net->ether_p, dest_hw_addr); ! eth_set_src_address(net->ether_p, source_hw_addr); eth_set_type(net->ether_p, type); --- 142,147 ---- eth_addr_t source_hw_addr, eth_addr_t dest_hw_addr, uint16_t type) { ! eth_set_dst_addr(net->ether_p, dest_hw_addr); ! eth_set_src_addr(net->ether_p, source_hw_addr); eth_set_type(net->ether_p, type); *************** *** 264,269 **** /* Do checksum later. */ ! ip_set_source_addr(net->ip_p, source_addr); ! ip_set_dest_addr(net->ip_p, dest_addr); return; --- 264,269 ---- /* Do checksum later. */ ! ip_set_src_addr(net->ip_p, source_addr); ! ip_set_dst_addr(net->ip_p, dest_addr); return; *************** *** 417,423 **** /* Create dhcp request message: broadcast */ ! void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options) { ! build_dhcp(net, xid, secs, net->cip_addr, 0, 0, 0, (ip_addr_t)0, eth_null, 1, options, DHCP_BOOTP_REQUEST); } --- 417,423 ---- /* Create dhcp request message: broadcast */ ! void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, ip_addr_t cip_addr, ip_addr_t sip_addr, list_t *options) { ! build_dhcp(net, xid, secs, 0, cip_addr, sip_addr, 0, (ip_addr_t)0, eth_null, 1, options, DHCP_BOOTP_REQUEST); } Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-librawnet.h 19 Dec 2002 03:11:45 -0000 1.6 --- dhcp-librawnet.h 27 Dec 2002 02:53:21 -0000 1.7 *************** *** 349,353 **** extern void build_dhcp_request_unicast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr); ! extern void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); extern void build_dhcp_release(rawnet_t *net, uint32_t xid, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr); --- 349,353 ---- extern void build_dhcp_request_unicast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr); ! extern void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, ip_addr_t cip_addr, ip_addr_t sip_addr, list_t *options); extern void build_dhcp_release(rawnet_t *net, uint32_t xid, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr); *************** *** 428,433 **** extern int dhcp_is_type(dhcp_obj * dhcp, unsigned char type); extern int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len); - extern int dhcp_have_atleast_requested_options(dhcp_obj * dhcp, unsigned char *option); - extern int dhcp_have_exact_requested_options(dhcp_obj * dhcp, unsigned char *options); extern int dhcp_have_option(dhcp_obj * dhcp, unsigned char tag); extern int dhcp_is_file_overload(dhcp_obj * dhcp); --- 428,431 ---- *************** *** 451,460 **** extern void eth_write_packet_image(eth_obj * eth, unsigned char *packet); ! extern eth_addr_t eth_get_src_address(eth_obj * eth); ! extern eth_addr_t eth_get_dst_address(eth_obj * eth); extern uint16_t eth_get_type(eth_obj * eth); ! extern void eth_set_src_address(eth_obj * eth, eth_addr_t addr); ! extern void eth_set_dst_address(eth_obj * eth, eth_addr_t addr); extern void eth_set_type(eth_obj * eth, uint16_t type); --- 449,458 ---- extern void eth_write_packet_image(eth_obj * eth, unsigned char *packet); ! extern eth_addr_t eth_get_src_addr(eth_obj * eth); ! extern eth_addr_t eth_get_dst_addr(eth_obj * eth); extern uint16_t eth_get_type(eth_obj * eth); ! extern void eth_set_src_addr(eth_obj * eth, eth_addr_t addr); ! extern void eth_set_dst_addr(eth_obj * eth, eth_addr_t addr); extern void eth_set_type(eth_obj * eth, uint16_t type); *************** *** 465,470 **** extern void ip_write_packet_image(ip_obj * ip, unsigned char *packet); ! extern ip_addr_t ip_get_source_addr(ip_obj * ip); ! extern ip_addr_t ip_get_dest_addr(ip_obj * ip); extern unsigned char ip_get_hl(ip_obj * ip); extern uint8_t ip_get_proto(ip_obj * ip); --- 463,468 ---- extern void ip_write_packet_image(ip_obj * ip, unsigned char *packet); ! extern ip_addr_t ip_get_src_addr(ip_obj * ip); ! extern ip_addr_t ip_get_dst_addr(ip_obj * ip); extern unsigned char ip_get_hl(ip_obj * ip); extern uint8_t ip_get_proto(ip_obj * ip); *************** *** 477,482 **** extern void ip_set_ttl(ip_obj * ip, uint8_t ip_ttl); extern void ip_set_proto(ip_obj * ip, unsigned char ip_proto); ! extern void ip_set_source_addr(ip_obj * ip, uint32_t ip_src); ! extern void ip_set_dest_addr(ip_obj * ip, uint32_t ip_src); /* ARP obj routines. */ --- 475,480 ---- extern void ip_set_ttl(ip_obj * ip, uint8_t ip_ttl); extern void ip_set_proto(ip_obj * ip, unsigned char ip_proto); ! extern void ip_set_src_addr(ip_obj * ip, uint32_t ip_src); ! extern void ip_set_dst_addr(ip_obj * ip, uint32_t ip_src); /* ARP obj routines. */ |
From: <act...@us...> - 2002-12-27 02:52:35
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9344 Modified Files: dhcp-com.c Log Message: removed unused functions Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-com.c 19 Dec 2002 03:30:15 -0000 1.6 --- dhcp-com.c 27 Dec 2002 02:52:30 -0000 1.7 *************** *** 454,489 **** } - - /* Check if we have at least the requested options: - * count up the number of options we want, then - * check for matches. If we match as many as we - * have configured then we're ok. */ - - int dhcp_have_atleast_requested_options(dhcp_obj * dhcp, unsigned char *options) - { - int i; - - for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { - if(options[i] && !dhcp_have_option(dhcp, i)) - return 1; - } - - return 0; - } - - int dhcp_have_exact_requested_options(dhcp_obj * dhcp, unsigned char *options) - { - int i; - - for(i = 0; i <= MAX_OPTIONS_HANDLED; i++) { - if(options[i] && !dhcp_have_option(dhcp, i)) - return 1; - if(dhcp_have_option(dhcp, i) && !options[i]) - return 1; - } - - return 0; - } - /* This is a little tricky since we haven't written anything * yet. We know that we must end on a 32-bit boundary, and --- 454,457 ---- |
From: <act...@us...> - 2002-12-24 03:03:32
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv29359 Modified Files: dhcp-client-control.c dhcp-client-states.c dhcp-client.h Log Message: client now only accepts packets from a port designated to a dhcp server Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client-control.c 23 Dec 2002 00:51:24 -0000 1.10 --- dhcp-client-control.c 24 Dec 2002 03:03:28 -0000 1.11 *************** *** 168,173 **** filter = stringbuffer_create(); ! stringbuffer_aprintf(filter, "arp or icmp or (udp and (src port %d or dst port %d))", ! dport, sport); if((dc->rawnet = --- 168,173 ---- filter = stringbuffer_create(); ! stringbuffer_aprintf(filter, "arp or icmp or (udp and src port %d)", ! dport); if((dc->rawnet = *************** *** 182,185 **** --- 182,189 ---- /* Additional fields. */ + + /* server port. */ + dc->server_port = dport; /* demoting an integer to an unsigned short * + * -- should be fine for our purposes. */ /* xid setting */ Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-client-states.c 23 Dec 2002 01:21:52 -0000 1.18 --- dhcp-client-states.c 24 Dec 2002 03:03:28 -0000 1.19 *************** *** 179,182 **** --- 179,183 ---- eth_addr = eth_get_src_address(dc->rawnet->ether_p); + /* make the strings of the addresses. */ eth_addr_string = eth_addr_to_string(eth_addr); ip_addr_string = ip_addr_to_string(ip_addr); *************** *** 224,232 **** { /* check for generic dhcp response. ! * we check for type, validity and ! * matching xid. */ ! if((!rawnet_is_valid(dc->rawnet)) || ! dc->rawnet->type != RAWNET_DHCP || (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid)) return 0; --- 225,243 ---- { /* check for generic dhcp response. ! * we check for type, ! * validity, matching xid, and ! * matching server source port */ ! /* is rawnet happy with the packet? */ ! if(((!rawnet_is_valid(dc->rawnet)) || ! ! /* is it a DHCP packet? */ ! (dc->rawnet->type != RAWNET_DHCP) || ! ! /* does the XID match up? */ ! (dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid) || ! ! /* is it from a server? */ ! (udp_get_src_port(dc->rawnet->udp_p) != dc->server_port))) return 0; Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-client.h 19 Dec 2002 06:50:59 -0000 1.8 --- dhcp-client.h 24 Dec 2002 03:03:29 -0000 1.9 *************** *** 48,51 **** --- 48,52 ---- ip_addr_t sip_addr; /* server's ip address. */ eth_addr_t shw_addr; /* server's hardware address. */ + uint16_t server_port; /* port to expect UDP packets from. */ } dhcp_client_control_t; |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv17767 Modified Files: dhcp-client-cache.c dhcp-client-states.c dhcp-client.c dhcp-files.c dhcp-libutil.h dhcp-sysconf.c Log Message: cleaned up dhcp-files a bit Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-client-cache.c 23 Dec 2002 00:51:24 -0000 1.10 --- dhcp-client-cache.c 23 Dec 2002 01:21:52 -0000 1.11 *************** *** 111,115 **** fname = get_fname(cc); ! move_file(fname_tmp, fname); xfree(fname); --- 111,115 ---- fname = get_fname(cc); ! file_move(fname_tmp, fname); xfree(fname); *************** *** 124,128 **** char *fname = get_fname_tmp(cc); ! delete_file(fname); xfree(fname); --- 124,128 ---- char *fname = get_fname_tmp(cc); ! file_delete(fname); xfree(fname); *************** *** 135,139 **** char *fname = get_fname(cc); ! delete_file(fname); xfree(fname); --- 135,139 ---- char *fname = get_fname(cc); ! file_delete(fname); xfree(fname); Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-client-states.c 21 Dec 2002 16:17:52 -0000 1.17 --- dhcp-client-states.c 23 Dec 2002 01:21:52 -0000 1.18 *************** *** 684,688 **** client_release(dc); ! delete_pid_file(dc->interface); dhcp_client_control_destroy(dc); } --- 684,688 ---- client_release(dc); ! file_delete_pid(dc->interface); dhcp_client_control_destroy(dc); } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-client.c 23 Dec 2002 01:09:26 -0000 1.16 --- dhcp-client.c 23 Dec 2002 01:21:52 -0000 1.17 *************** *** 133,137 **** pid_t pid; ! if(get_pid_file(interface, &pid)) return 0; /* no pid file -- therefore no process. */ --- 133,137 ---- pid_t pid; ! if(file_get_pid(interface, &pid)) return 0; /* no pid file -- therefore no process. */ *************** *** 147,151 **** return 1; else { ! delete_pid_file(interface); return 0; } --- 147,151 ---- return 1; else { ! file_delete_pid(interface); return 0; } *************** *** 276,280 **** info_message("killing %s running on interface: %s", getprogname(), interface); ! if(get_pid_file(interface, &pid)) { ERROR_MESSAGE("could not get PID for client %s. maybe it's not running?", interface); return; --- 276,280 ---- info_message("killing %s running on interface: %s", getprogname(), interface); ! if(file_get_pid(interface, &pid)) { ERROR_MESSAGE("could not get PID for client %s. maybe it's not running?", interface); return; *************** *** 296,300 **** pid_t pid; ! if(get_pid_file(interface, &pid)) { ERROR_MESSAGE ("could not get PID for client running on interface %s. Maybe it's not running?"); --- 296,300 ---- pid_t pid; ! if(file_get_pid(interface, &pid)) { ERROR_MESSAGE ("could not get PID for client running on interface %s. Maybe it's not running?"); *************** *** 317,321 **** client_cache_t *cc; ! if(!get_pid_file(interface, &pid)) { INFO_MESSAGE("%s already is running on %s. I won't delete the cache until it shuts down.", getprogname(), interface); --- 317,321 ---- client_cache_t *cc; ! if(!file_get_pid(interface, &pid)) { INFO_MESSAGE("%s already is running on %s. I won't delete the cache until it shuts down.", getprogname(), interface); *************** *** 434,438 **** } ! if(create_pid_file(interface)) { ERROR_MESSAGE("could not create PID file for interface: %s"); client_states[STATE_DO_SHUTDOWN] (NULL); --- 434,438 ---- } ! if(file_create_pid(interface)) { ERROR_MESSAGE("could not create PID file for interface: %s"); client_states[STATE_DO_SHUTDOWN] (NULL); Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-files.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-files.c 23 Dec 2002 01:09:26 -0000 1.6 --- dhcp-files.c 23 Dec 2002 01:21:52 -0000 1.7 *************** *** 30,33 **** --- 30,52 ---- #include "dhcp-libutil.h" + /* * * * * * * * * * * + * utility routines * + * * * * * * * * * * */ + + /* grab our pid file. <name>.pid */ + static char *get_pid_file_name(char *name) + { + stringbuffer_t *sb; + char *fname; + + sb = stringbuffer_create(); + stringbuffer_append(sb, name); + stringbuffer_append(sb, ".pid"); + + fname = xstrdup(stringbuffer_getstring(sb)); + stringbuffer_destroy(sb); + return fname; + } + static FILE *file_open_proc(const char *filename, char *cmode, int flags, mode_t mode) { *************** *** 51,78 **** } ! /* Assumes we're opening a directory only writable by us . */ ! ! /* create file or open it if it exists. */ ! FILE *file_open_or_create_safe(const char *filename, char *mode) ! { ! return (file_open_proc(filename, mode, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); ! } ! ! /* create file or open if it exists, and always truncate. */ ! FILE *file_create_and_truncate_safe(const char *filename, char *mode) ! { ! return (file_open_proc(filename, mode, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); ! } /* delete a file. */ ! int delete_file(char *fname) { return (unlink(fname)); } /* move a file. */ ! void move_file(char *fname, char *dest) { ! #ifdef HAVE_RENAME rename(fname, dest); #else /* HAVE_RENAME */ --- 70,89 ---- } ! /* * * * * * * * ! * interface * ! * * * * * * * */ /* delete a file. */ ! int file_delete(char *fname) { return (unlink(fname)); } + /* FIXME: we really should be checking return values here. */ /* move a file. */ ! void file_move(char *fname, char *dest) { ! /* use rename() if available. */ ! #ifdef HAVE_RENAME rename(fname, dest); #else /* HAVE_RENAME */ *************** *** 97,124 **** } /* change mode on a file so its publicaly readable. */ ! void make_file_public_read(char *fname) { chmod(fname, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); } ! /* grab our pid file. <name>.pid */ ! static char *get_pid_file_name(char *name) ! { ! stringbuffer_t *sb; ! char *fname; ! sb = stringbuffer_create(); ! stringbuffer_append(sb, name); ! stringbuffer_append(sb, ".pid"); ! fname = xstrdup(stringbuffer_getstring(sb)); ! stringbuffer_destroy(sb); ! return fname; } /* XXX - check return val. */ /* create a pid file <name>.pid */ ! int create_pid_file(char *name) { FILE *fp; --- 108,149 ---- } + /* check permissions. */ + int file_permissions_are(const char *fname, mode_t mode) + { + struct stat st; + + if(stat(fname, &st) < 0) { + ERROR_MESSAGE("could not stat file %s", fname); + return -1; + } else if(st.st_mode != mode) + return 0; /* mode matches. */ + else + return 1; /* mode does not match. */ + } + /* change mode on a file so its publicaly readable. */ ! void file_make_public_read(char *fname) { chmod(fname, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH); } ! /* File creation routines. These assume we're opening a directory ! * only writable by us. It is unsafe to use them elsewhere. */ ! /* create file or open it if it exists. */ ! FILE *file_open_or_create_safe(const char *filename, char *mode) ! { ! return (file_open_proc(filename, mode, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)); ! } ! /* create file or open if it exists, and always truncate. */ ! FILE *file_create_and_truncate_safe(const char *filename, char *mode) ! { ! return (file_open_proc(filename, mode, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)); } /* XXX - check return val. */ /* create a pid file <name>.pid */ ! int file_create_pid(char *name) { FILE *fp; *************** *** 142,151 **** /* delete a pid file <name>.pid */ ! int delete_pid_file(char *name) { int retval; char *fname = get_pid_file_name(name); ! retval = delete_file(fname); /* ignore any errors. */ xfree(fname); --- 167,176 ---- /* delete a pid file <name>.pid */ ! int file_delete_pid(char *name) { int retval; char *fname = get_pid_file_name(name); ! retval = file_delete(fname); /* ignore any errors. */ xfree(fname); *************** *** 154,158 **** /* get pid from file. */ ! int get_pid_file(char *name, pid_t * pid) { FILE *fp; --- 179,183 ---- /* get pid from file. */ ! int file_get_pid(char *name, pid_t * pid) { FILE *fp; *************** *** 177,194 **** return 0; } - - /* check permissions. */ - int file_permissions_are(const char *fname, mode_t mode) - { - struct stat st; - - if(stat(fname, &st) < 0) { - ERROR_MESSAGE("could not stat file %s", fname); - return -1; - } else if(st.st_mode != mode) - return 0; /* mode matches. */ - else - return 1; /* mode does not match. */ - } - - --- 202,203 ---- Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-libutil.h 23 Dec 2002 01:09:26 -0000 1.18 --- dhcp-libutil.h 23 Dec 2002 01:21:52 -0000 1.19 *************** *** 259,269 **** extern FILE *file_open_or_create_safe(const char *filename, char *mode); extern FILE *file_create_and_truncate_safe(const char *filename, char *mode); ! extern int delete_file(char *fname); ! extern void move_file(char *fname, char *dest); extern int file_exists(const char *fname); ! extern void make_file_public_read(char *fname); ! extern int create_pid_file(char *name); ! extern int delete_pid_file(char *name); ! extern int get_pid_file(char *name, pid_t * pid); extern int file_permissions_are(const char *fname, mode_t mode); --- 259,269 ---- extern FILE *file_open_or_create_safe(const char *filename, char *mode); extern FILE *file_create_and_truncate_safe(const char *filename, char *mode); ! extern int file_delete(char *fname); ! extern void file_move(char *fname, char *dest); extern int file_exists(const char *fname); ! extern void file_make_public_read(char *fname); ! extern int file_create_pid(char *name); ! extern int file_delete_pid(char *name); ! extern int file_get_pid(char *name, pid_t * pid); extern int file_permissions_are(const char *fname, mode_t mode); Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-sysconf.c 16 Dec 2002 07:20:42 -0000 1.9 --- dhcp-sysconf.c 23 Dec 2002 01:21:52 -0000 1.10 *************** *** 369,373 **** * so we won't do anything dangerous to the system yet. */ ! delete_file("resolv.conf"); return; } --- 369,373 ---- * so we won't do anything dangerous to the system yet. */ ! file_delete("resolv.conf"); return; } *************** *** 508,513 **** if(file_exists("resolv.conf")) { ! move_file("resolv.conf", "/etc/resolv.conf"); ! make_file_public_read("/etc/resolv.conf"); } --- 508,513 ---- if(file_exists("resolv.conf")) { ! file_move("resolv.conf", "/etc/resolv.conf"); ! file_make_public_read("/etc/resolv.conf"); } |
From: <act...@us...> - 2002-12-23 01:09:29
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv14835 Modified Files: dhcp-client.c dhcp-files.c dhcp-libutil.h Log Message: now checking for work_dir permissions Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-client.c 21 Dec 2002 17:13:14 -0000 1.15 --- dhcp-client.c 23 Dec 2002 01:09:26 -0000 1.16 *************** *** 348,353 **** if(!file_exists(work_dir)) { ! if(mkdir(work_dir, S_IRWXU) < 0) FATAL_MESSAGE("cannot create work directory", strerror(errno)); } --- 348,356 ---- if(!file_exists(work_dir)) { ! if(mkdir(work_dir, S_IRWXU) < 0) { FATAL_MESSAGE("cannot create work directory", strerror(errno)); + } else if(!file_permissions_are(work_dir, S_IRWXU)) { + FATAL_MESSAGE("wrong permissions on work directory: %s (use rwx only for owner)", work_dir); + } } Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-files.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-files.c 23 Dec 2002 00:51:25 -0000 1.5 --- dhcp-files.c 23 Dec 2002 01:09:26 -0000 1.6 *************** *** 141,154 **** } - /* XXX -- handle return val */ /* delete a pid file <name>.pid */ int delete_pid_file(char *name) { char *fname = get_pid_file_name(name); ! delete_file(fname); /* ignore any errors. */ xfree(fname); ! return 0; } --- 141,154 ---- } /* delete a pid file <name>.pid */ int delete_pid_file(char *name) { + int retval; char *fname = get_pid_file_name(name); ! retval = delete_file(fname); /* ignore any errors. */ xfree(fname); ! return retval; } *************** *** 177,178 **** --- 177,194 ---- return 0; } + + /* check permissions. */ + int file_permissions_are(const char *fname, mode_t mode) + { + struct stat st; + + if(stat(fname, &st) < 0) { + ERROR_MESSAGE("could not stat file %s", fname); + return -1; + } else if(st.st_mode != mode) + return 0; /* mode matches. */ + else + return 1; /* mode does not match. */ + } + + Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** dhcp-libutil.h 23 Dec 2002 00:51:25 -0000 1.17 --- dhcp-libutil.h 23 Dec 2002 01:09:26 -0000 1.18 *************** *** 266,269 **** --- 266,270 ---- extern int delete_pid_file(char *name); extern int get_pid_file(char *name, pid_t * pid); + extern int file_permissions_are(const char *fname, mode_t mode); /* interrupt handling. */ |
From: <act...@us...> - 2002-12-23 00:51:28
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11127 Modified Files: dhcp-client-cache.c dhcp-client-conf.c dhcp-client-control.c dhcp-convert.c dhcp-files.c dhcp-libutil.h dhcp-sniff.c dhcp-stringbuffer.c dhcp-tokenizer.c dhcp-util.c dhcp-varfile.c Log Message: fixed up stringbuffer a bit Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client-cache.c 16 Dec 2002 07:20:41 -0000 1.9 --- dhcp-client-cache.c 23 Dec 2002 00:51:24 -0000 1.10 *************** *** 78,86 **** { char *fname; ! stringbuffer *sb = create_stringbuffer(); stringbuffer_aprintf(sb, "%s.%s", cc->interface, suffix); fname = xstrdup(stringbuffer_getstring(sb)); /* FIXME: use a stringbuffer associated creation routine. */ ! destroy_stringbuffer(sb); return fname; --- 78,88 ---- { char *fname; ! stringbuffer_t *sb; ! ! sb = stringbuffer_create(); stringbuffer_aprintf(sb, "%s.%s", cc->interface, suffix); fname = xstrdup(stringbuffer_getstring(sb)); /* FIXME: use a stringbuffer associated creation routine. */ ! stringbuffer_destroy(sb); return fname; Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client-conf.c 21 Dec 2002 18:13:10 -0000 1.13 --- dhcp-client-conf.c 23 Dec 2002 00:51:24 -0000 1.14 *************** *** 317,325 **** { char *fname; ! stringbuffer *sb = create_stringbuffer(); stringbuffer_aprintf(sb, "%s.%s", cc->interface, "conf"); fname = xstrdup(stringbuffer_getstring(sb)); ! destroy_stringbuffer(sb); return fname; --- 317,327 ---- { char *fname; ! stringbuffer_t *sb; ! ! sb = stringbuffer_create(); stringbuffer_aprintf(sb, "%s.%s", cc->interface, "conf"); fname = xstrdup(stringbuffer_getstring(sb)); ! stringbuffer_destroy(sb); return fname; Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-client-control.c 21 Dec 2002 16:51:53 -0000 1.9 --- dhcp-client-control.c 23 Dec 2002 00:51:24 -0000 1.10 *************** *** 127,131 **** dhcp_client_control_t *dc; int dport, sport; ! stringbuffer *filter; eth_addr_t interface_addr; --- 127,131 ---- dhcp_client_control_t *dc; int dport, sport; ! stringbuffer_t *filter; eth_addr_t interface_addr; *************** *** 167,171 **** /* Create filter. */ ! filter = create_stringbuffer(); stringbuffer_aprintf(filter, "arp or icmp or (udp and (src port %d or dst port %d))", dport, sport); --- 167,171 ---- /* Create filter. */ ! filter = stringbuffer_create(); stringbuffer_aprintf(filter, "arp or icmp or (udp and (src port %d or dst port %d))", dport, sport); *************** *** 179,183 **** } ! destroy_stringbuffer(filter); /* Additional fields. */ --- 179,183 ---- } ! stringbuffer_destroy(filter); /* Additional fields. */ Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dhcp-convert.c 19 Dec 2002 03:30:15 -0000 1.6 --- dhcp-convert.c 23 Dec 2002 00:51:24 -0000 1.7 *************** *** 273,277 **** char *network_byte_to_string_byte(const unsigned char *data, int len) { ! stringbuffer *sb; char *s; --- 273,277 ---- char *network_byte_to_string_byte(const unsigned char *data, int len) { ! stringbuffer_t *sb; char *s; *************** *** 279,288 **** return NULL; ! sb = create_stringbuffer(); stringbuffer_aprintf(sb, "0x%hhx", *(unsigned char *)data); s = xstrdup(stringbuffer_getstring(sb)); ! destroy_stringbuffer(sb); return s; --- 279,288 ---- return NULL; ! sb = stringbuffer_create(); stringbuffer_aprintf(sb, "0x%hhx", *(unsigned char *)data); s = xstrdup(stringbuffer_getstring(sb)); ! stringbuffer_destroy(sb); return s; *************** *** 326,330 **** char *network_addr_list_to_string(const unsigned char *data, int len) { ! stringbuffer *sb; char *string; --- 326,330 ---- char *network_addr_list_to_string(const unsigned char *data, int len) { ! stringbuffer_t *sb; char *string; *************** *** 334,338 **** } ! sb = create_stringbuffer(); while(len > 0) { --- 334,338 ---- } ! sb = stringbuffer_create(); while(len > 0) { *************** *** 361,365 **** WARN_MESSAGE("network addr to list: no valid addresses passed."); ! destroy_stringbuffer(sb); xfree(string); return NULL; --- 361,365 ---- WARN_MESSAGE("network addr to list: no valid addresses passed."); ! stringbuffer_destroy(sb); xfree(string); return NULL; *************** *** 367,371 **** } else { ! destroy_stringbuffer(sb); return string; } --- 367,371 ---- } else { ! stringbuffer_destroy(sb); return string; } *************** *** 388,397 **** void *string_to_addr_list(const char *string) { ! stringbuffer *sb; uint32_t *addr; list_t *addr_list = NULL; char *cp, *tmp_string, *orig_string;; ! sb = create_stringbuffer(); stringbuffer_append(sb, string); stringbuffer_trim_newline(sb); --- 388,397 ---- void *string_to_addr_list(const char *string) { ! stringbuffer_t *sb; uint32_t *addr; list_t *addr_list = NULL; char *cp, *tmp_string, *orig_string;; ! sb = stringbuffer_create(); stringbuffer_append(sb, string); stringbuffer_trim_newline(sb); *************** *** 399,403 **** tmp_string = xstrdup(stringbuffer_getstring(sb)); ! destroy_stringbuffer(sb); orig_string = tmp_string; --- 399,403 ---- tmp_string = xstrdup(stringbuffer_getstring(sb)); ! stringbuffer_destroy(sb); orig_string = tmp_string; *************** *** 539,543 **** char *int_to_string(const unsigned char *data, int data_len, size_t size, int si) { ! stringbuffer *sb; char *string; --- 539,543 ---- char *int_to_string(const unsigned char *data, int data_len, size_t size, int si) { ! stringbuffer_t *sb; char *string; *************** *** 545,549 **** return NULL; ! sb = create_stringbuffer(); if(si) { /* signed. */ --- 545,549 ---- return NULL; ! sb = stringbuffer_create(); if(si) { /* signed. */ *************** *** 584,588 **** string = xstrdup(stringbuffer_getstring(sb)); ! destroy_stringbuffer(sb); return string; } --- 584,588 ---- string = xstrdup(stringbuffer_getstring(sb)); ! stringbuffer_destroy(sb); return string; } *************** *** 693,697 **** { ! stringbuffer *sb; char *string; --- 693,697 ---- { ! stringbuffer_t *sb; char *string; *************** *** 699,703 **** return NULL; ! sb = create_stringbuffer(); while(len > 0) { --- 699,703 ---- return NULL; ! sb = stringbuffer_create(); while(len > 0) { *************** *** 726,733 **** WARN_MESSAGE("uint16_t list to string: no valid integers passed."); xfree(string); ! destroy_stringbuffer(sb); return NULL; } else { ! destroy_stringbuffer(sb); return string; } --- 726,733 ---- WARN_MESSAGE("uint16_t list to string: no valid integers passed."); xfree(string); ! stringbuffer_destroy(sb); return NULL; } else { ! stringbuffer_destroy(sb); return string; } Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-files.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-files.c 21 Dec 2002 17:12:34 -0000 1.4 --- dhcp-files.c 23 Dec 2002 00:51:25 -0000 1.5 *************** *** 1,3 **** --- 1,4 ---- /* $Header$ + * * Copyright 2002 Thamer Alharbash <tm...@wh...> * *************** *** 105,117 **** static char *get_pid_file_name(char *name) { ! stringbuffer *sb; char *fname; ! sb = create_stringbuffer(); stringbuffer_append(sb, name); stringbuffer_append(sb, ".pid"); fname = xstrdup(stringbuffer_getstring(sb)); ! destroy_stringbuffer(sb); return fname; } --- 106,118 ---- static char *get_pid_file_name(char *name) { ! stringbuffer_t *sb; char *fname; ! sb = stringbuffer_create(); stringbuffer_append(sb, name); stringbuffer_append(sb, ".pid"); fname = xstrdup(stringbuffer_getstring(sb)); ! stringbuffer_destroy(sb); return fname; } Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-libutil.h 22 Dec 2002 08:31:30 -0000 1.16 --- dhcp-libutil.h 23 Dec 2002 00:51:25 -0000 1.17 *************** *** 57,61 **** size_t capacity; char *buf; ! } stringbuffer; /* utility data structures. */ --- 57,61 ---- size_t capacity; char *buf; ! } stringbuffer_t; /* utility data structures. */ *************** *** 86,90 **** FILE *fp; int line_no; ! stringbuffer *data_buff; token_t peek_value; uint8_t peeked; --- 86,90 ---- FILE *fp; int line_no; ! stringbuffer_t *data_buff; token_t peek_value; uint8_t peeked; *************** *** 95,100 **** char *filename; tokenizer_t *tokenizer; ! stringbuffer *var_name; ! stringbuffer *var_val; uint8_t mode; } varfile_t; --- 95,100 ---- char *filename; tokenizer_t *tokenizer; ! stringbuffer_t *var_name; ! stringbuffer_t *var_val; uint8_t mode; } varfile_t; *************** *** 206,226 **** /* stringbuffer. */ ! extern stringbuffer *create_stringbuffer(void); ! extern void destroy_stringbuffer(stringbuffer * sb); ! extern void stringbuffer_append(stringbuffer * sb, const char *s); ! extern stringbuffer *stringbuffer_trim_whitespace(stringbuffer * sb); ! extern char *stringbuffer_get_last_occurance(stringbuffer * sb, char c); ! extern void stringbuffer_trim_newline(stringbuffer * sb); ! extern const char *stringbuffer_getstring(stringbuffer * sb); ! extern void stringbuffer_aprintf(stringbuffer * sb, const char *fmt, ...); ! extern void stringbuffer_aprintf_align(stringbuffer * sb, int begin, int end, const char *fmt, ...); ! extern void stringbuffer_avprintf(stringbuffer * sb, const char *fmt, va_list ap); ! extern void stringbuffer_append_c(stringbuffer * sb, char c); ! extern void stringbuffer_clear(stringbuffer * sb); ! extern const char *stringbuffer_getnextline(stringbuffer * sb, const char *cptr); ! extern int stringbuffer_marknewlines(stringbuffer * sb); ! extern void stringbuffer_set(stringbuffer * dest, const char *s); ! extern void stringbuffer_align(stringbuffer * sb, int begin, int end); ! extern int stringbuffer_getlen(stringbuffer * sb); /* RTT mechanism. */ --- 206,229 ---- /* stringbuffer. */ ! extern stringbuffer_t *stringbuffer_create(void); ! extern void stringbuffer_destroy(stringbuffer_t *sb); ! extern void stringbuffer_clear(stringbuffer_t *sb); ! extern void stringbuffer_append_c(stringbuffer_t *sb, char c); ! extern void stringbuffer_append(stringbuffer_t *sb, const char *s); ! extern stringbuffer_t *stringbuffer_trim_whitespace(stringbuffer_t *sb); ! extern char *stringbuffer_get_last_occurance(stringbuffer_t *sb, char c); ! extern void stringbuffer_trim_newline(stringbuffer_t *sb); ! extern const char *stringbuffer_getstring(stringbuffer_t *sb); ! extern void stringbuffer_set(stringbuffer_t *dest, const char *s); ! extern void stringbuffer_copy(stringbuffer_t *dest, stringbuffer_t *src); ! extern void stringbuffer_replace_c(stringbuffer_t *sb, char c, char replace); ! extern void stringbuffer_align(stringbuffer_t *sb, int begin, int end); ! extern void stringbuffer_avprintf_align(stringbuffer_t *sb, int start, int end, const char *fmt, va_list ap); ! extern void stringbuffer_aprintf(stringbuffer_t *sb, const char *fmt, ...); ! extern void stringbuffer_aprintf_align(stringbuffer_t *sb, int start, int end, const char *fmt, ...); ! extern void stringbuffer_avprintf(stringbuffer_t *sb, const char *fmt, va_list ap); ! extern int stringbuffer_marknewlines(stringbuffer_t *sb); ! extern const char *stringbuffer_getnextline(stringbuffer_t *sb, const char *cptr); ! extern int stringbuffer_getlen(stringbuffer_t *sb); /* RTT mechanism. */ Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sniff.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-sniff.c 16 Nov 2002 00:23:44 -0000 1.3 --- dhcp-sniff.c 23 Dec 2002 00:51:25 -0000 1.4 *************** *** 53,57 **** int retval; int sport, dport; ! stringbuffer *filter; print_packet p_packet = print_dhcp_packet_verbose; list_t *available_interfaces; --- 53,57 ---- int retval; int sport, dport; ! stringbuffer_t *filter; print_packet p_packet = print_dhcp_packet_verbose; list_t *available_interfaces; *************** *** 114,118 **** } ! filter = create_stringbuffer(); stringbuffer_aprintf(filter, "arp or icmp or (udp and (port %d or port %d))", dport, sport); --- 114,118 ---- } ! filter = stringbuffer_create(); stringbuffer_aprintf(filter, "arp or icmp or (udp and (port %d or port %d))", dport, sport); *************** *** 120,124 **** net = rawnet_create(interface_name, stringbuffer_getstring(filter), 0, 0, 1); ! destroy_stringbuffer(filter); if(net == NULL) { --- 120,124 ---- net = rawnet_create(interface_name, stringbuffer_getstring(filter), 0, 0, 1); ! stringbuffer_destroy(filter); if(net == NULL) { Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-stringbuffer.c 21 Dec 2002 16:51:53 -0000 1.8 --- dhcp-stringbuffer.c 23 Dec 2002 00:51:25 -0000 1.9 *************** *** 107,110 **** --- 107,119 ---- } + /* zap newlines by placing spaces in their place. + * we use this before aligning. */ + static void stringbuffer_zap_newline(stringbuffer_t *sb) + { + + stringbuffer_replace_c(sb, '\n', ' '); + stringbuffer_replace_c(sb, '\r', ' '); + } + /* * * * * * * * * * * * * * * * stringbuffer routines. * *************** *** 112,120 **** /* create a new stringbuffer */ ! stringbuffer *create_stringbuffer(void) { ! stringbuffer *sb; ! sb = xmalloc(sizeof(stringbuffer)); sb->len = 0; sb->capacity = 0; --- 121,129 ---- /* create a new stringbuffer */ ! stringbuffer_t *stringbuffer_create(void) { ! stringbuffer_t *sb; ! sb = xmalloc(sizeof(stringbuffer_t)); sb->len = 0; sb->capacity = 0; *************** *** 125,129 **** /* destroy the stringbuffer */ ! void destroy_stringbuffer(stringbuffer * sb) { xfree(sb->buf); --- 134,138 ---- /* destroy the stringbuffer */ ! void stringbuffer_destroy(stringbuffer_t *sb) { xfree(sb->buf); *************** *** 132,136 **** /* clear a string. */ ! void stringbuffer_clear(stringbuffer * sb) { sb->len = 0; --- 141,145 ---- /* clear a string. */ ! void stringbuffer_clear(stringbuffer_t *sb) { sb->len = 0; *************** *** 139,143 **** /* append character to stringbuffer */ ! void stringbuffer_append_c(stringbuffer * sb, char c) { if(sb->capacity <= (sb->len)) { --- 148,152 ---- /* append character to stringbuffer */ ! void stringbuffer_append_c(stringbuffer_t *sb, char c) { if(sb->capacity <= (sb->len)) { *************** *** 152,156 **** /* append string to stringbuffer */ ! void stringbuffer_append(stringbuffer * sb, const char *s) { int len = strlen(s); --- 161,165 ---- /* append string to stringbuffer */ ! void stringbuffer_append(stringbuffer_t *sb, const char *s) { int len = strlen(s); *************** *** 186,190 **** /* FIXME: use memcpy() */ /* remove whitespace (including tabs) */ ! stringbuffer *stringbuffer_trim_whitespace(stringbuffer * sb) { char *ptr, *curptr; --- 195,199 ---- /* FIXME: use memcpy() */ /* remove whitespace (including tabs) */ ! stringbuffer_t *stringbuffer_trim_whitespace(stringbuffer_t *sb) { char *ptr, *curptr; *************** *** 234,238 **** /* get the last occurance of a specific character. useful for slicing. */ ! char *stringbuffer_get_last_occurance(stringbuffer * sb, char c) { char *ptr, *ptrend = NULL; --- 243,247 ---- /* get the last occurance of a specific character. useful for slicing. */ ! char *stringbuffer_get_last_occurance(stringbuffer_t *sb, char c) { char *ptr, *ptrend = NULL; *************** *** 248,252 **** /* remove the last newline character. */ ! void stringbuffer_trim_newline(stringbuffer * sb) { char *ptr; --- 257,261 ---- /* remove the last newline character. */ ! void stringbuffer_trim_newline(stringbuffer_t *sb) { char *ptr; *************** *** 268,272 **** /* return the C string from the buffer. */ ! const char *stringbuffer_getstring(stringbuffer * sb) { return sb->buf; --- 277,281 ---- /* return the C string from the buffer. */ ! const char *stringbuffer_getstring(stringbuffer_t *sb) { return sb->buf; *************** *** 274,278 **** /* set a string into a stringbuffer */ ! void stringbuffer_set(stringbuffer * dest, const char *s) { stringbuffer_clear(dest); /* zap */ --- 283,287 ---- /* set a string into a stringbuffer */ ! void stringbuffer_set(stringbuffer_t *dest, const char *s) { stringbuffer_clear(dest); /* zap */ *************** *** 281,285 **** /* copy a stringbuffer into another stringbuffer */ ! void stringbuffer_copy(stringbuffer * dest, stringbuffer * src) { stringbuffer_set(dest, stringbuffer_getstring(src)); --- 290,294 ---- /* copy a stringbuffer into another stringbuffer */ ! void stringbuffer_copy(stringbuffer_t *dest, stringbuffer_t *src) { stringbuffer_set(dest, stringbuffer_getstring(src)); *************** *** 287,291 **** /* replace in stringbuffer occurances of c with replace */ ! void stringbuffer_replace_c(stringbuffer * sb, char c, char replace) { char *ptr; --- 296,300 ---- /* replace in stringbuffer occurances of c with replace */ ! void stringbuffer_replace_c(stringbuffer_t *sb, char c, char replace) { char *ptr; *************** *** 297,314 **** } - /* zap newlines by placing spaces in their place. - * we use this before aligning. */ - static void stringbuffer_zap_newline(stringbuffer * sb) - { - - stringbuffer_replace_c(sb, '\n', ' '); - stringbuffer_replace_c(sb, '\r', ' '); - } - /* align a stringbuffer on begin and end columns. */ ! void stringbuffer_align(stringbuffer * sb, int begin, int end) { char *ptr, *word_string; ! stringbuffer *aligned_string; int len, i; --- 306,314 ---- } /* align a stringbuffer on begin and end columns. */ ! void stringbuffer_align(stringbuffer_t *sb, int begin, int end) { char *ptr, *word_string; ! stringbuffer_t *aligned_string; int len, i; *************** *** 316,320 **** stringbuffer_zap_newline(sb); ! aligned_string = create_stringbuffer(); ptr = sb->buf; --- 316,320 ---- stringbuffer_zap_newline(sb); ! aligned_string = stringbuffer_create(); ptr = sb->buf; *************** *** 338,342 **** stringbuffer_copy(sb, aligned_string); ! destroy_stringbuffer(aligned_string); return; --- 338,342 ---- stringbuffer_copy(sb, aligned_string); ! stringbuffer_destroy(aligned_string); return; *************** *** 346,352 **** /* append vprintf with alignment. */ ! void stringbuffer_avprintf_align(stringbuffer * sb, int start, int end, const char *fmt, va_list ap) { ! stringbuffer *tmp_sb; char *str; int total, len; --- 346,352 ---- /* append vprintf with alignment. */ ! void stringbuffer_avprintf_align(stringbuffer_t *sb, int start, int end, const char *fmt, va_list ap) { ! stringbuffer_t *tmp_sb; char *str; int total, len; *************** *** 366,370 **** if(start != 0 && end != 0) { ! tmp_sb = create_stringbuffer(); stringbuffer_append(tmp_sb, str); --- 366,370 ---- if(start != 0 && end != 0) { ! tmp_sb = stringbuffer_create(); stringbuffer_append(tmp_sb, str); *************** *** 372,376 **** stringbuffer_append(sb, stringbuffer_getstring(tmp_sb)); ! destroy_stringbuffer(tmp_sb); } else { --- 372,376 ---- stringbuffer_append(sb, stringbuffer_getstring(tmp_sb)); ! stringbuffer_destroy(tmp_sb); } else { *************** *** 384,388 **** /* append printf. */ ! void stringbuffer_aprintf(stringbuffer * sb, const char *fmt, ...) { va_list ap; --- 384,388 ---- /* append printf. */ ! void stringbuffer_aprintf(stringbuffer_t *sb, const char *fmt, ...) { va_list ap; *************** *** 396,400 **** /* append printf with alignment. */ ! void stringbuffer_aprintf_align(stringbuffer * sb, int start, int end, const char *fmt, ...) { va_list ap; --- 396,400 ---- /* append printf with alignment. */ ! void stringbuffer_aprintf_align(stringbuffer_t *sb, int start, int end, const char *fmt, ...) { va_list ap; *************** *** 408,412 **** /* append vprintf. */ ! void stringbuffer_avprintf(stringbuffer * sb, const char *fmt, va_list ap) { stringbuffer_avprintf_align(sb, 0, 0, fmt, ap); --- 408,412 ---- /* append vprintf. */ ! void stringbuffer_avprintf(stringbuffer_t *sb, const char *fmt, va_list ap) { stringbuffer_avprintf_align(sb, 0, 0, fmt, ap); *************** *** 424,428 **** * null terminators inside of them. */ ! int stringbuffer_marknewlines(stringbuffer * sb) { char *c; --- 424,428 ---- * null terminators inside of them. */ ! int stringbuffer_marknewlines(stringbuffer_t *sb) { char *c; *************** *** 451,455 **** /* called _after_ newlines are marked. */ ! const char *stringbuffer_getnextline(stringbuffer * sb, const char *cptr) { const char *ptr; --- 451,455 ---- /* called _after_ newlines are marked. */ ! const char *stringbuffer_getnextline(stringbuffer_t *sb, const char *cptr) { const char *ptr; *************** *** 475,479 **** } ! int stringbuffer_getlen(stringbuffer * sb) { return sb->len; --- 475,479 ---- } ! int stringbuffer_getlen(stringbuffer_t *sb) { return sb->len; Index: dhcp-tokenizer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-tokenizer.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-tokenizer.c 22 Dec 2002 08:31:30 -0000 1.1 --- dhcp-tokenizer.c 23 Dec 2002 00:51:25 -0000 1.2 *************** *** 423,427 **** tokenizer->fp = fp; tokenizer->line_no = 1; ! tokenizer->data_buff = create_stringbuffer(); tokenizer->peeked = 0; --- 423,427 ---- tokenizer->fp = fp; tokenizer->line_no = 1; ! tokenizer->data_buff = stringbuffer_create(); tokenizer->peeked = 0; *************** *** 433,437 **** { fclose(tokenizer->fp); ! destroy_stringbuffer(tokenizer->data_buff); xfree(tokenizer); --- 433,437 ---- { fclose(tokenizer->fp); ! stringbuffer_destroy(tokenizer->data_buff); xfree(tokenizer); Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-util.c 21 Dec 2002 16:51:53 -0000 1.10 --- dhcp-util.c 23 Dec 2002 00:51:25 -0000 1.11 *************** *** 53,57 **** /* append with colon seperation -- utility routine for message_proc. */ ! static void message_append_colon_sep(stringbuffer * sb, const char *str) { if(str != NULL) --- 53,57 ---- /* append with colon seperation -- utility routine for message_proc. */ ! static void message_append_colon_sep(stringbuffer_t *sb, const char *str) { if(str != NULL) *************** *** 65,77 **** const char *file, const char *fmt, va_list ap) { ! static stringbuffer *prefix_sb = NULL; ! static stringbuffer *msg_sb = NULL; const char *ptr = NULL; if(msg_sb == NULL) ! msg_sb = create_stringbuffer(); if(prefix_sb == NULL) ! prefix_sb = create_stringbuffer(); stringbuffer_clear(msg_sb); --- 65,77 ---- const char *file, const char *fmt, va_list ap) { ! static stringbuffer_t *prefix_sb = NULL; ! static stringbuffer_t *msg_sb = NULL; const char *ptr = NULL; if(msg_sb == NULL) ! msg_sb = stringbuffer_create(); if(prefix_sb == NULL) ! prefix_sb = stringbuffer_create(); stringbuffer_clear(msg_sb); *************** *** 538,544 **** { char *string; ! stringbuffer *sb; ! sb = create_stringbuffer(); stringbuffer_aprintf(sb, "%x:%x:%x:%x:%x:%x", eth_addr.data[0], eth_addr.data[1], eth_addr.data[2], eth_addr.data[3], eth_addr.data[4], eth_addr.data[5]); --- 538,544 ---- { char *string; ! stringbuffer_t *sb; ! sb = stringbuffer_create(); stringbuffer_aprintf(sb, "%x:%x:%x:%x:%x:%x", eth_addr.data[0], eth_addr.data[1], eth_addr.data[2], eth_addr.data[3], eth_addr.data[4], eth_addr.data[5]); *************** *** 546,550 **** string = xstrdup(stringbuffer_getstring(sb)); ! destroy_stringbuffer(sb); return string; --- 546,550 ---- string = xstrdup(stringbuffer_getstring(sb)); ! stringbuffer_destroy(sb); return string; Index: dhcp-varfile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-varfile.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-varfile.c 22 Dec 2002 08:31:30 -0000 1.5 --- dhcp-varfile.c 23 Dec 2002 00:51:25 -0000 1.6 *************** *** 55,60 **** varfile = xmalloc(sizeof(varfile_t)); varfile->filename = xstrdup(filename); ! varfile->var_name = create_stringbuffer(); ! varfile->var_val = create_stringbuffer(); varfile->tokenizer = tokenizer_create(filename); varfile->mode = mode; --- 55,60 ---- varfile = xmalloc(sizeof(varfile_t)); varfile->filename = xstrdup(filename); ! varfile->var_name = stringbuffer_create(); ! varfile->var_val = stringbuffer_create(); varfile->tokenizer = tokenizer_create(filename); varfile->mode = mode; *************** *** 65,70 **** { tokenizer_destroy(varfile->tokenizer); ! destroy_stringbuffer(varfile->var_name); ! destroy_stringbuffer(varfile->var_val); xfree(varfile->filename); xfree(varfile); --- 65,70 ---- { tokenizer_destroy(varfile->tokenizer); ! stringbuffer_destroy(varfile->var_name); ! stringbuffer_destroy(varfile->var_val); xfree(varfile->filename); xfree(varfile); |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10369 Modified Files: Makefile.am dhcp-conf.c dhcp-libutil.h dhcp-varfile.c Added Files: dhcp-tokenizer.c dhcp-tokenizer.h Removed Files: dhcp-parser.c dhcp-parser.h Log Message: replaced dhcp-parser with dhcp-tokenizer -- mostly just terminology changes --- NEW FILE: dhcp-tokenizer.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-tokenizer.c,v 1.1 2002/12/22 08:31:30 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #define MODULE_NAME "dhcp-tokenizer" #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-tokenizer.h" /* these characters are special. we only allow them in a quoted string. */ static char special_characters[] = ",;{}="; /* forward declaration of tokenizers. */ static token_t tokenize_comment(tokenizer_t *tokenizer); static token_t tokenize_gobble_line(tokenizer_t *tokenizer); static token_t tokenize_quoted_string(tokenizer_t *tokenizer); static token_t tokenize_string(tokenizer_t *tokenizer); static token_t tokenize_comment(tokenizer_t *tokenizer); static token_t tokenize_newline(tokenizer_t *tokenizer); static token_t tokenize_assignment(tokenizer_t *tokenizer); static token_t tokenize_block_open(tokenizer_t *tokenizer); static token_t tokenize_block_close(tokenizer_t *tokenizer); static token_t tokenize_comma(tokenizer_t *tokenizer); static token_t tokenize_semicolon(tokenizer_t *tokenizer); /* tokenizer dispatch table. */ tokenizers_t parsers[] = { /* char val */ /* routine. */ { ';', tokenize_semicolon }, { '\\', tokenize_gobble_line }, { '#' , tokenize_comment }, { '\"', tokenize_quoted_string }, { '\n', tokenize_newline }, { '=', tokenize_assignment }, { '{' , tokenize_block_open }, { '}', tokenize_block_close }, { ',', tokenize_comma }, }; /* * * * * * * * * * * * utility functions * * * * * * * * * * * */ static int is_special_char(int c) { int i; for(i = 0;i < NELMS(special_characters);i++) { if(c == special_characters[i]) return 1; } return 0; } /* is a valid string character. */ static int is_valid_string_char(int c) { if(c == '\\') return 0; if(isalnum(c) || ispunct(c)) return 1; else return 0; } /* the stream is EOF or an error occured. */ static token_t check_eof(tokenizer_t *tokenizer) { if(feof(tokenizer->fp)) return TOKEN_EOF; else return TOKEN_ERROR; } /* just gobble up till the end of the newline */ static token_t tokenize_gobble_line(tokenizer_t *tokenizer) { int c; while(1) { c = fgetc(tokenizer->fp); switch (c) { case EOF: return check_eof(tokenizer); case '\n': tokenizer->line_no++; return TOKEN_NEWLINE; default: break; } } } /* * * * * * * * * * * * * * * the tokenizer routines * * * * * * * * * * * * * * */ /* read a quoted string. */ static token_t tokenize_quoted_string(tokenizer_t *tokenizer) { int c, c2; while(1) { c = fgetc(tokenizer->fp); switch (c) { case EOF: return check_eof(tokenizer); case '\"': return TOKEN_STRING; case '\n': return TOKEN_ERROR; /* error to have newline in string constant. */ case '\\': c2 = getc(tokenizer->fp); if(c2 != '\\') { ungetc(c2, tokenizer->fp); if(tokenize_gobble_line(tokenizer) != TOKEN_NEWLINE) return TOKEN_ERROR; else break; } else ungetc(c2, tokenizer->fp); /* otherwise put it back and fall through. */ ungetc(c, tokenizer->fp); /* fall through */ default: if(is_valid_string_char(c) || c == ' ' || c == '\t') stringbuffer_append_c(tokenizer->data_buff, (char)c); else { ungetc(c, tokenizer->fp); return TOKEN_ERROR; } } } } /* read a string. */ static token_t tokenize_string(tokenizer_t *tokenizer) { int c, c2; while(1) { c = fgetc(tokenizer->fp); switch (c) { case EOF: return check_eof(tokenizer); case '\n': ungetc(c, tokenizer->fp); return TOKEN_STRING; /* newline terminates string. */ case '\t': case ' ': ungetc(c, tokenizer->fp); return TOKEN_STRING; /* spaces or tabs terminate string */ case '\\': c2 = getc(tokenizer->fp); if(c2 != '\\') { ungetc(c2, tokenizer->fp); if(tokenize_gobble_line(tokenizer) != TOKEN_NEWLINE) return TOKEN_ERROR; else break; } else ungetc(c2, tokenizer->fp); /* fall through. */ default: if(is_special_char(c)) { ungetc(c, tokenizer->fp); return TOKEN_STRING; } if(is_valid_string_char(c)) { stringbuffer_append_c(tokenizer->data_buff, (char)c); } else { ungetc(c, tokenizer->fp); return TOKEN_ERROR; /* anything else and we've been terminated. */ } } } } static token_t tokenize_comment(tokenizer_t *tokenizer) { return tokenize_gobble_line(tokenizer); } static token_t tokenize_newline(tokenizer_t *tokenizer) { tokenizer->line_no++; return TOKEN_NEWLINE; } static token_t tokenize_assignment(tokenizer_t *tokenizer) { return TOKEN_ASSIGNMENT; } static token_t tokenize_block_open(tokenizer_t *tokenizer) { return TOKEN_BLOCK_OPEN; } static token_t tokenize_block_close(tokenizer_t *tokenizer) { return TOKEN_BLOCK_CLOSE; } static token_t tokenize_comma(tokenizer_t *tokenizer) { return TOKEN_COMMA; } static token_t tokenize_semicolon(tokenizer_t *tokenizer) { return TOKEN_SEMICOLON; } static token_t tokenizer_get_next_token_proc(tokenizer_t *tokenizer, uint8_t peeking) { int c, c2; int i; /* have we peeked previously? */ if(tokenizer->peeked) { /* then we have enough to return with now. */ /* if we're not peeking now clear flag before return. */ if(!peeking) { /* remove peek flag. */ tokenizer->peeked = 0; } /* the data is already read, go ahead and return. */ return tokenizer->peek_value; } /* if we're peeking then setup our flag now since we'll be returning * a peeked value and not losing it. */ tokenizer->peeked = peeking; /* now read as usual. */ stringbuffer_clear(tokenizer->data_buff); while(1) { c = fgetc(tokenizer->fp); switch (c) { case EOF: tokenizer->peek_value = TOKEN_EOF; return tokenizer->peek_value; case ' ': case '\t': continue; case '\\': c2 = getc(tokenizer->fp); /* any backslash whose first trailing character is a * space-like or newline-like character means we * gobble up, but don't report end of line instead we * continue parsing. */ if(c2 == ' ' || c2 == '\t' || c2 == '\n' || c2 == '\r') { ungetc(c2, tokenizer->fp); if(tokenize_gobble_line(tokenizer) != TOKEN_NEWLINE) { tokenizer->peek_value = TOKEN_ERROR; return tokenizer->peek_value; } else { break; } } else { /* the next character may not be passed through * the special parsers. we assume it's a string * and do our best to read it .*/ ungetc(c2, tokenizer->fp); goto read_in_string; } /* fall through */ default: for(i = 0;i < NELMS(parsers); i++) { if(parsers[i].character == c) { tokenizer->peek_value = parsers[i].do_parse(tokenizer); return tokenizer->peek_value; } } /* otherwise we default to trying a string. */ read_in_string: /* if we have an alphanumeric it's a string. * read it in. */ if(is_valid_string_char(c) || c == '\\') { ungetc(c, tokenizer->fp); tokenizer->peek_value = tokenize_string(tokenizer); return tokenizer->peek_value; } /* anything else is an error. */ tokenizer->peek_value = TOKEN_ERROR; return tokenizer->peek_value; } } } /* * * * * * * * interface * * * * * * * */ /* get the next token. */ token_t tokenizer_get_next_token(tokenizer_t *tokenizer) { return(tokenizer_get_next_token_proc(tokenizer, 0)); } /* peek at the next token. */ token_t tokenizer_peek_next_token(tokenizer_t *tokenizer) { return(tokenizer_get_next_token_proc(tokenizer, 1)); } /* get the next token and ignore newlines. */ token_t tokenizer_get_next_token_ignore_newlines(tokenizer_t *tokenizer) { token_t token; while((token = tokenizer_get_next_token(tokenizer)) == TOKEN_NEWLINE); return token; } /* peek the next token and ignore newlines. */ token_t tokenizer_peek_next_token_ignore_newlines(tokenizer_t *tokenizer) { token_t token; while(1) { token = tokenizer_peek_next_token(tokenizer); if(token == TOKEN_NEWLINE) tokenizer_get_next_token(tokenizer); else return token; } } /* create a parser instance. */ tokenizer_t *tokenizer_create(const char *filename) { FILE *fp; tokenizer_t *tokenizer; fp = file_open_or_create_safe(filename, "r"); if(fp == NULL) return NULL; tokenizer = xmalloc(sizeof(tokenizer_t)); tokenizer->fp = fp; tokenizer->line_no = 1; tokenizer->data_buff = create_stringbuffer(); tokenizer->peeked = 0; return tokenizer; } /* destroy a tokenizer instance. */ void tokenizer_destroy(tokenizer_t *tokenizer) { fclose(tokenizer->fp); destroy_stringbuffer(tokenizer->data_buff); xfree(tokenizer); return; } /* get current line number from the tokenizer. */ int tokenizer_get_line_no(tokenizer_t *tokenizer) { return tokenizer->line_no; } /* get a data string from the tokenizer. */ const char *tokenizer_get_data(tokenizer_t *tokenizer) { return stringbuffer_getstring(tokenizer->data_buff); } --- NEW FILE: dhcp-tokenizer.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-tokenizer.h,v 1.1 2002/12/22 08:31:30 actmodern Exp $ * * Copyright 2002 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Tokenizer * */ #ifndef DHCP_TOKENIZER_H #define DHCP_TOKENIZER_H /* types. */ /* internal tokenizer type. */ typedef token_t (*tokenizer)(tokenizer_t *tokenizer); /* structures. */ /* tokenizer dispatch structure. */ typedef struct { char character; tokenizer do_parse; } tokenizers_t; /* prototypes. */ extern const char *tokenizer_get_data(tokenizer_t *tokenizer); extern int tokenizer_get_line_no(tokenizer_t *tokenizer); extern tokenizer_t *tokenizer_create(const char *filename); extern void tokenizer_destroy(tokenizer_t *tokenizer); extern token_t tokenizer_peek_next_token_ignore_newlines(tokenizer_t *tokenizer); extern token_t tokenizer_peek_next_token(tokenizer_t *tokenizer); extern token_t tokenizer_get_next_token_ignore_newlines(tokenizer_t *tokenizer); extern token_t tokenizer_get_next_token(tokenizer_t *tokenizer); /* tokenizer return values. */ enum parser_atom { TOKEN_ERROR = 0, TOKEN_STRING, TOKEN_ASSIGNMENT, TOKEN_NEWLINE, TOKEN_EOF, TOKEN_BLOCK_OPEN, TOKEN_BLOCK_CLOSE, TOKEN_SEMICOLON, TOKEN_COMMA }; #endif /* DHCP_TOKENIZER_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Makefile.am 16 Dec 2002 07:20:41 -0000 1.11 --- Makefile.am 22 Dec 2002 08:31:29 -0000 1.12 *************** *** 16,20 **** dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-convert.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-parser.h dhcp-sysconf.h dhcp-conf.h --- 16,20 ---- dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-convert.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-tokenizer.h dhcp-sysconf.h dhcp-conf.h *************** *** 27,31 **** dhcp-timer.c \ dhcp-varfile.c \ ! dhcp-parser.c \ dhcp-files.c \ dhcp-rawnet.c \ --- 27,31 ---- dhcp-timer.c \ dhcp-varfile.c \ ! dhcp-tokenizer.c \ dhcp-files.c \ dhcp-rawnet.c \ Index: dhcp-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-conf.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-conf.c 21 Dec 2002 18:13:10 -0000 1.7 --- dhcp-conf.c 22 Dec 2002 08:31:29 -0000 1.8 *************** *** 35,39 **** #include "dhcp-libutil.h" ! #include "dhcp-parser.h" #include "dhcp-conf.h" --- 35,39 ---- #include "dhcp-libutil.h" ! #include "dhcp-tokenizer.h" #include "dhcp-conf.h" *************** *** 149,155 **** conf = xmalloc(sizeof(conf_t)); ! conf->parser = create_parser(filename); ! if(conf->parser == NULL) { ERROR_MESSAGE("could not open configuration file: %s", filename); xfree(conf); --- 149,155 ---- conf = xmalloc(sizeof(conf_t)); ! conf->tokenizer = tokenizer_create(filename); ! if(conf->tokenizer == NULL) { ERROR_MESSAGE("could not open configuration file: %s", filename); xfree(conf); *************** *** 167,171 **** { xfree(conf->filename); ! destroy_parser(conf->parser); purge_list(conf->directives, directive_destroy_l); xfree(conf); --- 167,171 ---- { xfree(conf->filename); ! tokenizer_destroy(conf->tokenizer); purge_list(conf->directives, directive_destroy_l); xfree(conf); *************** *** 182,198 **** arg_symbol_t *identifier_symbol = NULL; const char *string; ! atom_t atom; const char **ptr; int i; ! atom = get_next_atom_ignore_newlines(conf->parser); /* identifiers are strings. so check for that type and do * a comparison against our data. */ ! if(atom != PARSER_ATOM_STRING) return NULL; ! string = parser_get_data(conf->parser); i = 0; --- 182,198 ---- arg_symbol_t *identifier_symbol = NULL; const char *string; ! token_t token; const char **ptr; int i; ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); /* identifiers are strings. so check for that type and do * a comparison against our data. */ ! if(token != TOKEN_STRING) return NULL; ! string = tokenizer_get_data(conf->tokenizer); i = 0; *************** *** 220,231 **** eth_addr_t *eth_addr = NULL; const char *string; ! atom_t atom; ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom != PARSER_ATOM_STRING) return NULL; ! string = parser_get_data(conf->parser); if(strchr(string, '.') != NULL) { --- 220,231 ---- eth_addr_t *eth_addr = NULL; const char *string; ! token_t token; ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token != TOKEN_STRING) return NULL; ! string = tokenizer_get_data(conf->tokenizer); if(strchr(string, '.') != NULL) { *************** *** 252,256 **** { uint8_t *placeholder; ! atom_t atom; /* this is fairly easy check if the atom is an assignment and just return an empty placeholder. --- 252,256 ---- { uint8_t *placeholder; ! token_t token; /* this is fairly easy check if the atom is an assignment and just return an empty placeholder. *************** *** 258,264 **** * we may create more. */ ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom != PARSER_ATOM_ASSIGNMENT) return NULL; --- 258,264 ---- * we may create more. */ ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token != TOKEN_ASSIGNMENT) return NULL; *************** *** 271,283 **** { uint8_t *bool_val; ! atom_t atom; const char *string; ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom != PARSER_ATOM_STRING) return NULL; ! string = parser_get_data(conf->parser); if(!strcmp(string, "yes")) { --- 271,283 ---- { uint8_t *bool_val; ! token_t token; const char *string; ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token != TOKEN_STRING) return NULL; ! string = tokenizer_get_data(conf->tokenizer); if(!strcmp(string, "yes")) { *************** *** 304,315 **** char *string_arg; const char *string; ! atom_t atom; ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom != PARSER_ATOM_STRING) return NULL; ! string = parser_get_data(conf->parser); string_arg = xstrdup(string); --- 304,315 ---- char *string_arg; const char *string; ! token_t token; ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token != TOKEN_STRING) return NULL; ! string = tokenizer_get_data(conf->tokenizer); string_arg = xstrdup(string); *************** *** 321,325 **** list_t *string_list = NULL; char *string; ! atom_t atom; /* ask compile_arg_string_list to do the work for us. --- 321,325 ---- list_t *string_list = NULL; char *string; ! token_t token; /* ask compile_arg_string_list to do the work for us. *************** *** 342,349 **** /* now peek for a comma, if available keep going. */ ! atom = parser_peek_next_atom(conf->parser); ! if(atom == PARSER_ATOM_COMMA) { ! atom = get_next_atom_ignore_newlines(conf->parser); } else { --- 342,349 ---- /* now peek for a comma, if available keep going. */ ! token = tokenizer_peek_next_token_ignore_newlines(conf->tokenizer); ! if(token == TOKEN_COMMA) { ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); } else { *************** *** 361,365 **** directive_t *directive; void *args; ! atom_t atom; int i; arg_type_t *arg_type; --- 361,365 ---- directive_t *directive; void *args; ! token_t token; int i; arg_type_t *arg_type; *************** *** 389,394 **** /* we're done. now we need a semicolon to end this directive. */ ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom != PARSER_ATOM_SEMICOLON) { ERROR_MESSAGE("semi colon terminator not present where expected at line: %d\n", conf_get_line_no(conf)); directive_destroy(directive); --- 389,394 ---- /* we're done. now we need a semicolon to end this directive. */ ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token != TOKEN_SEMICOLON) { ERROR_MESSAGE("semi colon terminator not present where expected at line: %d\n", conf_get_line_no(conf)); directive_destroy(directive); *************** *** 408,412 **** /* we expect the string is already read from the parser * before we're called. */ ! token_string = parser_get_data(conf->parser); /* now do a comparison and find our command_t. */ --- 408,412 ---- /* we expect the string is already read from the parser * before we're called. */ ! token_string = tokenizer_get_data(conf->tokenizer); /* now do a comparison and find our command_t. */ *************** *** 435,439 **** static void *compile_arg_group(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { ! atom_t atom; directive_t *directive; list_t *directive_list = NULL; --- 435,439 ---- static void *compile_arg_group(conf_t *conf, const char **argument_strings, const arg_symbol_t *argument_symbols) { ! token_t token; directive_t *directive; list_t *directive_list = NULL; *************** *** 442,448 **** * as per the commands allowed in the group. */ ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom != PARSER_ATOM_BLOCK_OPEN) return NULL; --- 442,448 ---- * as per the commands allowed in the group. */ ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token != TOKEN_BLOCK_OPEN) return NULL; *************** *** 451,461 **** while(1) { ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom == PARSER_ATOM_BLOCK_CLOSE) return directive_list; /* we should always start with a string. */ ! if(atom != PARSER_ATOM_STRING) goto error; --- 451,461 ---- while(1) { ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token == TOKEN_BLOCK_CLOSE) return directive_list; /* we should always start with a string. */ ! if(token != TOKEN_STRING) goto error; *************** *** 501,516 **** { ! atom_t atom; directive_t *directive; while(1) { ! atom = get_next_atom_ignore_newlines(conf->parser); ! if(atom == PARSER_ATOM_EOF) /* end of file */ return CONF_OK; /* we should always start with a string. */ ! if(atom != PARSER_ATOM_STRING) return CONF_ERROR; --- 501,516 ---- { ! token_t token; directive_t *directive; while(1) { ! token = tokenizer_get_next_token_ignore_newlines(conf->tokenizer); ! if(token == TOKEN_EOF) /* end of file */ return CONF_OK; /* we should always start with a string. */ ! if(token != TOKEN_STRING) return CONF_ERROR; *************** *** 536,539 **** int conf_get_line_no(conf_t *conf) { ! return parser_get_line_no(conf->parser); } --- 536,539 ---- int conf_get_line_no(conf_t *conf) { ! return tokenizer_get_line_no(conf->tokenizer); } Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-libutil.h 21 Dec 2002 16:51:53 -0000 1.15 --- dhcp-libutil.h 22 Dec 2002 08:31:30 -0000 1.16 *************** *** 31,34 **** --- 31,35 ---- /* types. */ + /* conf parser types. */ typedef uint32_t command_code_t; typedef uint32_t arg_len_t; *************** *** 36,39 **** --- 37,43 ---- typedef uint8_t arg_symbol_t; + /* tokenizer types. */ + typedef uint8_t token_t; + /* * * * * * * * * * * * Data structures. * *************** *** 41,44 **** --- 45,49 ---- /* native data structures. */ + /* list object. */ typedef struct list { *************** *** 82,91 **** int line_no; stringbuffer *data_buff; ! } parser_t; /* varfile object. */ typedef struct { char *filename; ! parser_t *parser; stringbuffer *var_name; stringbuffer *var_val; --- 87,98 ---- int line_no; stringbuffer *data_buff; ! token_t peek_value; ! uint8_t peeked; ! } tokenizer_t; /* varfile object. */ typedef struct { char *filename; ! tokenizer_t *tokenizer; stringbuffer *var_name; stringbuffer *var_val; *************** *** 116,120 **** typedef struct { char *filename; ! parser_t *parser; const command_t **commands; /* list of permissible commands. */ list_t *directives; --- 123,127 ---- typedef struct { char *filename; ! tokenizer_t *tokenizer; const command_t **commands; /* list of permissible commands. */ list_t *directives; Index: dhcp-varfile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-varfile.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-varfile.c 24 Nov 2002 20:54:31 -0000 1.4 --- dhcp-varfile.c 22 Dec 2002 08:31:30 -0000 1.5 *************** *** 32,36 **** #include "dhcp-libutil.h" ! #include "dhcp-parser.h" const char *varfile_get_name(varfile_t *varfile) --- 32,36 ---- #include "dhcp-libutil.h" ! #include "dhcp-tokenizer.h" const char *varfile_get_name(varfile_t *varfile) *************** *** 46,50 **** int varfile_get_lineno(varfile_t *varfile) { ! return parser_get_line_no(varfile->parser); } --- 46,50 ---- int varfile_get_lineno(varfile_t *varfile) { ! return tokenizer_get_line_no(varfile->tokenizer); } *************** *** 57,61 **** varfile->var_name = create_stringbuffer(); varfile->var_val = create_stringbuffer(); ! varfile->parser = create_parser(filename); varfile->mode = mode; return varfile; --- 57,61 ---- varfile->var_name = create_stringbuffer(); varfile->var_val = create_stringbuffer(); ! varfile->tokenizer = tokenizer_create(filename); varfile->mode = mode; return varfile; *************** *** 64,68 **** void destroy_varfile(varfile_t *varfile) { ! destroy_parser(varfile->parser); destroy_stringbuffer(varfile->var_name); destroy_stringbuffer(varfile->var_val); --- 64,68 ---- void destroy_varfile(varfile_t *varfile) { ! tokenizer_destroy(varfile->tokenizer); destroy_stringbuffer(varfile->var_name); destroy_stringbuffer(varfile->var_val); *************** *** 81,105 **** int varfile_get_next_varnames(varfile_t *varfile) { ! atom_t atom; while(1) { ! atom = get_next_atom(varfile->parser); ! if(atom == PARSER_ATOM_NEWLINE) /* skip empty lines/comments. */ continue; ! if(atom == PARSER_ATOM_EOF) return VARFILE_EOF; ! if(atom != PARSER_ATOM_STRING) return VARFILE_PARSE_ERROR; /* copy string out into varname */ ! stringbuffer_set(varfile->var_name, parser_get_data(varfile->parser)); ! atom = get_next_atom(varfile->parser); /* if we don't get an end of statement or eof here it's a parse error. */ ! if(atom != PARSER_ATOM_NEWLINE && atom != PARSER_ATOM_EOF) return VARFILE_PARSE_ERROR; --- 81,105 ---- int varfile_get_next_varnames(varfile_t *varfile) { ! token_t token; while(1) { ! token = tokenizer_get_next_token(varfile->tokenizer); ! if(token == TOKEN_NEWLINE) /* skip empty lines/comments. */ continue; ! if(token == TOKEN_EOF) return VARFILE_EOF; ! if(token != TOKEN_STRING) return VARFILE_PARSE_ERROR; /* copy string out into varname */ ! stringbuffer_set(varfile->var_name, tokenizer_get_data(varfile->tokenizer)); ! token = tokenizer_get_next_token(varfile->tokenizer); /* if we don't get an end of statement or eof here it's a parse error. */ ! if(token != TOKEN_NEWLINE && token != TOKEN_EOF) return VARFILE_PARSE_ERROR; *************** *** 110,152 **** int varfile_get_next_varval(varfile_t *varfile) { ! atom_t atom; /* get the name first. */ while(1) { ! atom = get_next_atom(varfile->parser); ! if(atom == PARSER_ATOM_NEWLINE) /* skip empty lines/comments. */ continue; ! if(atom == PARSER_ATOM_EOF) return VARFILE_EOF; ! if(atom != PARSER_ATOM_STRING) return VARFILE_PARSE_ERROR; /* copy string out into varname */ ! stringbuffer_set(varfile->var_name, parser_get_data(varfile->parser)); break; } ! atom = get_next_atom(varfile->parser); ! if(atom != PARSER_ATOM_ASSIGNMENT) return VARFILE_PARSE_ERROR; ! atom = get_next_atom(varfile->parser); ! if(atom != PARSER_ATOM_STRING) return VARFILE_PARSE_ERROR; /* copy string out into var val */ ! stringbuffer_set(varfile->var_val, parser_get_data(varfile->parser)); /* now we need a clean end of statement. */ ! atom = get_next_atom(varfile->parser); ! if(atom != PARSER_ATOM_NEWLINE && atom != PARSER_ATOM_EOF) return VARFILE_PARSE_ERROR; --- 110,152 ---- int varfile_get_next_varval(varfile_t *varfile) { ! token_t token; /* get the name first. */ while(1) { ! token = tokenizer_get_next_token(varfile->tokenizer); ! if(token == TOKEN_NEWLINE) /* skip empty lines/comments. */ continue; ! if(token == TOKEN_EOF) return VARFILE_EOF; ! if(token != TOKEN_STRING) return VARFILE_PARSE_ERROR; /* copy string out into varname */ ! stringbuffer_set(varfile->var_name, tokenizer_get_data(varfile->tokenizer)); break; } ! token = tokenizer_get_next_token(varfile->tokenizer); ! if(token != TOKEN_ASSIGNMENT) return VARFILE_PARSE_ERROR; ! token = tokenizer_get_next_token(varfile->tokenizer); ! if(token != TOKEN_STRING) return VARFILE_PARSE_ERROR; /* copy string out into var val */ ! stringbuffer_set(varfile->var_val, tokenizer_get_data(varfile->tokenizer)); /* now we need a clean end of statement. */ ! token = tokenizer_get_next_token(varfile->tokenizer); ! if(token != TOKEN_NEWLINE && token != TOKEN_EOF) return VARFILE_PARSE_ERROR; --- dhcp-parser.c DELETED --- --- dhcp-parser.h DELETED --- |