Changeset 227 for trunk/src/trustfile.c
- Timestamp:
- Apr 20, 2009, 5:59:31 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/trustfile.c
r221 r227 422 422 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 423 423 struct group gr; 424 char buffer[SH_GRBUF_SIZE];424 char * buffer = NULL; 425 425 struct passwd pwd; 426 char pbuffer[SH_PWBUF_SIZE];426 char * pbuffer = NULL; 427 427 #endif 428 428 … … 430 430 431 431 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 432 sh_getgrgid_r(grp, &gr, buffer, sizeof(buffer), &g); 432 buffer = malloc(SH_GRBUF_SIZE); 433 sh_getgrgid_r(grp, &gr, buffer, SH_GRBUF_SIZE, &g); 433 434 #else 434 435 g = sh_getgrgid(grp); … … 437 438 if (g == NULL) 438 439 { 439 SL_IRETURN(SL_FALSE, _("isingrp") ); 440 } 441 /* 442 if(g->gr_mem == NULL || g->gr_mem[0] == NULL ) 443 SL_IRETURN(SL_FALSE, _("isingrp") ); 444 */ 440 goto end_false; 441 } 445 442 446 443 /* this will return at the first match 447 444 */ 445 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 446 pbuffer = malloc(SH_PWBUF_SIZE); 447 #endif 448 448 449 for(p = g->gr_mem; *p != NULL; p++) 449 450 { … … 452 453 /* map user name to UID and compare */ 453 454 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 454 sh_getpwnam_r(*p, &pwd, pbuffer, sizeof(pbuffer), &w);455 sh_getpwnam_r(*p, &pwd, pbuffer, SH_PWBUF_SIZE, &w); 455 456 #else 456 457 w = sh_getpwnam(*p); … … 459 460 #ifdef TRUST_MAIN 460 461 if (w != NULL && *u == (uid_t)(w->pw_uid) ) 461 SL_IRETURN(SL_TRUE, _("isingrp"));462 goto end_true; 462 463 #else 463 464 if (w != NULL && *u == (uid_t)(w->pw_uid) ) 464 465 { 465 SL_IRETURN(SL_TRUE, _("isingrp"));466 goto end_true; 466 467 } 467 468 #endif … … 474 475 { 475 476 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWUID_R) 476 sh_getpwuid_r(*u, &pwd, pbuffer, sizeof(pbuffer), &w);477 sh_getpwuid_r(*u, &pwd, pbuffer, SH_PWBUF_SIZE, &w); 477 478 #else 478 479 w = sh_getpwuid(*u); … … 480 481 #ifdef TRUST_MAIN 481 482 if (w != NULL && grp == (gid_t)(w->pw_gid) ) 482 SL_IRETURN(SL_TRUE, _("isingrp"));483 goto end_true; 483 484 #else 484 485 if (w != NULL && grp == (gid_t)(w->pw_gid) ) 485 486 { 486 SL_IRETURN(SL_TRUE, _("isingrp")); 487 } 488 #endif 489 } 490 487 goto end_true; 488 } 489 #endif 490 } 491 492 end_false: 493 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 494 if (buffer) free(buffer); 495 if (pbuffer) free(pbuffer); 496 #endif 491 497 SL_IRETURN(SL_FALSE, _("isingrp")); 498 499 end_true: 500 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 501 if (buffer) free(buffer); 502 if (pbuffer) free(pbuffer); 503 #endif 504 SL_IRETURN(SL_TRUE, _("isingrp")); 492 505 } 493 506 … … 506 519 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 507 520 struct group gr; 508 char buffer[SH_GRBUF_SIZE];521 char * buffer = NULL; 509 522 struct passwd pw; 510 char pbuffer[SH_PWBUF_SIZE];523 char * pbuffer = NULL; 511 524 #endif 512 525 … … 521 534 522 535 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 523 sh_getgrgid_r(grp, &gr, buffer, sizeof(buffer), &g); 536 buffer = malloc(SH_GRBUF_SIZE); 537 sh_getgrgid_r(grp, &gr, buffer, SH_GRBUF_SIZE, &g); 524 538 #else 525 539 g = sh_getgrgid(grp); … … 533 547 (UID_CAST)grp); 534 548 #endif 535 SL_IRETURN(SL_FALSE, _("onlytrustedingrp") ); 549 retval = SL_FALSE; 550 goto end_retval; 536 551 } 537 552 … … 544 559 /* check for untrusted members of the group 545 560 */ 561 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 562 pbuffer = malloc(SH_PWBUF_SIZE); 563 #endif 564 546 565 for(p = g->gr_mem; *p != NULL; p++) 547 566 { … … 553 572 */ 554 573 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R) 555 sh_getpwnam_r(*p, &pw, pbuffer, sizeof(pbuffer), &w);574 sh_getpwnam_r(*p, &pw, pbuffer, SH_PWBUF_SIZE, &w); 556 575 #else 557 576 w = sh_getpwnam(*p); … … 601 620 #endif 602 621 tf_baduid = w->pw_uid; 603 SL_IRETURN(SL_FALSE, _("onlytrustedingrp")); 604 } 605 } 622 retval = SL_FALSE; 623 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 624 if (pbuffer) free(pbuffer); 625 #endif 626 goto end_retval; 627 } 628 } 629 630 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 631 if (pbuffer) free(pbuffer); 632 #endif 606 633 607 634 #ifndef TEST_ONLY … … 680 707 /* all found 681 708 */ 709 end_retval: 710 #if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R) 711 if (buffer) free(buffer); 712 #endif 682 713 SL_IRETURN(retval, _("onlytrustedingrp")); 683 714 } … … 685 716 int sl_trustfile(const char *fname, uid_t *okusers, uid_t *badusers) 686 717 { 687 char fexp[MAXFILENAME];/* file name fully expanded */688 register char *p = fexp;/* used to hold name to be checked */718 char * fexp = NULL; /* file name fully expanded */ 719 register char *p; /* used to hold name to be checked */ 689 720 struct stat stbuf; /* used to check file permissions */ 690 721 char c; /* used to hold temp char */ … … 693 724 if (fname == NULL) 694 725 SL_IRETURN(SL_EBADFILE, _("sl_trustfile")); 726 727 fexp = malloc( MAXFILENAME ); 728 if (!fexp) 729 SL_IRETURN(SL_EMEM, _("sl_trustfile")); 730 731 p = fexp; 695 732 696 733 /* … … 701 738 sl_errno = getfname(fname, fexp, MAXFILENAME); 702 739 if (sl_errno != 0) 703 return sl_errno; 740 { 741 free(fexp); 742 return sl_errno; 743 } 704 744 #else 705 745 if (SL_ISERROR(getfname(fname, fexp, MAXFILENAME))) 746 { 747 free(fexp); 706 748 SL_IRETURN(sl_errno, _("sl_trustfile")); 749 } 707 750 #endif 708 751 … … 755 798 fprintf(stderr, "---------------------------------------------\n"); 756 799 #endif 800 free(fexp); 757 801 SL_IRETURN(SL_ESTAT, _("sl_trustfile")); 758 802 } … … 781 825 * got it? 782 826 */ 783 char csym[MAXFILENAME];/* contents of symlink file */784 char full[MAXFILENAME];/* "full" name of symlink */827 char * csym; /* contents of symlink file */ 828 char * full; /* "full" name of symlink */ 785 829 register char *b, *t; /* used to copy stuff around */ 786 830 register int lsym; /* num chars in symlink ref */ … … 797 841 * R.W. Tue May 29 22:05:16 CEST 2001 798 842 */ 843 csym = malloc( MAXFILENAME ); 844 if (!csym) 845 { 846 free(fexp); 847 SL_IRETURN(SL_EMEM, _("sl_trustfile")); 848 } 849 799 850 lsym = readlink(fexp, csym, MAXFILENAME-1); 800 851 if (lsym >= 0) … … 808 859 fprintf(stderr, "---------------------------------------------\n"); 809 860 #endif 861 free(csym); 862 free(fexp); 810 863 SL_IRETURN(SL_EBADNAME, _("sl_trustfile")); 864 } 865 866 full = malloc( MAXFILENAME ); 867 if (!full) 868 { 869 free(csym); 870 free(fexp); 871 SL_IRETURN(SL_EMEM, _("sl_trustfile")); 811 872 } 812 873 … … 857 918 fprintf(stderr, "---------------------------------------------\n"); 858 919 #endif 920 free(full); 921 free(csym); 922 free(fexp); 859 923 SL_IRETURN(SL_ETRUNC, _("sl_trustfile")); 860 924 } … … 872 936 */ 873 937 if ((i = sl_trustfile(full, okusers, badusers)) != SL_ENONE) 874 SL_IRETURN(i, _("sl_trustfile")); 938 { 939 free(full); 940 free(csym); 941 free(fexp); 942 SL_IRETURN(i, _("sl_trustfile")); 943 } 875 944 876 945 /* … … 891 960 p++; 892 961 } 962 free(full); 963 free(csym); 893 964 continue; 894 965 } … … 922 993 923 994 tf_baduid = (uid_t) stbuf.st_uid; 995 free(fexp); 924 996 SL_IRETURN(SL_EBADUID, _("sl_trustfile")); 925 997 } … … 961 1033 962 1034 tf_badgid = (gid_t) stbuf.st_gid; 1035 free(fexp); 963 1036 SL_IRETURN(SL_EBADGID, _("sl_trustfile")); 964 1037 } … … 984 1057 tf_path[sizeof(tf_path)-1] = '\0'; 985 1058 1059 free(fexp); 986 1060 SL_IRETURN(SL_EBADOTH, _("sl_trustfile")); 987 1061 } … … 1009 1083 tf_path[sizeof(tf_path)-1] = '\0'; 1010 1084 1085 free(fexp); 1011 1086 SL_IRETURN(SL_ENONE, _("sl_trustfile")); 1012 1087 }
Note:
See TracChangeset
for help on using the changeset viewer.