| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | #include <afsconfig.h> |
| 19 | #include <afs/param.h> |
| 20 | |
| 21 | #include <roken.h> |
| 22 | |
| 23 | #include <afs/cmd.h> |
| 24 | #include <afs/com_err.h> |
| 25 | #include <afs/bubasics.h> |
| 26 | |
| 27 | #include "bc.h" |
| 28 | #include "bucoord_internal.h" |
| 29 | |
| 30 | struct ubik_client *cstructp; |
| 31 | |
| 32 | static int FreeVolumeEntryList(struct bc_volumeEntry *aentry); |
| 33 | static int FreeVolumeEntry(struct bc_volumeEntry *aentry); |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | afs_int32 |
| 44 | bc_GetPartitionID(char *aname, afs_int32 *aval) |
| 45 | { |
| 46 | |
| 47 | |
| 48 | |
| 49 | char tc; |
| 50 | char ascii[3]; |
| 51 | |
| 52 | |
| 53 | if (strcmp(aname, ".*") == 0) { |
| 54 | *aval = -1; |
| 55 | return 0; |
| 56 | } |
| 57 | tc = *aname; |
| 58 | if (tc == 0) |
| 59 | return -1; |
| 60 | |
| 61 | if (tc >= '0' && tc <= '9') { |
| 62 | *aval = bc_SafeATOI(aname); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | ascii[2] = 0; |
| 67 | if (strlen(aname) <= 2) { |
| 68 | strcpy(ascii, aname); |
| 69 | } else if (!strncmp(aname, "/vicep", 6)) { |
| 70 | strncpy(ascii, aname + 6, 2); |
| 71 | } else if (!strncmp(aname, "vicep", 5)) { |
| 72 | strncpy(ascii, aname + 5, 2); |
| 73 | } else |
| 74 | return (BC_NOPARTITION(156288011L)); |
| 75 | |
| 76 | |
| 77 | if (ascii[1] == 0) { |
| 78 | |
| 79 | if (ascii[0] < 'a' || ascii[0] > 'z') |
| 80 | return -1; |
| 81 | *aval = ascii[0] - 'a'; |
| 82 | return 0; |
| 83 | } else { |
| 84 | |
| 85 | if (ascii[0] < 'a' || ascii[0] > 'z') |
| 86 | return -1; |
| 87 | if (ascii[1] < 'a' || ascii[1] > 'z') |
| 88 | return -1; |
| 89 | *aval = (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26; |
| 90 | return 0; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | int |
| 118 | bc_ParseHost(char *aname, struct sockaddr_in *asockaddr) |
| 119 | |
| 120 | { |
| 121 | |
| 122 | struct hostent *th; |
| 123 | afs_uint32 addr; |
| 124 | afs_int32 b1, b2, b3, b4; |
| 125 | afs_int32 code; |
| 126 | afs_int32 tmp1, tmp2; |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4); |
| 132 | if (code == 4) { |
| 133 | |
| 134 | |
| 135 | |
| 136 | #ifdef STRUCT_SOCKADDR_HAS_SA_LEN1 |
| 137 | asockaddr->sin_len = sizeof(struct sockaddr_in); |
| 138 | #endif |
| 139 | asockaddr->sin_family = AF_INET2; |
| 140 | asockaddr->sin_port = 0; |
| 141 | addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; |
| 142 | memcpy(&tmp1, &addr, sizeof(afs_int32)); |
| 143 | tmp2 = htonl(tmp1)(__builtin_constant_p(tmp1) ? ((((__uint32_t)(tmp1)) >> 24) | ((((__uint32_t)(tmp1)) & (0xff << 16)) >> 8) | ((((__uint32_t)(tmp1)) & (0xff << 8)) << 8) | (((__uint32_t)(tmp1)) << 24)) : __bswap32_var(tmp1 )); |
| 144 | memcpy(&asockaddr->sin_addr.s_addr, &tmp2, sizeof(afs_int32)); |
| 145 | return (0); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | if (strcmp(aname, ".*") == 0) { |
| 154 | memset(asockaddr, 0, sizeof(struct sockaddr_in)); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | th = gethostbyname(aname); |
| 159 | if (!th) |
| 160 | |
| 161 | |
| 162 | |
| 163 | return (BC_NOHOST(156288010L)); |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | #ifdef STRUCT_SOCKADDR_HAS_SA_LEN1 |
| 169 | asockaddr->sin_len = sizeof(struct sockaddr_in); |
| 170 | #endif |
| 171 | asockaddr->sin_family = AF_INET2; |
| 172 | asockaddr->sin_port = 0; |
| 173 | memcpy(&tmp1, th->h_addrh_addr_list[0], sizeof(afs_int32)); |
| 174 | tmp2 = htonl(tmp1)(__builtin_constant_p(tmp1) ? ((((__uint32_t)(tmp1)) >> 24) | ((((__uint32_t)(tmp1)) & (0xff << 16)) >> 8) | ((((__uint32_t)(tmp1)) & (0xff << 8)) << 8) | (((__uint32_t)(tmp1)) << 24)) : __bswap32_var(tmp1 )); |
| 175 | memcpy(&(asockaddr->sin_addr.s_addr), &tmp2, |
| 176 | sizeof(asockaddr->sin_addr.s_addr)); |
| 177 | return (0); |
| 178 | |
| 179 | } |
| 180 | |
| 181 | |
| 182 | |
| 183 | int |
| 184 | bc_CreateVolumeSet(struct bc_config *aconfig, char *avolName, |
| 185 | afs_int32 aflags) |
| 186 | { |
| 187 | struct bc_volumeSet **tlast, *tset, *nset; |
| 188 | |
| 189 | if (bc_FindVolumeSet(aconfig, avolName)) |
| 190 | return -1; |
| 191 | |
| 192 | |
| 193 | nset = (struct bc_volumeSet *)malloc(sizeof(struct bc_volumeSet)); |
| 194 | memset(nset, 0, sizeof(*nset)); |
| 195 | nset->flags = aflags; |
| 196 | nset->name = (char *)malloc(strlen(avolName) + 1); |
| 197 | strcpy(nset->name, avolName); |
| 198 | if (aflags & VSFLAG_TEMPORARY1) { |
| 199 | |
| 200 | nset->next = aconfig->vset; |
| 201 | aconfig->vset = nset; |
| 202 | } else { |
| 203 | |
| 204 | for (tlast = &aconfig->vset, tset = *tlast; tset; |
| 205 | tlast = &tset->next, tset = *tlast); |
| 206 | *tlast = nset; |
| 207 | } |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static int |
| 212 | FreeVolumeEntry(struct bc_volumeEntry *aentry) |
| 213 | { |
| 214 | free(aentry->name); |
| 215 | free(aentry->serverName); |
| 216 | free(aentry->partname); |
| 217 | free(aentry); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static int |
| 222 | FreeVolumeEntryList(struct bc_volumeEntry *aentry) |
| 223 | { |
| 224 | struct bc_volumeEntry *tnext; |
| 225 | |
| 226 | while (aentry) { |
| 227 | tnext = aentry->next; |
| 228 | FreeVolumeEntry(aentry); |
| 229 | aentry = tnext; |
| 230 | } |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | |
| 236 | void |
| 237 | FreeVolumeSet(struct bc_volumeSet *avset) |
| 238 | { |
| 239 | FreeVolumeEntryList(avset->ventries); |
| 240 | free(avset->name); |
| 241 | free(avset); |
| 242 | } |
| 243 | |
| 244 | int |
| 245 | bc_DeleteVolumeSet(struct bc_config *aconfig, char *avolName, |
| 246 | afs_int32 *flags) |
| 247 | { |
| 248 | struct bc_volumeSet **tlast, *tset; |
| 249 | |
| 250 | *flags = 0; |
| 251 | tlast = &aconfig->vset; |
| 252 | for (tset = *tlast; tset; tlast = &tset->next, tset = *tlast) { |
| 253 | if (strcmp(avolName, tset->name) == 0) { |
| 254 | *flags = tset->flags; |
| 255 | *tlast = tset->next; |
| 256 | FreeVolumeSet(tset); |
| 257 | return 0; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | |
| 262 | return -1; |
| 263 | } |
| 264 | |
| 265 | int |
| 266 | bc_DeleteVolumeItem(struct bc_config *aconfig, char *avolName, |
| 267 | afs_int32 anumber) |
| 268 | { |
| 269 | afs_int32 i; |
| 270 | struct bc_volumeSet *tset; |
| 271 | struct bc_volumeEntry *tentry, **tlast; |
| 272 | |
| 273 | tset = bc_FindVolumeSet(aconfig, avolName); |
| 274 | if (!tset) |
| 275 | return -1; |
| 276 | |
| 277 | tlast = &tset->ventries; |
| 278 | for (i = 1, tentry = *tlast; tentry; |
| 279 | tlast = &tentry->next, tentry = *tlast, i++) { |
| 280 | if (anumber == i) { |
| 281 | |
| 282 | *tlast = tentry->next; |
| 283 | FreeVolumeEntry(tentry); |
| 284 | return 0; |
| 285 | } |
| 286 | } |
| 287 | return -2; |
| 288 | } |
| 289 | |
| 290 | int |
| 291 | bc_AddVolumeItem(struct bc_config *aconfig, char *avolName, char *ahost, |
| 292 | char *apart, char *avol) |
| 293 | { |
| 294 | struct bc_volumeSet *tset; |
| 295 | struct bc_volumeEntry **tlast, *tentry; |
| 296 | afs_int32 code; |
| 297 | |
| 298 | tset = bc_FindVolumeSet(aconfig, avolName); |
| 299 | if (!tset) |
| 300 | return (BC_NOVOLSET(156288007L)); |
| 301 | |
| 302 | |
| 303 | tlast = &tset->ventries; |
| 304 | |
| 305 | |
| 306 | for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast); |
| 307 | tentry = (struct bc_volumeEntry *)malloc(sizeof(struct bc_volumeEntry)); |
| 308 | memset(tentry, 0, sizeof(*tentry)); |
| 309 | tentry->serverName = (char *)malloc(strlen(ahost) + 1); |
| 310 | strcpy(tentry->serverName, ahost); |
| 311 | tentry->partname = (char *)malloc(strlen(apart) + 1); |
| 312 | strcpy(tentry->partname, apart); |
| 313 | tentry->name = (char *)malloc(strlen(avol) + 1); |
| 314 | strcpy(tentry->name, avol); |
| 315 | |
| 316 | code = bc_ParseHost(tentry->serverName, &tentry->server); |
| 317 | if (code) |
| 318 | return (code); |
| 319 | |
| 320 | code = bc_GetPartitionID(tentry->partname, &tentry->partition); |
| 321 | if (code) |
| 322 | return (code); |
| 323 | |
| 324 | *tlast = tentry; |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | struct bc_volumeSet * |
| 329 | bc_FindVolumeSet(struct bc_config *aconfig, char *aname) |
| 330 | { |
| 331 | |
| 332 | struct bc_volumeSet *tvs; |
| 333 | |
| 334 | for (tvs = aconfig->vset; tvs; tvs = tvs->next) { |
| 335 | if (!strcmp(tvs->name, aname)) |
| 336 | return (tvs); |
| 337 | } |
| 338 | return (struct bc_volumeSet *)0; |
| 339 | |
| 340 | } |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | int |
| 357 | bc_CreateDumpSchedule(struct bc_config *aconfig, char *adumpName, |
| 358 | afs_int32 expDate, afs_int32 expType) |
| 359 | { |
| 360 | struct bc_dumpSchedule *tdump; |
| 361 | struct bc_dumpSchedule *parent, *node; |
| 362 | afs_int32 code; |
| 363 | |
| 364 | if (strcmp(adumpName, "none") == 0) |
| 365 | return -2; |
| 366 | |
| 367 | code = FindDump(aconfig, adumpName, &parent, &node); |
| 368 | if (code == 0) |
| 369 | return -1; |
| 370 | else if (code != -1) |
| 371 | return -2; |
| 372 | |
| 373 | tdump = (struct bc_dumpSchedule *)malloc(sizeof(struct bc_dumpSchedule)); |
| 374 | memset(tdump, 0, sizeof(*tdump)); |
| 375 | |
| 376 | |
| 377 | tdump->next = aconfig->dsched; |
| 378 | aconfig->dsched = tdump; |
| 379 | |
| 380 | |
| 381 | tdump->name = (char *)malloc(strlen(adumpName) + 1); |
| 382 | strcpy(tdump->name, adumpName); |
| 383 | |
| 384 | |
| 385 | tdump->expDate = expDate; |
| 386 | tdump->expType = expType; |
| 387 | |
| 388 | bc_ProcessDumpSchedule(aconfig); |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | int |
| 398 | bc_DeleteDumpScheduleAddr(struct bc_config *aconfig, |
| 399 | struct bc_dumpSchedule *adumpAddr) |
| 400 | { |
| 401 | struct bc_dumpSchedule **tlast, *tdump; |
| 402 | struct bc_dumpSchedule *tnext; |
| 403 | |
| 404 | |
| 405 | for (tdump = adumpAddr->firstChild; tdump; tdump = tnext) { |
| 406 | |
| 407 | tnext = tdump->nextSibling; |
| 408 | bc_DeleteDumpScheduleAddr(aconfig, tdump); |
| 409 | } |
| 410 | |
| 411 | |
| 412 | for (tlast = &aconfig->dsched, tdump = *tlast; tdump; |
| 413 | tlast = &tdump->next, tdump = *tlast) { |
| 414 | if (tdump == adumpAddr) { |
| 415 | |
| 416 | *tlast = tdump->next; |
| 417 | free(tdump->name); |
| 418 | free(tdump); |
| 419 | return 0; |
| 420 | } |
| 421 | } |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | struct bc_dumpSchedule * |
| 435 | bc_FindDumpSchedule(struct bc_config *aconfig, char *aname) |
| 436 | { |
| 437 | struct bc_dumpSchedule *tds; |
| 438 | for (tds = aconfig->dsched; tds; tds = tds->next) { |
| 439 | if (!strcmp(tds->name, aname)) |
| 440 | return tds; |
| 441 | } |
| 442 | return (struct bc_dumpSchedule *)0; |
| 443 | } |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | int |
| 450 | bc_DeleteDumpSchedule(struct bc_config *aconfig, char *adumpName) |
| 451 | { |
| 452 | struct bc_dumpSchedule *tdump; |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | for (tdump = aconfig->dsched; tdump; tdump = tdump->next) { |
| 458 | if (strcmp(tdump->name, adumpName) == 0) { |
| 459 | |
| 460 | bc_DeleteDumpScheduleAddr(aconfig, tdump); |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | bc_ProcessDumpSchedule(aconfig); |
| 466 | return 0; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | int |
| 481 | bc_ProcessDumpSchedule(struct bc_config *aconfig) |
| 482 | { |
| 483 | struct bc_dumpSchedule *tds; |
| 484 | struct bc_dumpSchedule *parentptr, *nodeptr; |
| 485 | int retval; |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | for (tds = aconfig->dsched; tds; tds = tds->next) { |
| 491 | tds->parent = (struct bc_dumpSchedule *)0; |
| 492 | tds->nextSibling = (struct bc_dumpSchedule *)0; |
| 493 | tds->firstChild = (struct bc_dumpSchedule *)0; |
| 494 | } |
| 495 | |
| 496 | for (tds = aconfig->dsched; tds; tds = tds->next) { |
| 497 | retval = FindDump(aconfig, tds->name, &parentptr, &nodeptr); |
| 498 | if (retval != 0) { |
| 499 | printf("bc_processdumpschedule: finddump returns %d\n", retval); |
| 500 | exit(1); |
| 501 | } |
| 502 | |
| 503 | |
| 504 | if (parentptr != 0) { |
| 505 | nodeptr->parent = parentptr; |
| 506 | nodeptr->nextSibling = parentptr->firstChild; |
| 507 | parentptr->firstChild = nodeptr; |
| 508 | } |
| 509 | } |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | int |
| 532 | FindDump(struct bc_config *aconfig, char *nodeString, |
| 533 | struct bc_dumpSchedule **parentptr, |
| 534 | struct bc_dumpSchedule **nodeptr) |
| 535 | { |
| 536 | struct bc_dumpSchedule *dsptr; |
| 537 | char *separator; |
| 538 | int matchLength; |
| 539 | char *curptr; |
| 540 | |
| 541 | *parentptr = 0; |
| 542 | *nodeptr = 0; |
| 543 | |
| 544 | |
| 545 | if ((nodeString[0] != '/') |
| |
| 546 | || (strlen(&nodeString[0]) <= 1) |
| 547 | ) { |
| 548 | printf("FindDump: %s, error in dump name specification\n", |
| 549 | nodeString); |
| 550 | return (-3); |
| 551 | } |
| 552 | |
| 553 | matchLength = 0; |
| 554 | curptr = &nodeString[1]; |
| 555 | separator = strchr(curptr, '/'); |
| 556 | if (separator == 0) |
| |
| 557 | matchLength = strlen(curptr) + 1; |
| 558 | else |
| 559 | matchLength = (separator - &nodeString[0]); |
| 560 | |
| 561 | |
| 562 | while (1) { |
| 3 | Loop condition is true. Entering loop body |
|
| 563 | |
| 564 | for (dsptr = aconfig->dsched; dsptr != 0; dsptr = dsptr->next) { |
| 4 | Loop condition is true. Entering loop body |
|
| 565 | |
| 566 | |
| 567 | if (strlen(dsptr->name) != matchLength) |
| |
| 568 | continue; |
| 569 | |
| 570 | if (strncmp(dsptr->name, nodeString, matchLength) == 0) { |
| |
| 571 | *nodeptr = dsptr; |
| 572 | break; |
| 7 | Execution continues on line 576 |
|
| 573 | } |
| 574 | } |
| 575 | |
| 576 | if (nodeString[matchLength] == 0) { |
| |
| 577 | |
| 578 | if (*nodeptr) |
| 579 | return (0); |
| 580 | else |
| 581 | |
| 582 | return (-1); |
| 583 | } |
| 584 | |
| 585 | if (*nodeptr == 0) |
| |
| 586 | |
| 587 | return (-2); |
| 588 | |
| 589 | curptr = separator + 1; |
| 590 | if (*curptr == 0) { |
| 10 | Dereference of null pointer (loaded from variable 'curptr') |
|
| 591 | printf("FindDump: trailing / in %s\n", nodeString); |
| 592 | return (-3); |
| 593 | } |
| 594 | |
| 595 | separator = strchr(curptr, '/'); |
| 596 | if (separator == 0) |
| 597 | matchLength = strlen(&nodeString[0]); |
| 598 | else |
| 599 | matchLength = separator - &nodeString[0]; |
| 600 | |
| 601 | *parentptr = *nodeptr; |
| 602 | *nodeptr = 0; |
| 603 | } |
| 604 | } |