Changeset 76 for trunk/src/slib.c
- Timestamp:
- Dec 19, 2006, 10:01:59 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/slib.c
r34 r76 48 48 #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p))) 49 49 #endif 50 51 #define SH_REAL_SET 50 52 51 53 #include "slib.h" … … 566 568 567 569 /* 568 * A memset that does not get optimized away 570 * Have memset in a different translation unit (i.e. this) to prevent 571 * it to get optimized away 569 572 */ 570 573 void *sl_memset(void *s, int c, size_t n) 571 574 { 572 volatile char *p = (char *) s; 573 574 if (s != NULL) 575 { 576 while (n--) 577 *p++ = c; 578 } 579 return s; 575 return memset(s, c,n); 580 576 } 581 577 … … 870 866 register const char * q; 871 867 872 if ( dst == NULL)873 return SL_ENONE;874 if (src == NULL || *src == '\0')875 return SL_ENONE; 876 877 if (siz > 0) { 878 879 /* How much free space do we have ? 880 */ 881 dst_end = strlen(dst); 882 dst_free = siz - dst_end - 1;883 884 p = &dst[dst_end]; 885 q = src; 886 887 while (dst_free > 0 && *q != '\0') 888 { 889 *p++ = *q++;890 --dst_free;891 } 892 893 /* NULL terminate dst. 894 */ 895 *p = '\0'; 896 897 if (*q != '\0') 898 899 900 868 if (!(dst == NULL || src == NULL || *src == '\0')) 869 { 870 if (siz > 0) 871 { 872 873 /* How much free space do we have ? 874 */ 875 dst_end = strlen(dst); 876 dst_free = siz - dst_end - 1; 877 878 p = &dst[dst_end]; 879 q = src; 880 881 while (dst_free > 0 && *q != '\0') 882 { 883 *p++ = *q++; 884 --dst_free; 885 } 886 887 /* NULL terminate dst. 888 */ 889 *p = '\0'; 890 891 if (*q == '\0') 892 return SL_ENONE; 893 else 894 return SL_ETRUNC; 895 } 896 } 901 897 return SL_ENONE; 902 898 } … … 917 913 /* SL_ENTER(_("sl_strlcpy")); */ 918 914 919 if (dst == NULL) 920 return SL_ENULL; 921 if (src == NULL) 922 { 915 if (!((dst == NULL) || (src == NULL))) 916 { 917 if (siz > 0) { 918 /* copy siz-1 characters 919 */ 920 (void) strncpy(dst, src, siz-1); 921 922 /* NULL terminate 923 */ 924 dst[siz-1] = '\0'; 925 } 926 return SL_ENONE; 927 } 928 else if (src == NULL) 929 { 923 930 if (siz > 0) 924 931 dst[0] = '\0'; 925 932 return SL_ENONE; 926 933 } 927 928 929 if (siz > 0) { 930 /* copy siz-1 characters 931 */ 932 (void) strncpy(dst, src, siz-1); 933 934 /* NULL terminate 935 */ 936 dst[siz-1] = '\0'; 937 } 938 return SL_ENONE; 934 else 935 { 936 return SL_ENULL; 937 } 939 938 } 940 939 … … 1574 1573 } 1575 1574 1576 SL_TICKET sl_make_ticket (int fd, c har * filename)1575 SL_TICKET sl_make_ticket (int fd, const char * filename) 1577 1576 { 1578 1577 size_t len; … … 2376 2375 } 2377 2376 2377 int sl_write_line_fast (SL_TICKET ticket, void * msg, long nbytes) 2378 { 2379 int status; 2380 char * p = (char *) msg; 2381 2382 SL_ENTER(_("sl_write_line_fast")); 2383 2384 /* Here nbytes is strlen(msg), so p[nbytes] is the terminating '\0' 2385 * Overwrite the terminator, write out, then write back the terminator. 2386 */ 2387 p[nbytes] = '\n'; 2388 status = sl_write(ticket, msg, nbytes+1); 2389 p[nbytes] = '\0'; 2390 2391 SL_IRETURN(status, _("sl_write_line_fast")); 2392 } 2393 2378 2394 2379 2395 /* ---------------------------------------------------------------- … … 2389 2405 extern char tf_path[MAXFILENAME]; /* Error path for trust function. */ 2390 2406 extern uid_t tf_euid; /* Space for EUID of process. */ 2391 2392 2407 2393 2408 char * sl_error_string(int errorcode) … … 2490 2505 } 2491 2506 2507 #include "sh_mem.h" 2508 extern char * sh_util_strdup (const char * str); 2509 2510 struct sl_trustfile_store { 2511 char * filename; 2512 uid_t teuid; 2513 struct sl_trustfile_store * next; 2514 }; 2515 2516 static struct sl_trustfile_store * sl_trusted_files = NULL; 2517 2518 void sl_add_trusted_file(char * filename, uid_t teuid) 2519 { 2520 struct sl_trustfile_store *new = SH_ALLOC(sizeof(struct sl_trustfile_store)); 2521 2522 new->filename = sh_util_strdup (filename); 2523 new->teuid = teuid; 2524 new->next = sl_trusted_files; 2525 2526 sl_trusted_files = new; 2527 return; 2528 } 2529 2530 char * sl_check_trusted_file(char * filename, uid_t teuid) 2531 { 2532 struct sl_trustfile_store *new = sl_trusted_files; 2533 2534 while (new) 2535 { 2536 if ((new->teuid == teuid) && (0 == strcmp(new->filename, filename))) 2537 return filename; 2538 new = new->next; 2539 } 2540 2541 return NULL; 2542 } 2543 2544 void sl_clear_trusted_file(struct sl_trustfile_store * file) 2545 { 2546 if (file) 2547 { 2548 if (file->next != NULL) 2549 sl_clear_trusted_file(file->next); 2550 SH_FREE(file->filename); 2551 SH_FREE(file); 2552 } 2553 return; 2554 } 2555 2492 2556 int sl_trustfile_euid(char * filename, uid_t teuid) 2493 2557 { 2494 long status; 2558 long status; 2559 static time_t old = 0; 2560 static time_t now; 2561 2495 2562 SL_ENTER(_("sl_trustfile_euid")); 2496 2563 … … 2499 2566 SL_IRETURN(SL_EBADNAME, _("sl_trustfile_euid")); 2500 2567 2568 now = time(NULL); 2569 if (now < (old + 300)) 2570 { 2571 if (NULL != sl_check_trusted_file(filename, teuid)) 2572 { 2573 sl_strlcpy(tf_path, filename, sizeof(tf_path)); 2574 SL_IRETURN(SL_ENONE, _("sl_trustfile_euid")); 2575 } 2576 } 2577 else 2578 { 2579 sl_clear_trusted_file(sl_trusted_files); 2580 sl_trusted_files = NULL; 2581 old = now; 2582 } 2583 2501 2584 tf_euid = teuid; 2502 2585 status = sl_trustfile(filename, NULL, NULL); 2586 if (status == SL_ENONE) 2587 sl_add_trusted_file(filename, teuid); 2503 2588 SL_IRETURN(status, _("sl_trustfile_euid")); 2504 2589 }
Note:
See TracChangeset
for help on using the changeset viewer.