Print this page
5910 libnisdb won't build with modern GCC
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libnisdb/yptol/map_conv.c
+++ new/usr/src/lib/libnisdb/yptol/map_conv.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 + * Copyright 2015 Gary Mills
23 24 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 25 * Use is subject to license terms.
25 26 */
26 27
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 28 /*
30 29 * DESCRIPTION: Contains functions relating to movement of entire maps.
31 30 */
32 31
33 32 #include <unistd.h>
34 33 #include <syslog.h>
35 34 #include <ndbm.h>
36 35 #include <string.h>
37 36 #include "ypsym.h"
38 37 #include "ypdefs.h"
39 38 #include "shim.h"
40 39 #include "yptol.h"
41 40 #include "../ldap_util.h"
42 41
43 42 /*
44 43 * Switch on parts of ypdefs.h
45 44 */
46 45 USE_YPDBPATH
47 -USE_DBM
48 46
49 47 /*
50 48 * Decs
51 49 */
52 50 void add_separator(char *);
53 51 suc_code dump_domain_to_dit(char *, bool_t);
54 52 suc_code dump_map_to_dit(char *, char *, bool_t);
55 53 suc_code dump_maps_to_dit(bool_t);
56 54 suc_code dump_dit_to_map();
57 55 suc_code dump_dit_to_maps();
58 56
59 57 /*
60 58 * FUNCTION : dump_maps_to_dit()
61 59 *
62 60 * DESCRIPTION: Dump all the OLD STYLE NIS maps into the DIT.
63 61 *
64 62 * Since the DIT is not yet set up details about which maps and
65 63 * domains exist are gathered from the N2L config file and the
66 64 * existing map files.
67 65 *
68 66 * GIVEN : Flag indicating if containers and domains should be set up.
69 67 *
70 68 * RETURNS : Success code
71 69 */
72 70 suc_code
73 71 dump_maps_to_dit(bool_t init_containers)
74 72 {
75 73 char **dom_list;
76 74 int num_doms, i;
77 75
78 76 num_doms = get_mapping_domain_list(&dom_list);
79 77
80 78 /* Dump all domains in list */
81 79 for (i = 0; i < num_doms; i++) {
82 80 if (FAILURE == dump_domain_to_dit(dom_list[i], init_containers))
83 81 return (FAILURE);
84 82 }
85 83
86 84 return (SUCCESS);
87 85 }
88 86
89 87 /*
90 88 * FUNCTION : dump_domain_to_dit()
91 89 *
92 90 * DESCRIPTION: Dumps all maps in one domain into the DIT
93 91 *
94 92 * GIVEN : Name of the domain
95 93 * Flag indicating if containers and domains should be set up.
96 94 *
97 95 * RETURNS : SUCCESS = domain completely dumped
98 96 * FAILURE = domain not completely dumped
99 97 *
100 98 */
101 99 suc_code
102 100 dump_domain_to_dit(char *dom_name, bool_t init_containers)
103 101 {
104 102 char **map_list;
105 103 int i;
106 104
107 105 /* Set up nis domain object */
108 106 if (SUCCESS != make_nis_domain(dom_name, init_containers)) {
109 107 if (init_containers)
110 108 logmsg(MSG_NOTIMECHECK, LOG_ERR,
111 109 "Could not make nisDomain object for %s", dom_name);
112 110 else
113 111 logmsg(MSG_NOTIMECHECK, LOG_ERR,
114 112 "Problem detected with nisDomain object for %s",
115 113 dom_name);
116 114 return (FAILURE);
117 115 }
118 116
119 117 /* Get list of maps from mapping file */
120 118 map_list = get_mapping_map_list(dom_name);
121 119 if (NULL == map_list) {
122 120 logmsg(MSG_NOTIMECHECK, LOG_ERR,
123 121 "Could not get map list for %s", dom_name);
124 122 return (FAILURE);
125 123 }
126 124
127 125 for (i = 0; NULL != map_list[i]; i++) {
128 126 dump_map_to_dit(map_list[i], dom_name, init_containers);
129 127 }
130 128
131 129 free_map_list(map_list);
132 130
133 131 return (SUCCESS);
134 132 }
135 133
136 134 /*
137 135 * FUNCTION : dump_map_to_dit()
138 136 *
139 137 * DESCRIPTION: Dump a OLD STYLE NIS map into the DIT.
140 138 *
141 139 * GIVEN : Name of map (not fully qualified)
142 140 * Name of domain
143 141 * Flag indicating if containers should be set up.
144 142 *
145 143 * RETURNS : SUCCESS = Map copy completed
146 144 * FAILURE = Map copy not completed
147 145 */
148 146 suc_code
149 147 dump_map_to_dit(char *map_name, char *domain, bool_t init_containers)
150 148 {
151 149 char *myself = "dump_map_to_dit";
152 150 DBM *dbm;
153 151 datum key;
154 152 datum value;
155 153 char *map_path; /* Qualified map name */
156 154 int entry_count;
157 155 int next_print;
158 156
159 157 printf("Copying map \"%s\", domain \"%s\", to LDAP.\n",
160 158 map_name, domain);
161 159
162 160 /* Create the NIS container */
163 161 if (SUCCESS != make_nis_container(map_name, domain, init_containers)) {
164 162 if (init_containers)
165 163 logmsg(MSG_NOTIMECHECK, LOG_ERR,
166 164 "Could not make container for %s %s",
167 165 map_name, domain);
168 166 else
169 167 logmsg(MSG_NOTIMECHECK, LOG_ERR,
170 168 "Problem detected with container for %s %s",
171 169 map_name, domain);
172 170
173 171 return (FAILURE);
174 172 }
175 173
176 174 /* Make up fully qualified map name */
177 175 map_path = (char *)am(myself, strlen(domain) + strlen(map_name) +
178 176 ypdbpath_sz + 3);
179 177 if (NULL == map_path) {
180 178 logmsg(MSG_NOMEM, LOG_ERR,
181 179 "Could not alloc memory for %s %s", map_name, domain);
182 180 return (FAILURE);
183 181 }
184 182 strcpy(map_path, ypdbpath);
185 183 add_separator(map_path);
186 184 strcat(map_path, domain);
187 185 add_separator(map_path);
188 186 strcat(map_path, map_name);
189 187
190 188 /* Open the DBM file. Use real dbm call */
191 189 dbm = dbm_open(map_path, O_RDONLY, 0644);
192 190
193 191 /* Finished with full name */
194 192 sfree(map_path);
195 193
196 194 if (NULL == dbm) {
197 195 /*
198 196 * This map probably didn't exist. No problem, user may be
199 197 * going to populate container using LDAP.
200 198 */
201 199 return (SUCCESS);
202 200 }
203 201
204 202 /*
205 203 * N2L has no lock for old style maps. No problem ypserv -i is the
206 204 * only thing that accesses them.
207 205 */
208 206
209 207 /* For all entries in file */
210 208 for (key = dbm_firstkey(dbm), next_print = PRINT_FREQ, entry_count = 1;
211 209 NULL != key.dptr; key = dbm_nextkey(dbm), entry_count ++) {
212 210
213 211 /* Don't write zero length keys */
214 212 if (0 == key.dsize) {
215 213 logmsg(MSG_NOTIMECHECK, LOG_INFO,
216 214 "Zero length key ignored in %s %s", map_name, domain);
217 215 continue;
218 216 }
219 217
220 218 /* Don't write 'special' nis entries */
221 219 if (is_special_key(&key))
222 220 continue;
223 221
224 222 /* Get entry */
225 223 value = dbm_fetch(dbm, key);
226 224
227 225 /* Copy entry to DIT */
228 226 if (SUCCESS != write_to_dit(map_name, domain, key, value,
229 227 TRUE, TRUE))
230 228 /* Syslog will have already been done */
231 229 break;
232 230
233 231 /* If necessary print a progress report */
234 232 if (entry_count >= next_print) {
235 233 printf("%d entries processed.\n", entry_count);
236 234 next_print *= 2;
237 235 }
238 236 }
239 237
240 238 dbm_close(dbm);
241 239
242 240 return (SUCCESS);
243 241 }
244 242
245 243 /*
246 244 * FUNCTION : dump_dit_to_maps()
247 245 *
248 246 * DESCRIPTION: Dumps the contents of the DIT into the NEW STYLE NIS maps. If
249 247 * the maps, or their TTL files do not exist creates them.
250 248 *
251 249 * Since we are now treating the DIT as authoritative details of
252 250 * which domains and maps exist are gathered from the DIT.
253 251 *
254 252 * GIVEN : Nothing
255 253 *
256 254 * RETURNS : Success code
257 255 */
258 256 suc_code
259 257 dump_dit_to_maps()
260 258 {
261 259 char **dom_list;
262 260 int dom_count;
263 261 char *dom_path;
264 262 char **map_list;
265 263 int i, j;
266 264 char *myself = "dump_dit_to_maps";
267 265
268 266 /* For all domain objects in DIT */
269 267 dom_count = get_mapping_domain_list(&dom_list);
270 268
271 269 if (0 == dom_count) {
272 270 /* No problem, maybe no domains */
273 271 return (SUCCESS);
274 272 }
275 273
276 274 /* Dump all domains in list */
277 275 for (i = 0; i < dom_count; i++) {
278 276
279 277 /* If necessary create domain directory */
280 278 dom_path = (char *)am(myself, ypdbpath_sz +
281 279 strlen(dom_list[i]) + 2);
282 280 if (NULL == dom_path) {
283 281 return (FAILURE);
284 282 }
285 283
286 284 strcpy(dom_path, ypdbpath);
287 285 strcat(dom_path, "/");
288 286 strcat(dom_path, dom_list[i]);
289 287
290 288 if (0 != mkdir(dom_path, 0644)) {
291 289 /* If dir exists fine. Just use it */
292 290 if (EEXIST != errno) {
293 291 logmsg(MSG_NOTIMECHECK, LOG_ERR,
294 292 "Could not make create domain directory %s",
295 293 dom_path);
296 294 sfree(dom_path);
297 295 }
298 296 }
299 297
300 298 sfree(dom_path);
301 299
302 300 /* Get list of maps for this domain */
303 301 map_list = get_mapping_map_list(dom_list[i]);
304 302 if (NULL == map_list) {
305 303 /* No problem. Just no maps in this domain */
306 304 continue;
307 305 }
308 306
309 307 /* For all maps in domain */
310 308 for (j = 0; map_list[j] != NULL; j++) {
311 309 /* A normal map update will initialize it. */
312 310 if (FAILURE == dump_dit_to_map(map_list[j],
313 311 dom_list[i])) {
314 312 free_map_list(map_list);
315 313 return (FAILURE);
316 314 }
317 315
318 316 /* If we have a netgroup also generate netgroup.byxxx */
319 317 if (0 == strcmp(map_list[j], NETGROUP_MAP)) {
320 318 if (FAILURE == dump_dit_to_map(NETGROUP_BYHOST,
321 319 dom_list[i])) {
322 320 free_map_list(map_list);
323 321 return (FAILURE);
324 322 }
325 323 if (FAILURE == dump_dit_to_map(NETGROUP_BYUSER,
326 324 dom_list[i])) {
327 325 free_map_list(map_list);
328 326 return (FAILURE);
329 327 }
330 328 }
331 329 }
332 330 free_map_list(map_list);
333 331 }
334 332 return (SUCCESS);
335 333 }
336 334
337 335 /*
338 336 * FUNCTION : dump_dit_to_map()
339 337 *
340 338 * DESCRIPTION: Dumps the contents of the DIT into one NEW STYLE NIS map. If
341 339 * the map, or its TTL file does not exist creates them.
342 340 *
343 341 * This is the same operation as is carried out when updating a
344 342 * map that has timed out. As a result we can call the normal
345 343 * update function.
346 344 *
347 345 *
348 346 * GIVEN : Map name (unqualified)
349 347 * Domain name.
350 348 *
351 349 * RETURNS : SUCCESS = Map copy complete
352 350 * FAILURE = Problems
353 351 */
354 352 suc_code
355 353 dump_dit_to_map(char *map_name, char *domain)
356 354 {
357 355 char *myself = "dump_dit_to_map";
358 356 map_ctrl map;
359 357 char *map_path;
360 358
361 359 printf("Copying LDAP data to map \"%s\", domain \"%s\".\n",
362 360 map_name, domain);
363 361
364 362 /*
365 363 * To call update_map_from_dit() we need an initialized map_ctrl.
366 364 * The easiest way to get this is to generate a full path to the new
367 365 * map and then call map_ctrl_init().
368 366 */
369 367 map_path = (char *)am(myself, ypdbpath_sz + strlen(map_name) +
370 368 strlen(domain) + strlen(NTOL_PREFIX) + 3);
371 369 if (NULL == map_path)
372 370 return (FAILURE);
373 371
374 372 strcpy(map_path, ypdbpath);
375 373 add_separator(map_path);
376 374 strcat(map_path, domain);
377 375 add_separator(map_path);
378 376 strcat(map_path, NTOL_PREFIX);
379 377 strcat(map_path, map_name);
380 378
381 379 if (FAILURE == map_ctrl_init(&map, map_path)) {
382 380 sfree(map_path);
383 381 return (FAILURE);
384 382 }
385 383
386 384 sfree(map_path);
387 385
388 386 /*
389 387 * This is called before anything else is running so don't need to
390 388 * do normal update lock.
391 389 */
392 390 return (update_map_from_dit(&map, TRUE));
393 391 }
394 392
395 393 /*
396 394 * FUNCTION : add_seperator()
397 395 *
398 396 * DESCRIPTION: Adds a file separator to a string (which must already be big
399 397 * enough.)
400 398 *
401 399 * GIVEN : Pointer to the string
402 400 *
403 401 * RETURNS : Nothing
404 402 */
405 403 void
406 404 add_separator(char *str)
407 405 {
408 406 char *p;
409 407
410 408 p = str + strlen(str);
411 409 *p = SEP_CHAR;
412 410 *(p+1) = '\0';
413 411 }
↓ open down ↓ |
356 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX