- Timestamp:
- Oct 27, 2007, 12:51:09 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_entropy.c
r133 r135 117 117 int sh_entropy(int getbytes, char * nbuf) 118 118 { 119 staticint fd = -1;119 int fd = -1; 120 120 int n; 121 121 byte buffer[256+2]; … … 148 148 int addr_len; 149 149 150 150 #ifdef EGD_SOCKET_NAME 151 151 bname = EGD_SOCKET_NAME; 152 152 #endif 153 153 if ( !bname || !*bname ) 154 154 bname = _("=entropy"); … … 191 191 _("sh_entropy") ); 192 192 SH_FREE(name); 193 close(fd); 193 194 SL_RETURN( -1, _("sh_entropy") ); 194 195 } … … 206 207 sh_error_handle ((-1), FIL__, __LINE__, myerror, MSG_E_SUBGEN, 207 208 _("cannot write to EGD"), 208 _("sh_entropy") ); 209 _("sh_entropy") ); 210 close(fd); 209 211 SL_RETURN( -1, _("sh_entropy") ); 210 212 } … … 247 249 sh_error_handle ((-1), FIL__, __LINE__, myerror, MSG_E_SUBGEN, 248 250 _("cannot write to EGD"), 249 _("sh_entropy") ); 251 _("sh_entropy") ); 252 close(fd); 250 253 SL_RETURN( -1, _("sh_entropy") ); 251 254 } … … 267 270 } 268 271 memset(buffer, 0, sizeof(buffer) ); 269 272 close(fd); 270 273 SL_RETURN( 0, _("sh_entropy") ); /* success */ 271 274 } … … 275 278 276 279 #if defined (HAVE_URANDOM) 280 281 #include "sh_pthread.h" 277 282 278 283 int read_mbytes(int timeout_val, char * path, char * nbuf, int nbytes) … … 373 378 /* -- Give out nbytes bytes from the new pool. -- 374 379 */ 380 SH_MUTEX_LOCK_UNSAFE(mutex_skey); 375 381 for (i = 0; i < KEY_BYT; ++i) 376 382 { … … 379 385 nbuf[i] = keybuf[i]; 380 386 } 387 SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); 381 388 memset (keybuf, '\0', KEY_BYT); 382 389 … … 408 415 409 416 #include "sh_static.h" 417 #include "sh_pthread.h" 410 418 411 419 static … … 432 440 433 441 static 434 sourcetable_t source [] = {442 sourcetable_t source_template[] = { 435 443 { N_("w"), 436 444 N_("w"), … … 712 720 int imax, selcount; 713 721 char errbuf[SH_ERRBUF_SIZE]; 722 723 sourcetable_t *source = NULL; 714 724 715 725 SL_ENTER(_("sh_entropy")); … … 723 733 /* --- If there is entropy in the pool, return it. --- 724 734 */ 735 SH_MUTEX_LOCK_UNSAFE(mutex_skey); 725 736 if (skey->poolc >= nbytes) 726 737 { … … 731 742 --skey->poolc; 732 743 } 744 SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); /* alternative path */ 733 745 SL_RETURN(0, _("sh_entropy")); 734 746 } 747 SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); 735 748 736 749 … … 746 759 _("sl_get_cap_sub")); 747 760 } 761 762 while (source_template[i].command != NULL) { 763 ++i; 764 } 765 source = SH_ALLOC(i * sizeof(sourcetable_t)); 766 for (j = 0; j < i;++j) 767 memcpy(&source[j], &source_template[j], sizeof(sourcetable_t)); 768 i = 0; 748 769 749 770 while (source[i].command != NULL) { … … 877 898 } 878 899 buffer[bufcount] = '\0'; 900 901 SH_FREE(source); 879 902 880 903 if (0 != (caperr = sl_drop_cap_sub())) … … 906 929 /* store in system pool 907 930 */ 931 SH_MUTEX_LOCK_UNSAFE(mutex_skey); 908 932 for (i = 0; i < KEY_BYT; ++i) 909 933 skey->poolv[i] = keybuf[i]; 910 934 skey->poolc = KEY_BYT; 935 SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); 911 936 memset (buffer, '\0', BUF_ENT+2); 912 937 memset (keybuf, '\0', KEY_BYT); … … 921 946 /* give out nbytes Bytes from the entropy pool 922 947 */ 948 SH_MUTEX_LOCK_UNSAFE(mutex_skey); 923 949 for (i = 0; i < nbytes; ++i) 924 950 { … … 926 952 --skey->poolc; 927 953 } 954 SH_MUTEX_UNLOCK_UNSAFE(mutex_skey); 928 955 929 956 SL_RETURN(0, _("sh_entropy"));
Note:
See TracChangeset
for help on using the changeset viewer.