39 for (sp = s; sp && *sp; sp++) {
42 else if (!isascii ((
int)*sp) || !isprint ((
int)*sp))
44 else if (*sp ==
'"' || *sp ==
'\\')
53 for (sp = s; sp && *sp; sp++) {
56 else if (!isascii ((
int)*sp) || !isprint ((
int)*sp)) {
57 sprintf (nsp,
"\\%03o",
58 *(
const unsigned char *)sp);
60 }
else if (*sp ==
'"' || *sp ==
'\\') {
71char *
quotify_buf (
const unsigned char *s,
unsigned len,
char enclose_char,
78 for (i = 0; i < len; i++) {
81 else if (!isascii (s [i]) || !isprint (s [i]))
83 else if (s [i] ==
'"' || s [i] ==
'\\')
97 *nsp++ = enclose_char;
100 for (i = 0; i < len; i++) {
103 else if (!isascii (s [i]) || !isprint (s [i])) {
104 sprintf (nsp,
"\\%03o", s [i]);
106 }
else if (s [i] ==
'"' || s [i] ==
'\\') {
114 *nsp++ = enclose_char;
128 static char to64 [] =
129 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
131 bl = ((len * 4 + 2) / 3) + 1;
144 *s++ = to64 [extra << 4];
148 val = (extra << 8) + buf [i++];
153 *s++ = to64 [extra << 2];
157 val = (extra << 8) + buf [i++];
174 const unsigned char *data;
176 static char habuf [49];
184 for (i = 0; i < hlen; i++) {
185 sprintf (s,
"%02x", data [i]);
203 t = gmtime (&
lease -> starts);
204 strftime (tbuf,
sizeof tbuf,
"%Y/%m/%d %H:%M:%S", t);
207 t = gmtime (&
lease -> ends);
208 strftime (tbuf,
sizeof tbuf,
"%Y/%m/%d %H:%M:%S", t);
211 if (
lease -> hardware_addr.hlen)
214 lease -> hardware_addr.hlen - 1,
215 &
lease -> hardware_addr.hbuf [1]));
217 lease -> host ?
lease -> host -> name :
"<none>");
220#if defined (DEBUG_PACKET)
230 const char *name, *dot;
232 memset (&ds, 0,
sizeof ds);
242 in_options, cfg_options, scope, oc,
MDL)) {
244 name, dot, oc ->
option -> name,
246 ds.data, ds.len, 1, 1));
256 log_debug (
"packet length %d", tp -> packet_length);
257 log_debug (
"op = %d htype = %d hlen = %d hops = %d",
259 log_debug (
"xid = %x secs = %ld flags = %x",
265 log_debug (
"chaddr = %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
266 ((
unsigned char *)(tdp ->
chaddr)) [0],
267 ((
unsigned char *)(tdp ->
chaddr)) [1],
268 ((
unsigned char *)(tdp ->
chaddr)) [2],
269 ((
unsigned char *)(tdp ->
chaddr)) [3],
270 ((
unsigned char *)(tdp ->
chaddr)) [4],
271 ((
unsigned char *)(tdp ->
chaddr)) [5]);
274 if (tp -> options_valid) {
294 const unsigned char *buf;
307 memset(lbuf,
' ', 79);
310 for (i = 0; i < len; i++) {
319 memset(lbuf,
' ', 79);
321 sprintf (lbuf,
"%03x:", i);
323 }
else if ((i & 7) == 0)
326 if(isprint(buf[i])) {
327 lbuf[56+(i%16)]=buf[i];
332 sprintf (&lbuf [lbix],
" %02x", buf [i]);
353 for (i = 0; i < table -> hash_count; i++) {
354 if (!table -> buckets [i])
357 for (bp = table -> buckets [i]; bp; bp = bp ->
next) {
382 const u_int8_t *data;
389 if (data == NULL || bufptr == NULL || limit == 0) {
393 if (((
len == 0) || ((
len * 3) > limit))) {
398 for ( ;
byte <
len; ++byte) {
403 sprintf(bufptr,
"%02x", data[
byte]);
421 const u_int8_t *data;
426 if ((buf == NULL) || (limit < 3))
429 for (i = 0; (i < (limit - 3)) && (i <
len); i++) {
430 if (!isascii(data[i]) || !isprint(data[i])) {
440 memcpy(&buf[1], data, i);
458 const u_int8_t *data;
462 static char hex_buf_1[
HBLEN + 1];
463 static char hex_buf_2[
HBLEN + 1];
464 static char hex_buf_3[
HBLEN + 1];
470 if (limit >=
sizeof(hex_buf_1))
471 limit =
sizeof(hex_buf_1);
475 if (limit >=
sizeof(hex_buf_2))
476 limit =
sizeof(hex_buf_2);
480 if (limit >=
sizeof(hex_buf_3))
481 limit =
sizeof(hex_buf_3);
495 const u_int8_t *data;
497 static char dq_buf [
DQLEN + 1];
511 sprintf (s,
"%u.%u.%u.%u, ",
512 data [i], data [i + 1], data [i + 2], data [i + 3]);
515 }
while ((s - &dq_buf [0] >
DQLEN - 21) &&
527 static char vbuf [32];
528 sprintf (vbuf,
"%lu", val);
535 static char vbuf [32];
536 sprintf (vbuf,
"%lu", val);
540static unsigned print_subexpression (
struct expression *,
char *,
unsigned);
542static unsigned print_subexpression (expr, buf,
len)
550 switch (expr ->
op) {
560 strcpy (buf,
"(match)");
566 rv = 10 + strlen (expr ->
data.
check -> name);
568 sprintf (buf,
"(check %s)",
577 strcpy (buf,
"(eq ");
578 rv += print_subexpression (expr ->
data.
equal [0],
579 buf + rv, len - rv - 2);
581 rv += print_subexpression (expr ->
data.
equal [1],
582 buf + rv, len - rv - 1);
592 strcpy (buf,
"(neq ");
593 rv += print_subexpression (expr ->
data.
equal [0],
594 buf + rv, len - rv - 2);
596 rv += print_subexpression (expr ->
data.
equal [1],
597 buf + rv, len - rv - 1);
607 strcpy(buf,
"(regex ");
608 rv += print_subexpression(expr->
data.
equal[0],
609 buf + rv, len - rv - 2);
611 rv += print_subexpression(expr->
data.
equal[1],
612 buf + rv, len - rv - 1);
622 strcpy (buf,
"(substr ");
624 buf + rv, len - rv - 3);
626 rv += print_subexpression
628 buf + rv, len - rv - 2);
631 buf + rv, len - rv - 1);
641 strcpy (buf,
"(suffix ");
643 buf + rv, len - rv - 2);
647 buf + rv, len - rv - 1);
658 strcpy(buf,
"(lcase ");
659 rv += print_subexpression(expr->
data.
lcase,
660 buf + rv, len - rv - 1);
670 strcpy(buf,
"(ucase ");
671 rv += print_subexpression(expr->
data.
ucase,
672 buf + rv, len - rv - 1);
682 strcpy (buf,
"(concat ");
683 rv += print_subexpression (expr ->
data.
concat [0],
684 buf + rv, len - rv - 2);
686 rv += print_subexpression (expr ->
data.
concat [1],
687 buf + rv, len - rv - 1);
697 strcpy (buf,
"(pick1st ");
698 rv += print_subexpression
700 buf + rv, len - rv - 2);
702 rv += print_subexpression
704 buf + rv, len - rv - 1);
714 sprintf (buf,
"(dns-lookup %s)",
726 strcpy (&buf [1], s);
729 rv += print_subexpression (expr ->
data.
and [0],
730 buf + rv, len - rv - 2);
732 rv += print_subexpression (expr ->
data.
and [1],
733 buf + rv, len - rv - 1);
779 strcpy (buf,
"(not ");
780 rv += print_subexpression (expr ->
data.
not,
781 buf + rv, len - rv - 1);
795 rv = strlen (s) + 2 + (strlen (expr ->
data.
option -> name) +
798 sprintf (buf,
"(option %s.%s)",
807 strcpy (buf,
"(hardware)");
815 strcpy (buf,
"(substr ");
817 buf + rv, len - rv - 2);
820 buf + rv, len - rv - 1);
833 strncpy (buf, s, rv);
839 strcpy (buf,
"(encapsulate ");
852 strcpy (buf,
"(int8 ");
854 buf + rv, len - rv - 1);
864 strcpy (buf,
"(int16 ");
866 buf + rv, len - rv - 1);
876 strcpy (buf,
"(int32 ");
878 buf + rv, len - rv - 1);
888 strcpy (buf,
"(to-int8 ");
890 buf + rv, len - rv - 1);
900 strcpy (buf,
"(to-int16 ");
902 buf + rv, len - rv - 1);
912 strcpy (buf,
"(to-int32 ");
914 buf + rv, len - rv - 1);
931 rv = 10 + (strlen (expr ->
data.
option -> name) +
934 sprintf (buf,
"(exists %s.%s)",
968 s =
"leased-address";
976 s =
"host-decl-name";
998 strcpy (buf,
"(reverse ");
1000 buf + rv, len - rv - 2);
1003 buf + rv, len - rv - 1);
1013 strcpy (buf,
"(b2a ");
1015 buf + rv, len - rv - 4);
1018 buf + rv, len - rv - 3);
1021 buf + rv, len - rv - 2);
1024 buf + rv, len - rv - 1);
1035 strcpy (&buf [1],
"ns-update ");
1036 while (len < rv + 2) {
1037 rv += print_subexpression
1039 buf + rv, len - rv - 2);
1066 if (len > strlen (s) + 1) {
1068 strcpy (buf + 1, s);
1072 if (len > rv + strlen (s) + left) {
1073 strcpy (&buf [rv], s);
1074 rv += strlen (&buf [rv]);
1079 if (len > rv + strlen (s) + left) {
1080 strcpy (&buf [rv], s);
1081 rv += strlen (&buf [rv]);
1085 rv += print_subexpression
1087 buf + rv, len - rv - left);
1090 rv += print_subexpression
1092 buf + rv, len - rv - left);
1095 rv += print_subexpression
1097 buf + rv, len - rv - left);
1106 strcpy (buf,
"(null)");
1113 strcpy (buf,
"(funcall ");
1116 rv += print_subexpression
1126 rv = print_subexpression (expr ->
data.
arg.
val, buf, len);
1141 strcpy (buf,
"(function");
1142 for (foo = expr -> data.func -> args;
1143 foo; foo = foo ->
next) {
1144 if (len > rv + 2 + strlen (foo ->
string)) {
1146 strcpy (&buf [rv], foo ->
string);
1147 rv += strlen (foo ->
string);
1158 strcpy(buf,
"(gethostname)");
1164 log_fatal(
"Impossible case at %s:%d (undefined expression "
1165 "%d).",
MDL, expr->
op);
1177 print_subexpression (expr, buf,
sizeof buf);
1183 const char *suffix, ...)
1189 va_start (list, suffix);
1190 s = va_arg (list,
char *);
1194 s = va_arg (list,
char *);
1200 log_fatal (
"token_print_indent: no memory for copy buffer");
1202 va_start (list, suffix);
1203 s = va_arg (list,
char *);
1209 s = va_arg (list,
char *);
1220 const char *prefix,
const char *suffix,
1228 for (i = 0; i <
data -> len; i++)
1234 if (i ==
data -> len) {
1239 buf [
data -> len + 1] =
'"';
1240 buf [
data -> len + 2] = 0;
1242 prefix, suffix, buf);
1248 for (i = 0; i <
data -> len; i++) {
1249 sprintf (obuf,
"%2.2x",
data ->
data [i]);
1251 i == 0 ? prefix :
"",
1252 (i + 1 ==
data -> len
1255 if (i + 1 !=
data -> len)
1257 prefix, suffix,
":");
1264 const char *suffix,
const char *buf)
1268 len += strlen (prefix);
1270 len += strlen (buf);
1272 if (col + len > 79) {
1278 col = len > 79 ? 0 : 79 - len - 1;
1280 }
else if (prefix && *prefix) {
1281 fputs (prefix,
file);
1282 col += strlen (prefix);
1284 if ((buf != NULL) && (*buf != 0)) {
1288 if (suffix && *suffix) {
1289 if (col + strlen (suffix) > 79) {
1293 fputs (suffix,
file);
1294 col += strlen (suffix);
1304 for (i = 0; i <
indent; i++)
1314 static char buf[
sizeof(
"epoch 9223372036854775807; "
1315 "# Wed Jun 30 21:49:08 2147483647")];
1316 static char buf1[
sizeof(
"# Wed Jun 30 21:49:08 2147483647")];
1333#if (MAX_TIME > 0x7fffffffffffffff)
1334 if (t > 0x7fffffffffffffff)
1339 since_epoch = mktime(localtime(&t));
1340 if ((strftime(buf1,
sizeof(buf1),
1341 "# %a %b %d %H:%M:%S %Y",
1342 localtime(&t)) == 0) ||
1343 (snprintf(buf,
sizeof(buf),
"epoch %lu; %s",
1344 (
unsigned long)since_epoch, buf1) >=
sizeof(buf)))
1351 if (strftime(buf,
sizeof(buf),
"%w %Y/%m/%d %H:%M:%S;",
1428 int format,
const char *
file,
int line) {
1454 char *abspath = NULL;
1462 if (realpath(orgpath, buf) == NULL) {
1463 const char* errmsg = strerror(errno);
1464 log_fatal(
"Failed to get realpath for %s: %s",
1470 if (abspath == NULL) {
1471 log_fatal(
"No memory for filename:%s\n",
1475 memcpy (abspath, buf, strlen(buf));
1476 abspath[strlen(buf)] = 0x0;
void data_string_forget(struct data_string *data, const char *file, int line)
const char * pretty_print_option(struct option *option, const unsigned char *data, unsigned len, int emit_commas, int emit_quotes)
void option_space_foreach(struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void(*func)(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *))
char * format_lease_id(const unsigned char *s, unsigned len, int format, const char *file, int line)
int token_indent_data_string(FILE *file, int col, int indent, const char *prefix, const char *suffix, struct data_string *data)
char * print_dec_1(unsigned long val)
int token_print_indent_concat(FILE *file, int col, int indent, const char *prefix, const char *suffix,...)
void print_expression(char *name, struct expression *expr) const
char * quotify_string(const char *s, const char *file, int line)
char * print_dotted_quads(unsigned len, const u_int8_t *data)
char * print_hex(unsigned len, const u_int8_t *data, unsigned limit, unsigned buf_num)
void indent_spaces(FILE *file, int indent)
void hash_dump(struct hash_table *table)
char * print_dec_2(unsigned long val)
char * buf_to_hex(const unsigned char *s, unsigned len, const char *file, int line)
char * print_base64(const unsigned char *buf, unsigned len, const char *file, int line)
void print_lease(struct lease *lease)
void print_hex_or_string(unsigned len, const u_int8_t *data, unsigned limit, char *buf)
char * quotify_buf(const unsigned char *s, unsigned len, char enclose_char, const char *file, int line)
char * print_hw_addr(int htype, const int hlen, const unsigned char *data) const
char * absolute_path(const char *orgpath)
const char * print_time(TIME t)
int token_print_indent(FILE *file, int col, int indent, const char *prefix, const char *suffix, const char *buf)
void print_hex_only(unsigned len, const u_int8_t *data, unsigned limit, char *buf)
void dump_raw(unsigned char *buf, unsigned len) const
#define DEFAULT_TIME_FORMAT
void dump_packet_option(struct option_cache *, struct packet *, struct lease *, struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)
void dump_packet(struct packet *)
#define LOCAL_TIME_FORMAT
struct universe dhcp_universe
#define print_hex_1(len, data, limit)
struct iaddr ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address)
const char * piaddr(const struct iaddr addr)
void * dmalloc(size_t, const char *, int)
void dfree(void *, const char *, int)
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__
const unsigned char * data
unsigned char options[DHCP_MAX_OPTION_LEN]
char sname[DHCP_SNAME_LEN]
union expression::expr_union data
struct hash_bucket * next
const unsigned char * name
struct string_list * next
struct universe ** universes
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
struct binding_scope * global_scope
@ expr_variable_reference
struct expression * rrname
struct dns_host_entry * host_lookup
struct expression * extract_int
struct expression * ucase
struct expression::expr_union::@152152363213031317102070271074050115327136262165 substring
struct expression::expr_union::@142357143130043056032332065103331215371345065324 b2a
struct expression * rrdata
struct collection * check
struct expression * arglist
struct expression::expr_union::@153372267152270265274174275371207324115325231106 pick_first_value
struct expression * encode_int
struct data_string encapsulate
struct expression::expr_union::@361336052365376347372225147374123322154377006046 packet
struct expression::expr_union::@033056357357350044132160223061265122134157022063 dns_transaction
struct expression * and[2]
struct expression::expr_union::@321342175326372274026022043045233256003206100043 funcall
struct expression * separator
struct expression::expr_union::@245157277262265343375031324341307155317045004360 suffix
struct expression::expr_union::@210072170212011073140317037141257070237041140331 reverse
struct expression * lcase
struct data_string const_data
struct expression::expr_union::@155243052250312351005066334172140274044155221273 arg
struct expression * offset
struct expression::expr_union::@015162122113255073234214372022223270363074150272 ns_add
struct expression * width
struct expression * buffer
struct expression * concat[2]
struct expression * equal[2]