~ubuntu-branches/ubuntu/wily/maradns/wily-proposed

« back to all changes in this revision

Viewing changes to deadwood-3.2.05/src/DwSys.h

  • Committer: Package Import Robot
  • Author(s): Dariusz Dwornikowski, Tomasz Buchert, Dariusz Dwornikowski
  • Date: 2015-03-27 18:34:08 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20150327183408-wnfachdkdjt96yu6
Tags: 2.0.11-1
[ Tomasz Buchert ]
* Imported Upstream version 2.0.11

[ Dariusz Dwornikowski ]
* d/patches: 
  - refreshed all patches for new deadwood version
  - removed generating of random prime on build (Closes: #785536) 
* d/rules: date taken from changelog (Closes: #785535)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2007-2010 Sam Trenholme
2
 
 *
3
 
 * TERMS
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions
7
 
 * are met:
8
 
 *
9
 
 * 1. Redistributions of source code must retain the above copyright
10
 
 *    notice, this list of conditions and the following disclaimer.
11
 
 * 2. Redistributions in binary form must reproduce the above copyright
12
 
 *    notice, this list of conditions and the following disclaimer in the
13
 
 *    documentation and/or other materials provided with the distribution.
14
 
 *
15
 
 * This software is provided 'as is' with no guarantees of correctness or
16
 
 * fitness for purpose.
17
 
 */
18
 
 
19
 
#ifndef __DWSYS_H_DEFINED__
20
 
#define __DWSYS_H_DEFINED__
21
 
 
22
 
#ifndef MINGW
23
 
#include <grp.h>
24
 
#endif /* MINGW */
25
 
#include <stdio.h>
26
 
#include <string.h>
27
 
#include <unistd.h>
28
 
#include <fcntl.h>
29
 
#include <time.h>
30
 
#include "DwSocket.h"
31
 
 
32
 
/* Parameters that are currently hardcoded in the source code (This will
33
 
 * change once we get something very basic that works) */
34
 
 
35
 
#define DW_UID 99      /* UID that we run as */
36
 
#define DW_MINTIME 1178488417 /* Minimum allowed timestamp */
37
 
 
38
 
/* Make this look like a function just in case we need to make it
39
 
 * a function to make things thread-safe */
40
 
#define get_time() the_time
41
 
 
42
 
/* These are public functions */
43
 
 
44
 
/* Initialize the log */
45
 
void dw_log_init();
46
 
 
47
 
#ifdef MINGW
48
 
void dw_tcp_log_init();
49
 
#endif /* MINGW */
50
 
 
51
 
/* Close the log */
52
 
void dw_log_close();
53
 
 
54
 
/* Log a char followed by an IP */
55
 
void dw_log_ip(char *string, ip_addr_T *ip, int min_log_level);
56
 
 
57
 
/* Log a string followed by the contents of a DwStr object */
58
 
void dw_log_dwstr(char *s1, dw_str *s2, int min_log_level);
59
 
 
60
 
/* Log a string followed by the contents of a DwStr object followed by
61
 
 * another string */
62
 
void dw_log_dwstr_str(char *s1, dw_str *s2, char *s3, int min_log_level);
63
 
 
64
 
/* Log a string; input: String to log; minimum log level that we log this
65
 
 * string at */
66
 
void dw_log_string(char *string, int min_log_level);
67
 
 
68
 
/* Log 3 strings; input: Strings to log; minimum log level that we log these
69
 
 * strings at */
70
 
void dw_log_3strings(char *s1, char *s2, char *s3, int min_log_level);
71
 
 
72
 
/* Log a string, a number, and a string
73
 
 * input: String #1, Number, and String #2 to log;
74
 
 * minimum log level that we log this at */
75
 
void dw_log_number(char *s1, int number, char *s2, int min_log_level);
76
 
 
77
 
/* Log a string and a number in hex */
78
 
void dw_log_hex(char *s1, uint32_t number, int min_log_level);
79
 
 
80
 
/* Log 3 strings; input: Strings to log; minimum log level that we log these
81
 
 * strings at; this always logs and is run before Dwood2rc file is parsed */
82
 
void dw_alog_3strings(char *s1, char *s2, char *s3);
83
 
 
84
 
/* Log a string, a number, and a string
85
 
 * input: String #1, Number, and String #2 to log;
86
 
 * minimum log level that we log this at
87
 
 * This always logs and is run before Dwood2rc file is fully parsed */
88
 
void dw_alog_number(char *s1, int number, char *s2);
89
 
 
90
 
/* Exit with a fatal error and log it */
91
 
void dw_fatal(char *why);
92
 
 
93
 
/* Set the 64-bit timestamp starting at 290805600 unix() time (When
94
 
 * the Blake's 7 episode Gambit was originally broadcast); this should
95
 
 * be called once a second or so */
96
 
void set_time();
97
 
 
98
 
/* Read mararc parameters and set global variables based on those
99
 
 * parameters */
100
 
void process_mararc();
101
 
 
102
 
/* Initialize the cache */
103
 
void init_cache();
104
 
 
105
 
#ifndef MINGW
106
 
/* Assign handlers for TERM, HUP, and USR1 signals, so we can write
107
 
 * the cache to a file */
108
 
void setup_signals();
109
 
#endif /* MINGW */
110
 
 
111
 
/* Process a signal received, writing the cache to a file */
112
 
void process_signal(int number);
113
 
 
114
 
/* Initialize random number generator.  */
115
 
void init_rng();
116
 
 
117
 
/* Drop privileges and become unprivileged user */
118
 
void sandbox();
119
 
 
120
 
/* Get, from the Mararc parameters, the list of bind addresses
121
 
 * we will bind to; return this list as a comma-separated dw_str */
122
 
dw_str *get_bind_addrs();
123
 
 
124
 
/* Make sure a DNS packet is sane, and return the packet's
125
 
 * query ID.  If roy_arends_check has a value of 1, we also make sure
126
 
 * it's a DNS question (and not a reply).  This is named in honor of
127
 
 * Roy Arends, who pointed out the original MaraDNS didn't check this.
128
 
 * If this returns -1, the packet was not sane */
129
 
int32_t get_dns_qid(unsigned char *a, int len, int roy_arends_check);
130
 
 
131
 
/* Given a string with a DNS packet, and the length of that string,
132
 
 * make the first two butes of the packet (the query ID) the third
133
 
 * argument (qid), and return that random number. -1 on error */
134
 
int32_t set_dns_qid(unsigned char *packet, int len, uint16_t qid);
135
 
 
136
 
/* This function converts a dw_str object in to a null-terminated
137
 
 * C-string with the last item in the comma-separated list in the
138
 
 * dw_str, with any leading whitespace in the last item removed */
139
 
char *pop_last_item(dw_str *list);
140
 
 
141
 
/* This creates a netmask from a single number, storing the number in a
142
 
 * string of octets.  0 just makes the string all 0s; 1 makes the string
143
 
 * 0x80 0x00 0x00 etc.; 2 makes the string 0xc0 0x00 etc.; etc.
144
 
 * The string of octets has a length len (4 for ipv4; 16 for ipv6) */
145
 
void make_netmask(int num, uint8_t *str, int len);
146
 
 
147
 
/* Get a numeric value from the mararc parameters and make sure it is
148
 
 * within a range; if def is not -1, make an out-of-range parameter
149
 
 * the def value */
150
 
int32_t get_key_n(int32_t get, int32_t min, int32_t max, int32_t def);
151
 
 
152
 
#endif /* __DWSYS_H_DEFINED__ */
153