| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
#define NC_NONETCONFIG ENOENT |
| 58 |
#define NC_NOMEM ENOMEM |
| 59 |
#define NC_NOTINIT EINVAL |
| 60 |
#define NC_BADFILE EBADF |
| 61 |
#define NC_NOTFOUND ENOPROTOOPT |
| 62 |
|
| 63 |
|
| 64 |
|
| 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 |
|
| 73 |
|
| 74 |
#define NC_NOFLAG_C '-' |
| 75 |
#define NC_VISIBLE_C 'v' |
| 76 |
#define NC_BROADCAST_C 'b' |
| 77 |
|
| 78 |
|
| 79 |
|
| 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; |
| 93 |
int ref; |
| 94 |
struct netconfig_list *head; |
| 95 |
struct netconfig_list *tail; |
| 96 |
}; |
| 97 |
|
| 98 |
struct netconfig_list { |
| 99 |
char *linep; |
| 100 |
struct netconfig *ncp; |
| 101 |
struct netconfig_list *next; |
| 102 |
}; |
| 103 |
|
| 104 |
struct netconfig_vars { |
| 105 |
int valid; |
| 106 |
int flag; |
| 107 |
struct netconfig_list *nc_configs; |
| 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; |
| 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 |
|
| 136 |
|
| 137 |
|
| 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 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 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 |
|
| 193 |
|
| 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 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
struct netconfig * |
| 221 |
getnetconfig(handlep) |
| 222 |
void *handlep; |
| 223 |
{ |
| 224 |
struct netconfig_vars *ncp = (struct netconfig_vars *)handlep; |
| 225 |
char *stringp; |
| 226 |
struct netconfig_list *list; |
| 227 |
struct netconfig *np; |
| 228 |
struct netconfig *result; |
| 229 |
|
| 230 |
|
| 231 |
|
| 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 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
if (ncp->flag == 0) { |
| 251 |
ncp->flag = 1; |
| 252 |
ncp->nc_configs = ni.head; |
| 253 |
if (ncp->nc_configs != NULL) { |
| 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 |
|
| 266 |
|
| 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 |
|
| 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 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
if (ni.head == NULL) { |
| 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 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 388 |
|
| 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 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
struct netconfig * |
| 420 |
getnetconfigent(netid) |
| 421 |
const char *netid; |
| 422 |
{ |
| 423 |
FILE *file; |
| 424 |
char *linep; |
| 425 |
char *stringp; |
| 426 |
struct netconfig *ncp = NULL; |
| 427 |
struct netconfig_list *list; |
| 428 |
|
| 429 |
nc_error = NC_NOTFOUND; |
| 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 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 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) { |
| 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; |
| 479 |
|
| 480 |
do { |
| 481 |
if ((stringp = fgets(linep, MAXNETCONFIGLINE, file)) == NULL) { |
| 482 |
break; |
| 483 |
} |
| 484 |
} while (*stringp == '#'); |
| 485 |
if (stringp == NULL) { |
| 486 |
break; |
| 487 |
} |
| 488 |
if ((tmpp = strpbrk(stringp, "\t ")) == NULL) { |
| 489 |
nc_error = NC_BADFILE; |
| 490 |
break; |
| 491 |
} |
| 492 |
if (strlen(netid) == (size_t) (len = tmpp - stringp) && |
| 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 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
void |
| 519 |
freenetconfigent(netconfigp) |
| 520 |
struct netconfig *netconfigp; |
| 521 |
{ |
| 522 |
if (netconfigp != NULL) { |
| 523 |
free(netconfigp->nc_netid); |
| 524 |
if (netconfigp->nc_lookups != NULL) |
| 525 |
free(netconfigp->nc_lookups); |
| 526 |
free(netconfigp); |
| 527 |
} |
| 528 |
return; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
static int |
| 544 |
parse_ncp(stringp, ncp) |
| 545 |
char *stringp; |
| 546 |
struct netconfig *ncp; |
| 547 |
{ |
| 548 |
char *tokenp; |
| 549 |
char *lasts; |
| 550 |
|
| 551 |
nc_error = NC_BADFILE; |
| 552 |
stringp[strlen(stringp)-1] = '\0'; |
| 553 |
|
| 554 |
if ((ncp->nc_netid = strtok_r(stringp, "\t ", &lasts)) == NULL) { |
| 555 |
return (-1); |
| 556 |
} |
| 557 |
|
| 558 |
|
| 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 |
|
| 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 |
|
| 593 |
if ((ncp->nc_protofmly = strtok_r(NULL, "\t ", &lasts)) == NULL) { |
| 594 |
return (-1); |
| 595 |
} |
| 596 |
|
| 597 |
if ((ncp->nc_proto = strtok_r(NULL, "\t ", &lasts)) == NULL) { |
| 598 |
return (-1); |
| 599 |
} |
| 600 |
|
| 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; |
| 612 |
|
| 613 |
if (ncp->nc_lookups != NULL) |
| 614 |
free(ncp->nc_lookups); |
| 615 |
|
| 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 *)); |
| 623 |
} |
| 624 |
} |
| 625 |
return (0); |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 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 |
|
| 657 |
return ((char *)message); |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 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 |
|
| 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 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 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 |
} |