Changeset 745 for trunk/server/source3/libsmb/libsmb_context.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/libsmb/libsmb_context.c
r414 r745 8 8 Copyright (C) Derrell Lipman 2003-2008 9 9 Copyright (C) Jeremy Allison 2007, 2008 10 10 11 11 This program is free software; you can redistribute it and/or modify 12 12 it under the terms of the GNU General Public License as published by 13 13 the Free Software Foundation; either version 3 of the License, or 14 14 (at your option) any later version. 15 15 16 16 This program is distributed in the hope that it will be useful, 17 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 19 GNU General Public License for more details. 20 20 21 21 You should have received a copy of the GNU General Public License 22 22 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 24 24 25 25 #include "includes.h" 26 #include "libsmb/libsmb.h" 26 27 #include "libsmbclient.h" 27 28 #include "libsmb_internal.h" 29 #include "secrets.h" 28 30 29 31 … … 44 46 char *home = NULL; 45 47 TALLOC_CTX *frame = talloc_stackframe(); 46 47 load_case_tables ();48 49 setup_logging("libsmbclient", True);48 49 load_case_tables_library(); 50 51 setup_logging("libsmbclient", DEBUG_STDOUT); 50 52 51 53 /* Here we would open the smb.conf file if needed ... */ 52 54 53 55 lp_set_in_client(True); 54 56 55 57 home = getenv("HOME"); 56 58 if (home) { … … 66 68 } 67 69 } 68 70 69 71 if (!conf_loaded) { 70 72 /* … … 74 76 * defaults ... 75 77 */ 76 78 77 79 if (!lp_load(get_dyn_CONFIGFILE(), True, False, False, False)) { 78 80 DEBUG(5, ("Could not load config file: %s\n", … … 98 100 } 99 101 } 100 102 101 103 load_interfaces(); /* Load the list of interfaces ... */ 102 104 103 105 reopen_logs(); /* Get logging working ... */ 104 106 105 107 /* 106 108 * Block SIGPIPE (from lib/util_sock.c: write()) … … 108 110 */ 109 111 BlockSignals(True, SIGPIPE); 110 112 111 113 /* Create the mutex we'll use to protect initialized_ctx_count */ 112 114 if (SMB_THREAD_CREATE_MUTEX("initialized_ctx_count_mutex", … … 137 139 { 138 140 SMBCCTX *context; 139 141 140 142 /* The first call to this function should initialize the module */ 141 143 SMB_THREAD_ONCE(&SMBC_initialized, SMBC_module_init, NULL); … … 150 152 return NULL; 151 153 } 152 154 153 155 ZERO_STRUCTP(context); 154 156 155 157 context->internal = SMB_MALLOC_P(struct SMBC_internal_data); 156 158 if (!context->internal) { … … 159 161 return NULL; 160 162 } 161 163 162 164 /* Initialize the context and establish reasonable defaults */ 163 165 ZERO_STRUCTP(context->internal); 164 166 165 167 smbc_setDebug(context, 0); 166 168 smbc_setTimeout(context, 20000); 167 169 168 170 smbc_setOptionFullTimeNames(context, False); 169 171 smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE); … … 177 179 smbc_setOptionUseCCache(context, true); 178 180 } 179 181 180 182 smbc_setFunctionAuthData(context, SMBC_get_auth_data); 181 183 smbc_setFunctionCheckServer(context, SMBC_check_server); 182 184 smbc_setFunctionRemoveUnusedServer(context, SMBC_remove_unused_server); 183 185 184 186 smbc_setOptionUserData(context, NULL); 185 187 smbc_setFunctionAddCachedServer(context, SMBC_add_cached_server); … … 187 189 smbc_setFunctionRemoveCachedServer(context, SMBC_remove_cached_server); 188 190 smbc_setFunctionPurgeCachedServers(context, SMBC_purge_cached_servers); 189 191 190 192 smbc_setFunctionOpen(context, SMBC_open_ctx); 191 193 smbc_setFunctionCreat(context, SMBC_creat_ctx); … … 216 218 smbc_setFunctionRemovexattr(context, SMBC_removexattr_ctx); 217 219 smbc_setFunctionListxattr(context, SMBC_listxattr_ctx); 218 220 219 221 smbc_setFunctionOpenPrintJob(context, SMBC_open_print_job_ctx); 220 222 smbc_setFunctionPrintFile(context, SMBC_print_file_ctx); 221 223 smbc_setFunctionListPrintJobs(context, SMBC_list_print_jobs_ctx); 222 224 smbc_setFunctionUnlinkPrintJob(context, SMBC_unlink_print_job_ctx); 223 225 224 226 return context; 225 227 } … … 240 242 return 1; 241 243 } 242 244 243 245 if (shutdown_ctx) { 244 246 SMBCFILE * f; 245 247 DEBUG(1,("Performing aggressive shutdown.\n")); 246 248 247 249 f = context->internal->files; 248 250 while (f) { … … 251 253 } 252 254 context->internal->files = NULL; 253 255 254 256 /* First try to remove the servers the nice way. */ 255 257 if (smbc_getFunctionPurgeCachedServers(context)(context)) { … … 294 296 } 295 297 } 296 298 297 299 /* Things we have to clean up */ 298 300 smbc_setWorkgroup(context, NULL); 299 301 smbc_setNetbiosName(context, NULL); 300 302 smbc_setUser(context, NULL); 301 303 302 304 DEBUG(3, ("Context %p successfully freed\n", context)); 303 305 … … 325 327 smb_panic("error unlocking 'initialized_ctx_count'"); 326 328 } 327 329 328 330 return 0; 329 331 } … … 347 349 const char *s; 348 350 } option_value; 349 351 350 352 va_start(ap, option_name); 351 353 352 354 if (strcmp(option_name, "debug_to_stderr") == 0) { 353 355 option_value.b = (bool) va_arg(ap, int); 354 356 smbc_setOptionDebugToStderr(context, option_value.b); 355 357 356 358 } else if (strcmp(option_name, "full_time_names") == 0) { 357 359 option_value.b = (bool) va_arg(ap, int); 358 360 smbc_setOptionFullTimeNames(context, option_value.b); 359 361 360 362 } else if (strcmp(option_name, "open_share_mode") == 0) { 361 363 option_value.i = va_arg(ap, int); 362 364 smbc_setOptionOpenShareMode(context, option_value.i); 363 365 364 366 } else if (strcmp(option_name, "auth_function") == 0) { 365 367 option_value.auth_fn = 366 368 va_arg(ap, smbc_get_auth_data_with_context_fn); 367 369 smbc_setFunctionAuthDataWithContext(context, option_value.auth_fn); 368 370 369 371 } else if (strcmp(option_name, "user_data") == 0) { 370 372 option_value.v = va_arg(ap, void *); 371 373 smbc_setOptionUserData(context, option_value.v); 372 374 373 375 } else if (strcmp(option_name, "smb_encrypt_level") == 0) { 374 376 option_value.s = va_arg(ap, const char *); … … 383 385 SMBC_ENCRYPTLEVEL_REQUIRE); 384 386 } 385 387 386 388 } else if (strcmp(option_name, "browse_max_lmb_count") == 0) { 387 389 option_value.i = va_arg(ap, int); 388 390 smbc_setOptionBrowseMaxLmbCount(context, option_value.i); 389 391 390 392 } else if (strcmp(option_name, "urlencode_readdir_entries") == 0) { 391 393 option_value.b = (bool) va_arg(ap, int); 392 394 smbc_setOptionUrlEncodeReaddirEntries(context, option_value.b); 393 395 394 396 } else if (strcmp(option_name, "one_share_per_server") == 0) { 395 397 option_value.b = (bool) va_arg(ap, int); 396 398 smbc_setOptionOneSharePerServer(context, option_value.b); 397 399 398 400 } else if (strcmp(option_name, "use_kerberos") == 0) { 399 401 option_value.b = (bool) va_arg(ap, int); 400 402 smbc_setOptionUseKerberos(context, option_value.b); 401 403 402 404 } else if (strcmp(option_name, "fallback_after_kerberos") == 0) { 403 405 option_value.b = (bool) va_arg(ap, int); 404 406 smbc_setOptionFallbackAfterKerberos(context, option_value.b); 405 407 406 408 } else if (strcmp(option_name, "use_ccache") == 0) { 407 409 option_value.b = (bool) va_arg(ap, int); … … 412 414 smbc_setOptionNoAutoAnonymousLogin(context, option_value.b); 413 415 } 414 416 415 417 va_end(ap); 416 418 } … … 431 433 return (void *) smbc_getOptionDebugToStderr(context); 432 434 #endif 433 435 434 436 } else if (strcmp(option_name, "full_time_names") == 0) { 435 437 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 438 440 return (void *) smbc_getOptionFullTimeNames(context); 439 441 #endif 440 442 441 443 } else if (strcmp(option_name, "open_share_mode") == 0) { 442 444 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 445 447 return (void *) smbc_getOptionOpenShareMode(context); 446 448 #endif 447 449 448 450 } else if (strcmp(option_name, "auth_function") == 0) { 449 451 return (void *) smbc_getFunctionAuthDataWithContext(context); 450 452 451 453 } else if (strcmp(option_name, "user_data") == 0) { 452 454 return smbc_getOptionUserData(context); 453 455 454 456 } else if (strcmp(option_name, "smb_encrypt_level") == 0) { 455 457 switch(smbc_getOptionSmbEncryptionLevel(context)) … … 462 464 return (void *) "require"; 463 465 } 464 466 465 467 } else if (strcmp(option_name, "smb_encrypt_on") == 0) { 466 468 SMBCSRV *s; 467 469 unsigned int num_servers = 0; 468 470 469 471 for (s = context->internal->servers; s; s = s->next) { 470 472 num_servers++; … … 478 480 return (void *) (bool) (num_servers > 0); 479 481 #endif 480 482 481 483 } else if (strcmp(option_name, "browse_max_lmb_count") == 0) { 482 484 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 485 487 return (void *) smbc_getOptionBrowseMaxLmbCount(context); 486 488 #endif 487 489 488 490 } else if (strcmp(option_name, "urlencode_readdir_entries") == 0) { 489 491 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 492 494 return (void *) (bool) smbc_getOptionUrlEncodeReaddirEntries(context); 493 495 #endif 494 496 495 497 } else if (strcmp(option_name, "one_share_per_server") == 0) { 496 498 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 499 501 return (void *) (bool) smbc_getOptionOneSharePerServer(context); 500 502 #endif 501 503 502 504 } else if (strcmp(option_name, "use_kerberos") == 0) { 503 505 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 506 508 return (void *) (bool) smbc_getOptionUseKerberos(context); 507 509 #endif 508 510 509 511 } else if (strcmp(option_name, "fallback_after_kerberos") == 0) { 510 512 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 513 515 return (void *) (bool) smbc_getOptionFallbackAfterKerberos(context); 514 516 #endif 515 517 516 518 } else if (strcmp(option_name, "use_ccache") == 0) { 517 519 #if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T) … … 528 530 #endif 529 531 } 530 532 531 533 return NULL; 532 534 } … … 544 546 { 545 547 int pid; 546 548 547 549 if (!context) { 548 550 errno = EBADF; 549 551 return NULL; 550 552 } 551 553 552 554 /* Do not initialise the same client twice */ 553 555 if (context->internal->initialized) { 554 556 return NULL; 555 557 } 556 557 if (context->internal->debug_stderr) { 558 /* 559 * Hmmm... Do we want a unique dbf per-thread? For now, we'll just 560 * leave it up to the user. If any one context spefies debug to 561 * stderr then all will be. 562 */ 563 dbf = x_stderr; 564 x_setbuf(x_stderr, NULL); 565 } 566 558 567 559 if ((!smbc_getFunctionAuthData(context) && 568 560 !smbc_getFunctionAuthDataWithContext(context)) || 569 561 smbc_getDebug(context) < 0 || 570 562 smbc_getDebug(context) > 100) { 571 563 572 564 errno = EINVAL; 573 565 return NULL; 574 575 } 576 566 567 } 568 577 569 if (!smbc_getUser(context)) { 578 570 /* 579 571 * FIXME: Is this the best way to get the user info? 580 572 */ 581 573 char *user = getenv("USER"); 582 574 /* walk around as "guest" if no username can be found */ 583 575 if (!user) { … … 595 587 SAFE_FREE(user); 596 588 597 589 if (!smbc_getUser(context)) { 598 590 errno = ENOMEM; 599 591 return NULL; 600 592 } 601 593 } 602 594 603 595 if (!smbc_getNetbiosName(context)) { 604 596 /* … … 629 621 return NULL; 630 622 } 631 623 632 624 smbc_setNetbiosName(context, netbios_name); 633 625 SAFE_FREE(netbios_name); … … 638 630 } 639 631 } 640 632 641 633 DEBUG(1, ("Using netbios name %s.\n", smbc_getNetbiosName(context))); 642 634 643 635 if (!smbc_getWorkgroup(context)) { 644 636 char *workgroup; … … 665 657 } 666 658 } 667 659 668 660 DEBUG(1, ("Using workgroup %s.\n", smbc_getWorkgroup(context))); 669 661 670 662 /* shortest timeout is 1 second */ 671 663 if (smbc_getTimeout(context) > 0 && smbc_getTimeout(context) < 1000) 672 664 smbc_setTimeout(context, 1000); 673 665 674 666 context->internal->initialized = True; 675 667 … … 685 677 smb_panic("error unlocking 'initialized_ctx_count'"); 686 678 } 687 679 688 680 return context; 689 681 }
Note:
See TracChangeset
for help on using the changeset viewer.