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

« back to all changes in this revision

Viewing changes to .pc/config_pollution.patch/deadwood-3.2.07/src/DwMain.c

  • 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
#include <stdio.h>
 
20
#include <signal.h>
 
21
#include "DwSocket.h"
 
22
#include "DwTcpSocket.h"
 
23
#include "DwSys.h"
 
24
#include "version.h"
 
25
 
 
26
extern int32_t key_n[];
 
27
 
 
28
#ifdef MINGW
 
29
void windows_socket_start() {
 
30
        WSADATA wsaData;
 
31
        WORD wVersionRequested = MAKEWORD(2,2);
 
32
        WSAStartup( wVersionRequested, &wsaData);
 
33
}
 
34
#ifdef IPV6
 
35
ipv6_not_supported_on_windows_build;
 
36
#endif /* IPV6 */
 
37
#endif /* MINGW */
 
38
 
 
39
void usage() {
 
40
        printf("Usage: Deadwood [-f dwood3rc]\n");
 
41
        exit(1);
 
42
}
 
43
 
 
44
/* Show the name of the program */
 
45
void dw_show_programname() {
 
46
#ifdef IPV6
 
47
        dw_log_string(
 
48
        "Deadwood: A DNS UDP non-recursive cache (IPv6 supported)",1);
 
49
#else /* IPV6 */
 
50
        dw_log_string(
 
51
        "Deadwood: A DNS UDP non-recursive cache (IPv4-only)",1);
 
52
#endif /* IPV6 */
 
53
}
 
54
 
 
55
/* Parse command-line arguments given to server */
 
56
void dw_parse_args(int argc, char **argv) {
 
57
        if(argc != 1 && argc != 3) {
 
58
                usage();
 
59
        } else if(argc == 3) {
 
60
                if(argv[1] == 0 || argv[2] == 0) {
 
61
                        usage();
 
62
                } if(*(argv[1]) != '-' || *(argv[1] + 1) != 'f' ||
 
63
                     *(argv[1] + 2) != 0) {
 
64
                        usage();
 
65
                }
 
66
                process_mararc(argv[2]);
 
67
        } else {
 
68
#ifndef MINGW
 
69
                process_mararc("/etc/dwood3rc");
 
70
#else /* MINGW */
 
71
                process_mararc("dwood3rc.txt");
 
72
#endif /* MINGW */
 
73
        }
 
74
}
 
75
 
 
76
/* DNS non-recursive caching server */
 
77
int dw_udp_main(int argc, char **argv) {
 
78
        int bind_count = 0; /* Number of IPs we bound to */
 
79
        set_add_constant(); /* Has to be done before processing mararc */
 
80
        dw_parse_args(argc,argv);
 
81
        dw_show_programname();
 
82
        process_mararc_params();
 
83
#ifdef MINGW
 
84
        windows_socket_start();
 
85
#else
 
86
        setup_signals();
 
87
        signal(SIGPIPE, SIG_IGN); /* *NIX security bug workaround */
 
88
#endif /* MINGW */
 
89
        dw_log_number("Verbose_level set to ",key_n[DWM_N_verbose_level]
 
90
                      ,"",4);
 
91
        /* Bind to all UDP sockets */
 
92
        bind_count = bind_all_udp();
 
93
        if(bind_count > 0) {
 
94
                dw_log_number("We bound to ",bind_count," addresses",1);
 
95
        } else {
 
96
                dw_fatal("Unable to bind to any IP addresses (UDP)");
 
97
        }
 
98
        /* Bind to all TCP sockets */
 
99
        bind_count = bind_all_tcp();
 
100
        if(bind_count <= 0 && key_n[DWM_N_tcp_listen] == 1) {
 
101
                dw_fatal("Unable to bind to any IP addresses (TCP)");
 
102
        }
 
103
        /* Initialize "inflight" hash */
 
104
        init_inflight_hash();
 
105
#ifdef MINGW
 
106
        fflush(stdout);
 
107
#endif /* MINGW */
 
108
        init_rng();
 
109
        sandbox();
 
110
        init_cache();
 
111
        process_root_upstream();
 
112
        malloc_tcp_pend();
 
113
        init_tcp_b_pend();
 
114
        init_b_remote();
 
115
        bigloop();
 
116
        return 0;
 
117
}
 
118
 
 
119
/* Make -Wall happy */
 
120
extern int dw_tcp_main(int argc, char **argv);
 
121
/* Combined binary: Have DwUdp and DwTcp be the same program */
 
122
 
 
123
#ifndef MINGW
 
124
int main(int argc, char **argv) {
 
125
#else /* MINGW */
 
126
int dw_svc_main(int argc, char **argv) {
 
127
#endif /* MINGW */
 
128
        char *a = 0, *b = 0;
 
129
        int c = 0;
 
130
        dw_alog_3strings("Deadwood version ",VERSION,"");
 
131
        if(argv[0] == 0) {
 
132
                dw_alog_3strings("Don't invoke this program without ",
 
133
                        "argv[0] ","set");
 
134
                exit(1);
 
135
        }
 
136
        a = argv[0];
 
137
 
 
138
        /* Have 'a' point to the first character in the basename */
 
139
        while(*a != 0 && c < 250) {
 
140
                if(*a == '/' || *a == '\\') {
 
141
                        b = a;
 
142
                }
 
143
                a++;
 
144
                c++;
 
145
        }
 
146
        if(b != 0) {
 
147
                a = b + 1;
 
148
        } else {
 
149
                a = argv[0];
 
150
        }
 
151
 
 
152
        if((*a == 'D' || *a == 'd') && *(a+1) == 'w' && (*(a+2) == 'T' ||
 
153
           *(a+2) == 't')) {
 
154
                printf("Deadwood now has TCP support; DwTcp isn't needed\n");
 
155
                exit(1);
 
156
        }
 
157
        dw_udp_main(argc,argv);
 
158
        return 0;
 
159
}
 
160