Debian Codegraph @

extra/tirpc/libtirpc-1.3.5/src/getnetconfig.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /*
30 * Copyright (c) 1989 by Sun Microsystems, Inc.
31 */
32
33 #include <pthread.h>
34 #include <reentrant.h>
35 #include <stdio.h>
36 #include <errno.h>
37 #include <netconfig.h>
38 #include <stddef.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <rpc/rpc.h>
42 #include <unistd.h>
43 #include "rpc_com.h"
44
45 /*
46 * The five library routines in this file provide application access to the
47 * system network configuration database, /etc/netconfig. In addition to the
48 * netconfig database and the routines for accessing it, the environment
49 * variable NETPATH and its corresponding routines in getnetpath.c may also be
50 * used to specify the network transport to be used.
51 */
52
53 /*
54 * netconfig errors
55 */
56
57 #define NC_NONETCONFIG ENOENT
58 #define NC_NOMEM ENOMEM
59 #define NC_NOTINIT EINVAL /* setnetconfig was not called first */
60 #define NC_BADFILE EBADF /* format for netconfig file is bad */
61 #define NC_NOTFOUND ENOPROTOOPT /* specified netid was not found */
62
63 /*
64 * semantics as strings (should be in netconfig.h)
65 */
66 #define NC_TPI_CLTS_S "tpi_clts"
67 #define NC_TPI_COTS_S "tpi_cots"
68 #define NC_TPI_COTS_ORD_S "tpi_cots_ord"
69 #define NC_TPI_RAW_S "tpi_raw"
70
71 /*
72 * flags as characters (also should be in netconfig.h)
73 */
74 #define NC_NOFLAG_C '-'
75 #define NC_VISIBLE_C 'v'
76 #define NC_BROADCAST_C 'b'
77
78 /*
79 * Character used to indicate there is no name-to-address lookup library
80 */
81 #define NC_NOLOOKUP "-"
82
83 static const char * const _nc_errors[] = {
84 "Netconfig database not found",
85 "Not enough memory",
86 "Not initialized",
87 "Netconfig database has invalid format",
88 "Netid not found in netconfig database"
89 };
90
91 struct netconfig_info {
92 int eof; /* all entries has been read */
93 int ref; /* # of times setnetconfig() has been called */
94 struct netconfig_list *head; /* head of the list */
95 struct netconfig_list *tail; /* last of the list */
96 };
97
98 struct netconfig_list {
99 char *linep; /* hold line read from netconfig */
100 struct netconfig *ncp;
101 struct netconfig_list *next;
102 };
103
104 struct netconfig_vars {
105 int valid; /* token that indicates a valid netconfig_vars */
106 int flag; /* first time flag */
107 struct netconfig_list *nc_configs; /* pointer to the current netconfig entry */
108 };
109
110 #define NC_VALID 0xfeed
111 #define NC_STORAGE 0xf00d
112 #define NC_INVALID 0
113
114
115 static int *__nc_error(void);
116 static int parse_ncp(char *, struct netconfig *);
117 static struct netconfig *dup_ncp(struct netconfig *);
118
119
120 static FILE *nc_file; /* for netconfig db */
121 static struct netconfig_info ni = { 0, 0, NULL, NULL};
122 extern pthread_mutex_t nc_db_lock;
123
124 #define MAXNETCONFIGLINE 1000
125
126 static int *
127 __nc_error()
128 {
129 static pthread_mutex_t nc_lock = PTHREAD_MUTEX_INITIALIZER;
130 extern thread_key_t nc_key;
131 static int nc_error = 0;
132 int error, *nc_addr;
133
134 /*
135 * Use the static `nc_error' if we are the main thread
136 * (including non-threaded programs), or if an allocation
137 * fails.
138 */
139 if (nc_key == KEY_INITIALIZER) {
140 error = 0;
141 mutex_lock(&nc_lock);
142 if (nc_key == KEY_INITIALIZER)
143 error = thr_keycreate(&nc_key, free);
144 mutex_unlock(&nc_lock);
145 if (error)
146 return (&nc_error);
147 }
148 if ((nc_addr = (int *)thr_getspecific(nc_key)) == NULL) {
149 if((nc_addr = (int *)malloc(sizeof (int))) == NULL)
150 return (&nc_error);
151 if (thr_setspecific(nc_key, (void *) nc_addr) != 0) {
152 if (nc_addr)
153 free(nc_addr);
154 return (&nc_error);
155 }
156 *nc_addr = 0;
157 }
158 return (nc_addr);
159 }
160
161 #define nc_error (*(__nc_error()))
162 /*
163 * A call to setnetconfig() establishes a /etc/netconfig "session". A session
164 * "handle" is returned on a successful call. At the start of a session (after
165 * a call to setnetconfig()) searches through the /etc/netconfig database will
166 * proceed from the start of the file. The session handle must be passed to
167 * getnetconfig() to parse the file. Each call to getnetconfig() using the
168 * current handle will process one subsequent entry in /etc/netconfig.
169 * setnetconfig() must be called before the first call to getnetconfig().
170 * (Handles are used to allow for nested calls to setnetpath()).
171 *
172 * A new session is established with each call to setnetconfig(), with a new
173 * handle being returned on each call. Previously established sessions remain
174 * active until endnetconfig() is called with that session's handle as an
175 * argument.
176 *
177 * setnetconfig() need *not* be called before a call to getnetconfigent().
178 * setnetconfig() returns a NULL pointer on failure (for example, if
179 * the netconfig database is not present).
180 */
181 void *
182 setnetconfig()
183 {
184 struct netconfig_vars *nc_vars;
185
186 if ((nc_vars = (struct netconfig_vars *)malloc(sizeof
187 (struct netconfig_vars))) == NULL) {
188 return(NULL);
189 }
190
191 /*
192 * For multiple calls, i.e. nc_file is not NULL, we just return the
193 * handle without reopening the netconfig db.
194 */
195 mutex_lock(&nc_db_lock);
196 ni.ref++;
197 if ((nc_file != NULL) || (nc_file = fopen(NETCONFIG, "r")) != NULL) {
198 nc_vars->valid = NC_VALID;
199 nc_vars->flag = 0;
200 nc_vars->nc_configs = ni.head;
201 mutex_unlock(&nc_db_lock);
202 return ((void *)nc_vars);
203 }
204 ni.ref--;
205 mutex_unlock(&nc_db_lock);
206 nc_error = NC_NONETCONFIG;
207 free(nc_vars);
208 return (NULL);
209 }
210
211
212 /*
213 * When first called, getnetconfig() returns a pointer to the first entry in
214 * the netconfig database, formatted as a struct netconfig. On each subsequent
215 * call, getnetconfig() returns a pointer to the next entry in the database.
216 * getnetconfig() can thus be used to search the entire netconfig file.
217 * getnetconfig() returns NULL at end of file.
218 */
219
220 struct netconfig *
221 getnetconfig(handlep)
222 void *handlep;
223 {
224 struct netconfig_vars *ncp = (struct netconfig_vars *)handlep;
225 char *stringp; /* tmp string pointer */
226 struct netconfig_list *list;
227 struct netconfig *np;
228 struct netconfig *result;
229
230 /*
231 * Verify that handle is valid
232 */
233 mutex_lock(&nc_db_lock);
234 if (ncp == NULL || nc_file == NULL) {
235 nc_error = NC_NOTINIT;
236 mutex_unlock(&nc_db_lock);
237 return (NULL);
238 }
239
240 switch (ncp->valid) {
241 case NC_VALID:
242 /*
243 * If entry has already been read into the list,
244 * we return the entry in the linked list.
245 * If this is the first time call, check if there are any entries in
246 * linked list. If no entries, we need to read the netconfig db.
247 * If we have been here and the next entry is there, we just return
248 * it.
249 */
250 if (ncp->flag == 0) { /* first time */
251 ncp->flag = 1;
252 ncp->nc_configs = ni.head;
253 if (ncp->nc_configs != NULL) /* entry already exist */ {
254 mutex_unlock(&nc_db_lock);
255 return(ncp->nc_configs->ncp);
256 }
257 }
258 else if (ncp->nc_configs != NULL && ncp->nc_configs->next != NULL) {
259 ncp->nc_configs = ncp->nc_configs->next;
260 mutex_unlock(&nc_db_lock);
261 return(ncp->nc_configs->ncp);
262 }
263
264 /*
265 * If we cannot find the entry in the list and is end of file,
266 * we give up.
267 */
268 if (ni.eof == 1) {
269 mutex_unlock(&nc_db_lock);
270 return(NULL);
271 }
272 break;
273 default:
274 nc_error = NC_NOTINIT;
275 mutex_unlock(&nc_db_lock);
276 return (NULL);
277 }
278
279 stringp = (char *) malloc(MAXNETCONFIGLINE);
280 if (stringp == NULL) {
281 mutex_unlock(&nc_db_lock);
282 return (NULL);
283 }
284
285 #ifdef MEM_CHK
286 if (malloc_verify() == 0) {
287 fprintf(stderr, "memory heap corrupted in getnetconfig\n");
288 exit(1);
289 }
290 #endif
291
292 /*
293 * Read a line from netconfig file.
294 */
295 do {
296 if (fgets(stringp, MAXNETCONFIGLINE, nc_file) == NULL) {
297 free(stringp);
298 ni.eof = 1;
299 mutex_unlock(&nc_db_lock);
300 return (NULL);
301 }
302 } while (*stringp == '#');
303
304 list = (struct netconfig_list *) malloc(sizeof (struct netconfig_list));
305 if (list == NULL) {
306 free(stringp);
307 mutex_unlock(&nc_db_lock);
308 return(NULL);
309 }
310 np = (struct netconfig *) malloc(sizeof (struct netconfig));
311 if (np == NULL) {
312 free(stringp);
313 free(list);
314 mutex_unlock(&nc_db_lock);
315 return(NULL);
316 }
317 list->ncp = np;
318 list->next = NULL;
319 list->ncp->nc_lookups = NULL;
320 list->linep = stringp;
321 if (parse_ncp(stringp, list->ncp) == -1) {
322 free(stringp);
323 free(np);
324 free(list);
325 mutex_unlock(&nc_db_lock);
326 return (NULL);
327 }
328 else {
329 /*
330 * If this is the first entry that's been read, it is the head of
331 * the list. If not, put the entry at the end of the list.
332 * Reposition the current pointer of the handle to the last entry
333 * in the list.
334 */
335 if (ni.head == NULL) { /* first entry */
336 ni.head = ni.tail = list;
337 }
338 else {
339 ni.tail->next = list;
340 ni.tail = ni.tail->next;
341 }
342 ncp->nc_configs = ni.tail;
343 result = ni.tail->ncp;
344 mutex_unlock(&nc_db_lock);
345 return result;
346 }
347 }
348
349 /*
350 * endnetconfig() may be called to "unbind" or "close" the netconfig database
351 * when processing is complete, releasing resources for reuse. endnetconfig()
352 * may not be called before setnetconfig(). endnetconfig() returns 0 on
353 * success and -1 on failure (for example, if setnetconfig() was not called
354 * previously).
355 */
356 int
357 endnetconfig(handlep)
358 void *handlep;
359 {
360 struct netconfig_vars *nc_handlep = (struct netconfig_vars *)handlep;
361
362 struct netconfig_list *q, *p;
363
364 /*
365 * Verify that handle is valid
366 */
367 if (nc_handlep == NULL || (nc_handlep->valid != NC_VALID &&
368 nc_handlep->valid != NC_STORAGE)) {
369 nc_error = NC_NOTINIT;
370 return (-1);
371 }
372
373 /*
374 * Return 0 if anyone still needs it.
375 */
376 nc_handlep->valid = NC_INVALID;
377 nc_handlep->flag = 0;
378 nc_handlep->nc_configs = NULL;
379 mutex_lock(&nc_db_lock);
380 if (--ni.ref > 0) {
381 mutex_unlock(&nc_db_lock);
382 free(nc_handlep);
383 return(0);
384 }
385
386 /*
387 * Noone needs these entries anymore, then frees them.
388 * Make sure all info in netconfig_info structure has been reinitialized.
389 */
390 q = p = ni.head;
391 ni.eof = ni.ref = 0;
392 ni.head = NULL;
393 ni.tail = NULL;
394 while (q) {
395 p = q->next;
396 if (q->ncp->nc_lookups != NULL) free(q->ncp->nc_lookups);
397 free(q->ncp);
398 free(q->linep);
399 free(q);
400 q = p;
401 }
402 free(nc_handlep);
403 if(nc_file != NULL) {
404 fclose(nc_file);
405 }
406 nc_file = NULL;
407 mutex_unlock(&nc_db_lock);
408 return (0);
409 }
410
411 /*
412 * getnetconfigent(netid) returns a pointer to the struct netconfig structure
413 * corresponding to netid. It returns NULL if netid is invalid (that is, does
414 * not name an entry in the netconfig database). It returns NULL and sets
415 * errno in case of failure (for example, if the netconfig database cannot be
416 * opened).
417 */
418
419 struct netconfig *
420 getnetconfigent(netid)
421 const char *netid;
422 {
423 FILE *file; /* NETCONFIG db's file pointer */
424 char *linep; /* holds current netconfig line */
425 char *stringp; /* temporary string pointer */
426 struct netconfig *ncp = NULL; /* returned value */
427 struct netconfig_list *list; /* pointer to cache list */
428
429 nc_error = NC_NOTFOUND; /* default error. */
430 if (netid == NULL || strlen(netid) == 0) {
431 return (NULL);
432 }
433
434 if (strcmp(netid, "unix") == 0) {
435 fprintf(stderr, "The local transport is called \"unix\" ");
436 fprintf(stderr, "in /etc/netconfig.\n");
437 fprintf(stderr, "Please change this to \"local\" manually ");
438 fprintf(stderr, "or run mergemaster(8).\n");
439 }
440
441 /*
442 * Look up table if the entries have already been read and parsed in
443 * getnetconfig(), then copy this entry into a buffer and return it.
444 * If we cannot find the entry in the current list and there are more
445 * entries in the netconfig db that has not been read, we then read the
446 * db and try find the match netid.
447 * If all the netconfig db has been read and placed into the list and
448 * there is no match for the netid, return NULL.
449 */
450 mutex_lock(&nc_db_lock);
451 if (ni.head != NULL) {
452 for (list = ni.head; list; list = list->next) {
453 if (strcmp(list->ncp->nc_netid, netid) == 0) {
454 ncp = dup_ncp(list->ncp);
455 mutex_unlock(&nc_db_lock);
456 return ncp;
457 }
458 }
459 if (ni.eof == 1) { /* that's all the entries */
460 mutex_unlock(&nc_db_lock);
461 return(NULL);
462 }
463 }
464 mutex_unlock(&nc_db_lock);
465
466 if ((file = fopen(NETCONFIG, "r")) == NULL) {
467 nc_error = NC_NONETCONFIG;
468 return (NULL);
469 }
470
471 if ((linep = malloc(MAXNETCONFIGLINE)) == NULL) {
472 fclose(file);
473 nc_error = NC_NOMEM;
474 return (NULL);
475 }
476 do {
477 ptrdiff_t len;
478 char *tmpp; /* tmp string pointer */
479
480 do {
481 if ((stringp = fgets(linep, MAXNETCONFIGLINE, file)) == NULL) {
482 break;
483 }
484 } while (*stringp == '#');
485 if (stringp == NULL) { /* eof */
486 break;
487 }
488 if ((tmpp = strpbrk(stringp, "\t ")) == NULL) { /* can't parse file */
489 nc_error = NC_BADFILE;
490 break;
491 }
492 if (strlen(netid) == (size_t) (len = tmpp - stringp) && /* a match */
493 strncmp(stringp, netid, (size_t)len) == 0) {
494 if ((ncp = (struct netconfig *)
495 malloc(sizeof (struct netconfig))) == NULL) {
496 break;
497 }
498 ncp->nc_lookups = NULL;
499 if (parse_ncp(linep, ncp) == -1) {
500 free(ncp);
501 ncp = NULL;
502 }
503 break;
504 }
505 } while (stringp != NULL);
506 if (ncp == NULL) {
507 free(linep);
508 }
509 fclose(file);
510 return(ncp);
511 }
512
513 /*
514 * freenetconfigent(netconfigp) frees the netconfig structure pointed to by
515 * netconfigp (previously returned by getnetconfigent()).
516 */
517
518 void
519 freenetconfigent(netconfigp)
520 struct netconfig *netconfigp;
521 {
522 if (netconfigp != NULL) {
523 free(netconfigp->nc_netid); /* holds all netconfigp's strings */
524 if (netconfigp->nc_lookups != NULL)
525 free(netconfigp->nc_lookups);
526 free(netconfigp);
527 }
528 return;
529 }
530
531 /*
532 * Parse line and stuff it in a struct netconfig
533 * Typical line might look like:
534 * udp tpi_cots vb inet udp /dev/udp /usr/lib/ip.so,/usr/local/ip.so
535 *
536 * We return -1 if any of the tokens don't parse, or malloc fails.
537 *
538 * Note that we modify stringp (putting NULLs after tokens) and
539 * we set the ncp's string field pointers to point to these tokens within
540 * stringp.
541 */
542
543 static int
544 parse_ncp(stringp, ncp)
545 char *stringp; /* string to parse */
546 struct netconfig *ncp; /* where to put results */
547 {
548 char *tokenp; /* for processing tokens */
549 char *lasts;
550
551 nc_error = NC_BADFILE; /* nearly anything that breaks is for this reason */
552 stringp[strlen(stringp)-1] = '\0'; /* get rid of newline */
553 /* netid */
554 if ((ncp->nc_netid = strtok_r(stringp, "\t ", &lasts)) == NULL) {
555 return (-1);
556 }
557
558 /* semantics */
559 if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
560 return (-1);
561 }
562 if (strcmp(tokenp, NC_TPI_COTS_ORD_S) == 0)
563 ncp->nc_semantics = NC_TPI_COTS_ORD;
564 else if (strcmp(tokenp, NC_TPI_COTS_S) == 0)
565 ncp->nc_semantics = NC_TPI_COTS;
566 else if (strcmp(tokenp, NC_TPI_CLTS_S) == 0)
567 ncp->nc_semantics = NC_TPI_CLTS;
568 else if (strcmp(tokenp, NC_TPI_RAW_S) == 0)
569 ncp->nc_semantics = NC_TPI_RAW;
570 else
571 return (-1);
572
573 /* flags */
574 if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
575 return (-1);
576 }
577 for (ncp->nc_flag = NC_NOFLAG; *tokenp != '\0';
578 tokenp++) {
579 switch (*tokenp) {
580 case NC_NOFLAG_C:
581 break;
582 case NC_VISIBLE_C:
583 ncp->nc_flag |= NC_VISIBLE;
584 break;
585 case NC_BROADCAST_C:
586 ncp->nc_flag |= NC_BROADCAST;
587 break;
588 default:
589 return (-1);
590 }
591 }
592 /* protocol family */
593 if ((ncp->nc_protofmly = strtok_r(NULL, "\t ", &lasts)) == NULL) {
594 return (-1);
595 }
596 /* protocol name */
597 if ((ncp->nc_proto = strtok_r(NULL, "\t ", &lasts)) == NULL) {
598 return (-1);
599 }
600 /* network device */
601 if ((ncp->nc_device = strtok_r(NULL, "\t ", &lasts)) == NULL) {
602 return (-1);
603 }
604 if ((tokenp = strtok_r(NULL, "\t ", &lasts)) == NULL) {
605 return (-1);
606 }
607 if (strcmp(tokenp, NC_NOLOOKUP) == 0) {
608 ncp->nc_nlookups = 0;
609 ncp->nc_lookups = NULL;
610 } else {
611 char *cp; /* tmp string */
612
613 if (ncp->nc_lookups != NULL) /* from last visit */
614 free(ncp->nc_lookups);
615 /* preallocate one string pointer */
616 ncp->nc_lookups = (char **)malloc(sizeof (char *));
617 ncp->nc_nlookups = 0;
618 while ((cp = tokenp) != NULL) {
619 tokenp = _get_next_token(cp, ',');
620 ncp->nc_lookups[(size_t)ncp->nc_nlookups++] = cp;
621 ncp->nc_lookups = (char **)realloc(ncp->nc_lookups,
622 (size_t)(ncp->nc_nlookups+1) *sizeof(char *)); /* for next loop */
623 }
624 }
625 return (0);
626 }
627
628
629 /*
630 * Returns a string describing the reason for failure.
631 */
632 char *
633 nc_sperror()
634 {
635 const char *message;
636
637 switch(nc_error) {
638 case NC_NONETCONFIG:
639 message = _nc_errors[0];
640 break;
641 case NC_NOMEM:
642 message = _nc_errors[1];
643 break;
644 case NC_NOTINIT:
645 message = _nc_errors[2];
646 break;
647 case NC_BADFILE:
648 message = _nc_errors[3];
649 break;
650 case NC_NOTFOUND:
651 message = _nc_errors[4];
652 break;
653 default:
654 message = "Unknown network selection error";
655 }
656 /* LINTED const castaway */
657 return ((char *)message);
658 }
659
660 /*
661 * Prints a message onto standard error describing the reason for failure.
662 */
663 void
664 nc_perror(s)
665 const char *s;
666 {
667 fprintf(stderr, "%s: %s\n", s, nc_sperror());
668 }
669
670 /*
671 * Duplicates the matched netconfig buffer.
672 */
673 static struct netconfig *
674 dup_ncp(ncp)
675 struct netconfig *ncp;
676 {
677 struct netconfig *p;
678 char *tmp;
679 char *t;
680 u_int i;
681
682 if ((tmp=malloc(MAXNETCONFIGLINE)) == NULL)
683 return(NULL);
684 if ((p=(struct netconfig *)malloc(sizeof(struct netconfig))) == NULL) {
685 free(tmp);
686 return(NULL);
687 }
688 /*
689 * First we dup all the data from matched netconfig buffer. Then we
690 * adjust some of the member pointer to a pre-allocated buffer where
691 * contains part of the data.
692 * To follow the convention used in parse_ncp(), we store all the
693 * necessary information in the pre-allocated buffer and let each
694 * of the netconfig char pointer member point to the right address
695 * in the buffer.
696 */
697 *p = *ncp;
698 p->nc_netid = (char *)strcpy(tmp,ncp->nc_netid);
699 t = strchr(tmp, 0) + 1;
700 p->nc_protofmly = (char *)strcpy(t,ncp->nc_protofmly);
701 t = strchr(t, 0) + 1;
702 p->nc_proto = (char *)strcpy(t,ncp->nc_proto);
703 t = strchr(t, 0) + 1;
704 p->nc_device = (char *)strcpy(t,ncp->nc_device);
705 p->nc_lookups = (char **)malloc((size_t)(p->nc_nlookups+1) * sizeof(char *));
706 if (p->nc_lookups == NULL) {
707 free(p);
708 free(tmp);
709 return(NULL);
710 }
711 for (i=0; i < p->nc_nlookups; i++) {
712 t = strchr(t, 0) + 1;
713 p->nc_lookups[i] = (char *)strcpy(t,ncp->nc_lookups[i]);
714 }
715 return(p);
716 }