]>
Commit | Line | Data |
---|---|---|
98bf1607 | 1 | /* |
d122accf | 2 | * Copyright(c) 2009-2010 by Internet Systems Consortium, Inc.("ISC") |
98bf1607 SR |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
14 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | * | |
16 | * Internet Systems Consortium, Inc. | |
17 | * 950 Charter Street | |
18 | * Redwood City, CA 94063 | |
19 | * <info@isc.org> | |
20 | * http://www.isc.org/ | |
21 | * | |
22 | */ | |
23 | ||
24 | /*Trying to figure out what we need to define to get things to work. | |
25 | It looks like we want/need the export library but need the fdwatchcommand | |
26 | which may be a problem */ | |
27 | ||
28 | #include "dhcpd.h" | |
29 | ||
3ac2a573 SR |
30 | #include <sys/time.h> |
31 | ||
98bf1607 SR |
32 | dhcp_context_t dhcp_gbl_ctx; |
33 | ||
34 | void | |
35 | isclib_cleanup(void) | |
36 | { | |
37 | #if defined (NSUPDATE) | |
38 | if (dhcp_gbl_ctx.dnsclient != NULL) | |
39 | dns_client_destroy((dns_client_t **)&dhcp_gbl_ctx.dnsclient); | |
40 | #endif | |
41 | ||
42 | if (dhcp_gbl_ctx.task != NULL) { | |
98bf1607 SR |
43 | isc_task_shutdown(dhcp_gbl_ctx.task); |
44 | isc_task_detach(&dhcp_gbl_ctx.task); | |
45 | } | |
46 | ||
47 | if (dhcp_gbl_ctx.timermgr != NULL) | |
48 | isc_timermgr_destroy(&dhcp_gbl_ctx.timermgr); | |
49 | ||
50 | if (dhcp_gbl_ctx.socketmgr != NULL) | |
51 | isc_socketmgr_destroy(&dhcp_gbl_ctx.socketmgr); | |
52 | ||
53 | if (dhcp_gbl_ctx.taskmgr != NULL) | |
54 | isc_taskmgr_destroy(&dhcp_gbl_ctx.taskmgr); | |
55 | ||
56 | if (dhcp_gbl_ctx.actx_started != ISC_FALSE) { | |
57 | isc_app_ctxfinish(dhcp_gbl_ctx.actx); | |
58 | dhcp_gbl_ctx.actx_started = ISC_FALSE; | |
59 | } | |
60 | ||
61 | if (dhcp_gbl_ctx.actx != NULL) | |
62 | isc_appctx_destroy(&dhcp_gbl_ctx.actx); | |
63 | ||
64 | if (dhcp_gbl_ctx.mctx != NULL) | |
65 | isc_mem_detach(&dhcp_gbl_ctx.mctx); | |
66 | ||
67 | return; | |
68 | } | |
69 | ||
70 | isc_result_t | |
71 | dhcp_context_create(void) { | |
72 | isc_result_t result; | |
73 | ||
74 | /* | |
75 | * Set up the error messages, this isn't the right place | |
76 | * for this call but it is convienent for now. | |
77 | */ | |
78 | result = dhcp_result_register(); | |
79 | if (result != ISC_R_SUCCESS) { | |
80 | log_fatal("register_table() %s: %u", "failed", result); | |
81 | } | |
82 | ||
83 | memset(&dhcp_gbl_ctx, 0, sizeof (dhcp_gbl_ctx)); | |
84 | ||
85 | isc_lib_register(); | |
86 | ||
87 | /* get the current time for use as the random seed */ | |
88 | gettimeofday(&cur_tv, (struct timezone *)0); | |
89 | isc_random_seed(cur_tv.tv_sec); | |
90 | ||
91 | #if defined (NSUPDATE) | |
92 | result = dns_lib_init(); | |
93 | if (result != ISC_R_SUCCESS) | |
94 | goto cleanup; | |
95 | #endif | |
96 | ||
97 | result = isc_mem_create(0, 0, &dhcp_gbl_ctx.mctx); | |
98 | if (result != ISC_R_SUCCESS) | |
99 | goto cleanup; | |
100 | ||
101 | result = isc_appctx_create(dhcp_gbl_ctx.mctx, &dhcp_gbl_ctx.actx); | |
102 | if (result != ISC_R_SUCCESS) | |
103 | goto cleanup; | |
104 | ||
105 | result = isc_app_ctxstart(dhcp_gbl_ctx.actx); | |
106 | if (result != ISC_R_SUCCESS) | |
107 | return (result); | |
108 | dhcp_gbl_ctx.actx_started = ISC_TRUE; | |
109 | ||
110 | result = isc_taskmgr_createinctx(dhcp_gbl_ctx.mctx, | |
111 | dhcp_gbl_ctx.actx, | |
112 | 1, 0, | |
113 | &dhcp_gbl_ctx.taskmgr); | |
114 | if (result != ISC_R_SUCCESS) | |
115 | goto cleanup; | |
116 | ||
117 | result = isc_socketmgr_createinctx(dhcp_gbl_ctx.mctx, | |
118 | dhcp_gbl_ctx.actx, | |
119 | &dhcp_gbl_ctx.socketmgr); | |
120 | if (result != ISC_R_SUCCESS) | |
121 | goto cleanup; | |
122 | ||
123 | result = isc_timermgr_createinctx(dhcp_gbl_ctx.mctx, | |
124 | dhcp_gbl_ctx.actx, | |
125 | &dhcp_gbl_ctx.timermgr); | |
126 | if (result != ISC_R_SUCCESS) | |
127 | goto cleanup; | |
128 | ||
fe4b839a | 129 | result = isc_task_create(dhcp_gbl_ctx.taskmgr, 0, &dhcp_gbl_ctx.task); |
98bf1607 SR |
130 | if (result != ISC_R_SUCCESS) |
131 | goto cleanup; | |
132 | ||
133 | #if defined (NSUPDATE) | |
134 | result = dns_client_createx(dhcp_gbl_ctx.mctx, | |
135 | dhcp_gbl_ctx.actx, | |
136 | dhcp_gbl_ctx.taskmgr, | |
137 | dhcp_gbl_ctx.socketmgr, | |
138 | dhcp_gbl_ctx.timermgr, | |
139 | 0, | |
140 | &dhcp_gbl_ctx.dnsclient); | |
141 | if (result != ISC_R_SUCCESS) | |
142 | goto cleanup; | |
143 | #else | |
144 | /* The dst library is inited as part of dns_lib_init, we don't | |
145 | * need it if NSUPDATE is enabled */ | |
146 | result = dst_lib_init(dhcp_gbl_ctx.mctx, NULL, 0); | |
147 | if (result != ISC_R_SUCCESS) | |
148 | goto cleanup; | |
149 | ||
150 | #endif | |
151 | return(ISC_R_SUCCESS); | |
152 | ||
153 | cleanup: | |
d122accf SR |
154 | /* |
155 | * Currently we don't try and cleanup, just return an error | |
156 | * expecting that our caller will log the error and exit. | |
157 | */ | |
98bf1607 SR |
158 | |
159 | return(result); | |
160 | } | |
161 | ||
f4bc8261 SR |
162 | /* |
163 | * Convert a string name into the proper structure for the isc routines | |
164 | * | |
165 | * Previously we allowed names without a trailing '.' however the current | |
166 | * dns and dst code requires the names to end in a period. If the | |
167 | * name doesn't have a trailing period add one as part of creating | |
168 | * the dns name. | |
169 | */ | |
170 | ||
98bf1607 SR |
171 | isc_result_t |
172 | dhcp_isc_name(unsigned char *namestr, | |
173 | dns_fixedname_t *namefix, | |
174 | dns_name_t **name) | |
175 | { | |
176 | size_t namelen; | |
177 | isc_buffer_t b; | |
178 | isc_result_t result; | |
f4bc8261 | 179 | |
98bf1607 SR |
180 | namelen = strlen((char *)namestr); |
181 | isc_buffer_init(&b, namestr, namelen); | |
182 | isc_buffer_add(&b, namelen); | |
183 | dns_fixedname_init(namefix); | |
184 | *name = dns_fixedname_name(namefix); | |
f4bc8261 | 185 | result = dns_name_fromtext(*name, &b, dns_rootname, 0, NULL); |
98bf1607 SR |
186 | isc_buffer_invalidate(&b); |
187 | return(result); | |
188 | } | |
189 | ||
190 | isc_result_t | |
191 | isclib_make_dst_key(char *inname, | |
192 | char *algorithm, | |
193 | unsigned char *secret, | |
194 | int length, | |
195 | dst_key_t **dstkey) | |
196 | { | |
197 | isc_result_t result; | |
198 | dns_name_t *name; | |
199 | dns_fixedname_t name0; | |
200 | isc_buffer_t b; | |
98bf1607 SR |
201 | |
202 | isc_buffer_init(&b, secret, length); | |
203 | isc_buffer_add(&b, length); | |
204 | ||
205 | /* We only support HMAC_MD5 currently */ | |
206 | if (strcasecmp(algorithm, DHCP_HMAC_MD5_NAME) != 0) { | |
207 | return(DHCP_R_INVALIDARG); | |
208 | } | |
209 | ||
f4bc8261 | 210 | result = dhcp_isc_name((unsigned char *)inname, &name0, &name); |
98bf1607 SR |
211 | if (result != ISC_R_SUCCESS) { |
212 | return(result); | |
213 | } | |
214 | ||
215 | return(dst_key_frombuffer(name, DST_ALG_HMACMD5, DNS_KEYOWNER_ENTITY, | |
216 | DNS_KEYPROTO_DNSSEC, dns_rdataclass_in, | |
217 | &b, dhcp_gbl_ctx.mctx, dstkey)); | |
218 | } | |
219 |