Changeset 165 for branches/samba-3.0/source/lib
- Timestamp:
- Mar 11, 2009, 9:14:55 AM (16 years ago)
- Location:
- branches/samba-3.0/source/lib
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.0/source/lib/charcnv.c
r124 r165 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Character set conversion Extensions … … 6 6 Copyright (C) Simo Sorce 2001 7 7 Copyright (C) Martin Pool 2003 8 8 9 9 This program is free software; you can redistribute it and/or modify 10 10 it under the terms of the GNU General Public License as published by 11 11 the Free Software Foundation; either version 2 of the License, or 12 12 (at your option) any later version. 13 13 14 14 This program is distributed in the hope that it will be useful, 15 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 17 GNU General Public License for more details. 18 18 19 19 You should have received a copy of the GNU General Public License 20 20 along with this program; if not, write to the Free Software … … 35 35 * 36 36 * @brief Character-set conversion routines built on our iconv. 37 * 37 * 38 38 * @note Samba's internal character set (at least in the 3.0 series) 39 39 * is always the same as the one for the Unix filesystem. It is … … 145 145 const char *n2 = charset_name((charset_t)c2); 146 146 if (conv_handles[c1][c2] && 147 148 147 strcmp(n1, conv_handles[c1][c2]->from_name) == 0 && 148 strcmp(n2, conv_handles[c1][c2]->to_name) == 0) 149 149 continue; 150 150 … … 202 202 203 203 static size_t convert_string_internal(charset_t from, charset_t to, 204 void const *src, size_t srclen,205 204 void const *src, size_t srclen, 205 void *dest, size_t destlen, BOOL allow_bad_conv) 206 206 { 207 207 size_t i_len, o_len; … … 237 237 retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len); 238 238 if(retval==(size_t)-1) { 239 239 const char *reason="unknown error"; 240 240 switch(errno) { 241 241 case EINVAL: … … 247 247 break; 248 248 case E2BIG: 249 reason="No more room"; 249 reason="No more room"; 250 250 if (!conv_silent) { 251 251 if (from == CH_UNIX) { … … 278 278 use_as_is: 279 279 280 /* 280 /* 281 281 * Conversion not supported. This is actually an error, but there are so 282 282 * many misconfigured iconv systems and smb.conf's out there we can't just … … 376 376 377 377 size_t convert_string(charset_t from, charset_t to, 378 void const *src, size_t srclen,379 378 void const *src, size_t srclen, 379 void *dest, size_t destlen, BOOL allow_bad_conv) 380 380 { 381 381 /* … … 518 518 * 519 519 * Ensure the srclen contains the terminating zero. 520 * 520 * 521 521 * I hate the goto's in this function. It's embarressing..... 522 522 * There has to be a cleaner way to do this. JRA. … … 524 524 525 525 size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to, 526 526 void const *src, size_t srclen, void *dst, BOOL allow_bad_conv) 527 527 { 528 528 size_t i_len, o_len, destlen = (srclen * 3) / 2; … … 584 584 &inbuf, &i_len, 585 585 &outbuf, &o_len); 586 if(retval == (size_t)-1) {587 586 if(retval == (size_t)-1) { 587 const char *reason="unknown error"; 588 588 switch(errno) { 589 589 case EINVAL: … … 595 595 break; 596 596 case E2BIG: 597 goto convert; 597 goto convert; 598 598 case EILSEQ: 599 599 reason="Illegal multibyte sequence"; … … 630 630 ob[destlen] = '\0'; 631 631 ob[destlen+1] = '\0'; 632 632 633 return destlen; 633 634 634 635 use_as_is: 635 636 636 /* 637 /* 637 638 * Conversion not supported. This is actually an error, but there are so 638 639 * many misconfigured iconv systems and smb.conf's out there we can't just … … 720 721 * 721 722 * @param srclen length of source buffer. 722 * @param dest always set at least to NULL 723 * @param dest always set at least to NULL 723 724 * @note -1 is not accepted for srclen. 724 725 * … … 726 727 **/ 727 728 size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, 728 729 729 void const *src, size_t srclen, void *dst, 730 BOOL allow_bad_conv) 730 731 { 731 732 void **dest = (void **)dst; … … 745 746 size_t size; 746 747 smb_ucs2_t *buffer; 747 748 748 749 size = push_ucs2_allocate(&buffer, src); 749 750 if (size == (size_t)-1) { … … 754 755 return srclen; 755 756 } 756 757 757 758 size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True); 758 759 free(buffer); … … 797 798 798 799 strupper_w(buffer); 799 800 800 801 size = convert_string(CH_UTF16LE, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True); 801 802 if (size == (size_t)-1) { … … 811 812 size_t size; 812 813 smb_ucs2_t *buffer = NULL; 813 814 814 815 size = convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, 815 816 (void **)(void *)&buffer, True); 816 817 if (size == (size_t)-1 || !buffer) { 817 818 smb_panic("failed to create UCS2 buffer"); … … 835 836 smb_ucs2_t *buffer = NULL; 836 837 char *out_buffer; 837 838 838 839 size = push_ucs2_allocate(&buffer, s); 839 840 if (size == -1 || !buffer) { … … 842 843 843 844 strlower_w(buffer); 844 845 845 846 size = pull_ucs2_allocate(&out_buffer, buffer); 846 847 SAFE_FREE(buffer); … … 849 850 return NULL; 850 851 } 851 852 852 853 return out_buffer; 853 854 } … … 879 880 size_t src_len = strlen(src); 880 881 pstring tmpbuf; 881 882 883 884 885 882 size_t ret; 883 884 /* No longer allow a length of -1 */ 885 if (dest_len == (size_t)-1) 886 smb_panic("push_ascii - dest_len == -1"); 886 887 887 888 if (flags & STR_UPPER) { … … 894 895 src_len++; 895 896 896 ret =convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); 897 if (ret == (size_t)-1 && 898 (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) 899 && dest_len > 0) { 900 ((char *)dest)[0] = '\0'; 901 } 902 return ret; 903 897 ret =convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, True); 898 if (ret == (size_t)-1 && 899 (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) 900 && dest_len > 0) { 901 ((char *)dest)[0] = '\0'; 902 } 903 return ret; 904 904 } 905 905 … … 1030 1030 * <dl> 1031 1031 * <dt>STR_TERMINATE <dd>means include the null termination. 1032 * <dt>STR_UPPER 1032 * <dt>STR_UPPER <dd>means uppercase in the destination. 1033 1033 * <dt>STR_NOALIGN <dd>means don't do alignment. 1034 1034 * </dl> … … 1094 1094 * allocating a buffer using talloc(). 1095 1095 * 1096 * @param dest always set at least to NULL 1096 * @param dest always set at least to NULL 1097 1097 * 1098 1098 * @returns The number of bytes occupied by the string in the destination 1099 * 1099 * or -1 in case of error. 1100 1100 **/ 1101 1101 size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src) … … 1111 1111 * Copy a string from a unix char* src to a UCS2 destination, allocating a buffer 1112 1112 * 1113 * @param dest always set at least to NULL 1113 * @param dest always set at least to NULL 1114 1114 * 1115 1115 * @returns The number of bytes occupied by the string in the destination 1116 * 1116 * or -1 in case of error. 1117 1117 **/ 1118 1118 … … 1130 1130 Flags can have: 1131 1131 STR_TERMINATE means include the null termination 1132 STR_UPPER 1132 STR_UPPER means uppercase in the destination 1133 1133 dest_len is the maximum length allowed in the destination. If dest_len 1134 1134 is -1 then no maxiumum is used. … … 1164 1164 * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc 1165 1165 * 1166 * @param dest always set at least to NULL 1166 * @param dest always set at least to NULL 1167 1167 * 1168 1168 * @returns The number of bytes occupied by the string in the destination … … 1180 1180 * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer 1181 1181 * 1182 * @param dest always set at least to NULL 1182 * @param dest always set at least to NULL 1183 1183 * 1184 1184 * @returns The number of bytes occupied by the string in the destination … … 1190 1190 1191 1191 *dest = NULL; 1192 return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, True); 1192 return convert_string_allocate(NULL, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, True); 1193 1193 } 1194 1194 … … 1231 1231 if (src_len != (size_t)-1) 1232 1232 src_len &= ~1; 1233 1233 1234 1234 ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len, True); 1235 1235 if (ret == (size_t)-1) { … … 1239 1239 if (src_len == (size_t)-1) 1240 1240 src_len = ret*2; 1241 1241 1242 1242 if (dest_len && ret) { 1243 1243 /* Did we already process the terminating zero ? */ … … 1265 1265 * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc 1266 1266 * 1267 * @param dest always set at least to NULL 1267 * @param dest always set at least to NULL 1268 1268 * 1269 1269 * @returns The number of bytes occupied by the string in the destination … … 1280 1280 * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer 1281 1281 * 1282 * @param dest always set at least to NULL 1282 * @param dest always set at least to NULL 1283 1283 * 1284 1284 * @returns The number of bytes occupied by the string in the destination … … 1295 1295 * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc 1296 1296 * 1297 * @param dest always set at least to NULL 1297 * @param dest always set at least to NULL 1298 1298 * 1299 1299 * @returns The number of bytes occupied by the string in the destination … … 1310 1310 * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer 1311 1311 * 1312 * @param dest always set at least to NULL 1312 * @param dest always set at least to NULL 1313 1313 * 1314 1314 * @returns The number of bytes occupied by the string in the destination … … 1321 1321 return convert_string_allocate(NULL, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, True); 1322 1322 } 1323 1323 1324 1324 /** 1325 1325 * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc 1326 1326 * 1327 * @param dest always set at least to NULL 1327 * @param dest always set at least to NULL 1328 1328 * 1329 1329 * @returns The number of bytes occupied by the string in the destination … … 1339 1339 /** 1340 1340 Copy a string from a char* src to a unicode or ascii 1341 dos codepage destination choosing unicode or ascii based on the 1341 dos codepage destination choosing unicode or ascii based on the 1342 1342 flags in the SMB buffer starting at base_ptr. 1343 1343 Return the number of bytes occupied by the string in the destination. 1344 1344 flags can have: 1345 1345 STR_TERMINATE means include the null termination. 1346 STR_UPPER 1347 STR_ASCII 1346 STR_UPPER means uppercase in the destination. 1347 STR_ASCII use ascii even with unicode packet. 1348 1348 STR_NOALIGN means don't do alignment. 1349 1349 dest_len is the maximum length allowed in the destination. If dest_len … … 1370 1370 1371 1371 if (!(flags & STR_ASCII) && \ 1372 1373 1372 ((flags & STR_UNICODE || \ 1373 (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { 1374 1374 return push_ucs2(base_ptr, dest, src, dest_len, flags); 1375 1375 } … … 1384 1384 STR_TERMINATE means the string in src is null terminated. 1385 1385 STR_UNICODE means to force as unicode. 1386 STR_ASCII 1386 STR_ASCII use ascii even with unicode packet. 1387 1387 STR_NOALIGN means don't do alignment. 1388 1388 if STR_TERMINATE is set then src_len is ignored is it is -1 … … 1400 1400 1401 1401 if (!(flags & STR_ASCII) && \ 1402 1403 1402 ((flags & STR_UNICODE || \ 1403 (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { 1404 1404 return pull_ucs2(base_ptr, dest, src, dest_len, src_len, flags); 1405 1405 } … … 1410 1410 { 1411 1411 if (!(flags & STR_ASCII) && \ 1412 1413 1412 ((flags & STR_UNICODE || \ 1413 (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { 1414 1414 return ucs2_align(base_ptr, p, flags); 1415 1415 } … … 1434 1434 #ifdef __OS2__ 1435 1435 size_t ilen_max; 1436 size_t olen_orig; 1437 const char *inbuf; 1436 1438 #endif 1437 1439 size_t ilen_orig; 1438 1440 size_t ilen; 1439 size_t olen_orig;1440 1441 size_t olen; 1441 const char *inbuf; 1442 1442 1443 char *outbuf; 1443 1444 … … 1491 1492 break; 1492 1493 1494 1493 1495 case EINVAL : 1494 1496 #ifndef __OS2__ -
branches/samba-3.0/source/lib/debug.c
r124 r165 693 693 * loop check do a new check as root. 694 694 */ 695 695 696 if( geteuid() != 0 ) 696 697 return; … … 715 716 } 716 717 } 718 717 719 /* 718 720 * Here's where we need to panic if dbf == NULL.. -
branches/samba-3.0/source/lib/events.c
r1 r165 65 65 DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te, 66 66 te->event_name)); 67 DLIST_REMOVE(te->event_ctx->timed_events, te); 67 if (te->event_ctx) { 68 DLIST_REMOVE(te->event_ctx->timed_events, te); 69 } 68 70 return 0; 69 71 } … … 135 137 struct event_context *event_ctx = fde->event_ctx; 136 138 137 DLIST_REMOVE(event_ctx->fd_events, fde); 139 if (event_ctx) { 140 DLIST_REMOVE(event_ctx->fd_events, fde); 141 } 138 142 return 0; 139 143 } … … 298 302 } 299 303 304 static int event_context_destructor(struct event_context *ev) 305 { 306 while (ev->fd_events != NULL) { 307 ev->fd_events->event_ctx = NULL; 308 DLIST_REMOVE(ev->fd_events, ev->fd_events); 309 } 310 while (ev->timed_events != NULL) { 311 ev->timed_events->event_ctx = NULL; 312 DLIST_REMOVE(ev->timed_events, ev->timed_events); 313 } 314 return 0; 315 } 316 317 void event_context_reinit(struct event_context *ev) 318 { 319 event_context_destructor(ev); 320 return; 321 } 322 300 323 struct event_context *event_context_init(TALLOC_CTX *mem_ctx) 301 324 { 302 return TALLOC_ZERO_P(NULL, struct event_context); 303 } 304 305 int set_event_dispatch_time(struct event_context *event_ctx, 306 const char *event_name, struct timeval when) 307 { 308 struct timed_event *te; 309 310 for (te = event_ctx->timed_events; te; te = te->next) { 311 if (strcmp(event_name, te->event_name) == 0) { 312 DLIST_REMOVE(event_ctx->timed_events, te); 313 te->when = when; 314 add_event_by_time(te); 315 return 1; 316 } 317 } 318 return 0; 319 } 320 321 /* Returns 1 if event was found and cancelled, 0 otherwise. */ 322 323 int cancel_named_event(struct event_context *event_ctx, 324 const char *event_name) 325 { 326 struct timed_event *te; 327 328 for (te = event_ctx->timed_events; te; te = te->next) { 329 if (strcmp(event_name, te->event_name) == 0) { 330 TALLOC_FREE(te); 331 return 1; 332 } 333 } 334 return 0; 335 } 325 struct event_context *result; 326 327 result = TALLOC_ZERO_P(mem_ctx, struct event_context); 328 if (result == NULL) { 329 return NULL; 330 } 331 332 talloc_set_destructor(result, event_context_destructor); 333 return result; 334 } -
branches/samba-3.0/source/lib/genrand.c
r1 r165 29 29 static void (*reseed_callback)(int *newseed); 30 30 31 32 31 /**************************************************************** 33 32 Copy any user given reseed data. -
branches/samba-3.0/source/lib/iconv.c
r62 r165 187 187 } 188 188 189 189 190 /* otherwise we have to do it chunks at a time */ 190 191 while (*inbytesleft > 0) { -
branches/samba-3.0/source/lib/interfaces.c
r1 r165 83 83 #include "interfaces.h" 84 84 85 #if defHAVE_IFACE_IFCONF85 #if HAVE_IFACE_IFCONF 86 86 87 87 /* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1 -
branches/samba-3.0/source/lib/messages.c
r62 r165 128 128 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, 129 129 O_RDWR|O_CREAT,0600); 130 130 131 if (!tdb) { 131 132 DEBUG(0,("ERROR: Failed to initialise messages database\n")); -
branches/samba-3.0/source/lib/replace/autoconf-2.60.m4
r39 r165 180 180 # Enable extensions on systems that normally disable them, 181 181 # typically due to standards-conformance issues. 182 m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[ 182 183 AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], 183 184 [ … … 209 210 AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) 210 211 ]) 212 ]) -
branches/samba-3.0/source/lib/select.c
r33 r165 29 29 This means all Samba signal handlers should call sys_select_signal(). 30 30 */ 31 31 32 static pid_t initialised; 32 33 static int select_pipe[2]; … … 95 96 errno = 0; 96 97 ret = select(maxfd,readfds2,writefds,errorfds,tval); 98 97 99 if (ret <= 0) { 98 100 FD_ZERO(readfds2); -
branches/samba-3.0/source/lib/util.c
r105 r165 1992 1992 SMB_STRUCT_FLOCK lock; 1993 1993 int ret; 1994 1995 DEBUG(8,("fcntl_lock fd=%d op=%d offset=%.0f count=%.0f type=%d\n", 1996 fd,op,(double)offset,(double)count,type)); 1994 1997 1995 1998 lock.l_type = type; … … 3335 3338 return talloc_named_const(context, size, name); 3336 3339 } 3340 3341 bool reinit_after_fork(struct messaging_context *msg_ctx, 3342 struct event_context *ev_ctx, 3343 bool parent_longlived) 3344 { 3345 set_need_random_reseed(); 3346 if (tdb_reopen_all(parent_longlived ? 1 : 0) == -1) { 3347 DEBUG(0, ("tdb_reopen_all failed.\n")); 3348 return false; 3349 } 3350 event_context_reinit(ev_ctx); 3351 return true; 3352 } -
branches/samba-3.0/source/lib/util_sock.c
r161 r165 155 155 {"TCP_KEEPINTVL", IPPROTO_TCP, TCP_KEEPINTVL, 0, OPT_INT}, 156 156 #endif 157 #if defined(IPTOS_LOWDELAY) && !defined(TCPV40HDRS)157 #ifdef IPTOS_LOWDELAY 158 158 {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON}, 159 159 #endif 160 #if defined(IPTOS_THROUGHPUT) && !defined(TCPV40HDRS)160 #ifdef IPTOS_THROUGHPUT 161 161 {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON}, 162 162 #endif -
branches/samba-3.0/source/lib/util_tdb.c
r134 r165 82 82 tdb_setalarm_sigptr(tdb, NULL); 83 83 CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); 84 if (gotalarm ) {84 if (gotalarm && (ret == -1)) { 85 85 DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n", 86 86 timeout, key.dptr, tdb_name(tdb)));
Note:
See TracChangeset
for help on using the changeset viewer.