関数 | |
SMBCCTX * | smbc_new_context (void) |
Create a new SBMCCTX (a context). | |
int | smbc_free_context (SMBCCTX *context, int shutdown_ctx) |
Delete a SBMCCTX (a context) acquired from smbc_new_context(). | |
void | smbc_option_set (SMBCCTX *context, char *option_name,...) |
Each time the context structure is changed, we have binary backward compatibility issues. | |
SMBCCTX * | smbc_init_context (SMBCCTX *context) |
Initialize a SBMCCTX (a context). | |
int | smbc_init (smbc_get_auth_data_fn fn, int debug) |
Initialize the samba client library. | |
SMBCCTX * | smbc_set_context (SMBCCTX *new_context) |
Set or retrieve the compatibility library's context pointer |
SMBCCTX* smbc_new_context | ( | void | ) |
Create a new SBMCCTX (a context).
Must be called before the context is passed to smbc_context_init()
libsmbclient.c の 6222 行で定義されています。
参照先 smbc_internal_data::_share_mode・_SMBCCTX::_smbc_options::browse_max_lmb_count・_SMBCCTX::callbacks・_SMBCCTX::_smbc_callbacks::check_server_fn・_SMBCCTX::chmod・_SMBCCTX::close_fn・_SMBCCTX::closedir・_SMBCCTX::creat・_SMBCCTX::debug・errno・_SMBCCTX::fstat・_SMBCCTX::fstatdir・_SMBCCTX::getdents・_SMBCCTX::getxattr・_SMBCCTX::internal・_SMBCCTX::list_print_jobs・_SMBCCTX::listxattr・_SMBCCTX::lseek・_SMBCCTX::lseekdir・_SMBCCTX::mkdir・_SMBCCTX::_smbc_options::one_share_per_server・_SMBCCTX::open・_SMBCCTX::open_print_job・_SMBCCTX::opendir・_SMBCCTX::options・_SMBCCTX::print_file・_SMBCCTX::read・_SMBCCTX::readdir・_SMBCCTX::_smbc_callbacks::remove_unused_server_fn・_SMBCCTX::removexattr・_SMBCCTX::rename・_SMBCCTX::rmdir・_SMBCCTX::setxattr・smbc_check_server()・smbc_chmod_ctx()・smbc_close_ctx()・smbc_closedir_ctx()・smbc_creat_ctx()・smbc_default_cache_functions()・smbc_fstat_ctx()・smbc_fstatdir_ctx()・smbc_getdents_ctx()・smbc_getxattr_ctx()・smbc_list_print_jobs_ctx()・smbc_listxattr_ctx()・smbc_lseek_ctx()・smbc_lseekdir_ctx()・smbc_mkdir_ctx()・smbc_open_ctx()・smbc_open_print_job_ctx()・smbc_opendir_ctx()・smbc_print_file_ctx()・smbc_read_ctx()・smbc_readdir_ctx()・smbc_remove_unused_server()・smbc_removexattr_ctx()・smbc_rename_ctx()・smbc_rmdir_ctx()・smbc_setxattr_ctx()・SMBC_SHAREMODE_DENY_NONE・smbc_stat_ctx()・smbc_telldir_ctx()・smbc_unlink_ctx()・smbc_unlink_print_job_ctx()・smbc_utimes_ctx()・smbc_write_ctx()・_SMBCCTX::stat・_SMBCCTX::telldir・_SMBCCTX::timeout・_SMBCCTX::unlink・_SMBCCTX::unlink_print_job・_SMBCCTX::_smbc_options::urlencode_readdir_entries・_SMBCCTX::utimes・_SMBCCTX::write.
参照元 cac_NewServerHandle()・smbc_init().
06223 { 06224 SMBCCTX *context; 06225 06226 context = SMB_MALLOC_P(SMBCCTX); 06227 if (!context) { 06228 errno = ENOMEM; 06229 return NULL; 06230 } 06231 06232 ZERO_STRUCTP(context); 06233 06234 context->internal = SMB_MALLOC_P(struct smbc_internal_data); 06235 if (!context->internal) { 06236 SAFE_FREE(context); 06237 errno = ENOMEM; 06238 return NULL; 06239 } 06240 06241 ZERO_STRUCTP(context->internal); 06242 06243 06244 /* ADD REASONABLE DEFAULTS */ 06245 context->debug = 0; 06246 context->timeout = 20000; /* 20 seconds */ 06247 06248 context->options.browse_max_lmb_count = 3; /* # LMBs to query */ 06249 context->options.urlencode_readdir_entries = False;/* backward compat */ 06250 context->options.one_share_per_server = False;/* backward compat */ 06251 context->internal->_share_mode = SMBC_SHAREMODE_DENY_NONE; 06252 /* backward compat */ 06253 06254 context->open = smbc_open_ctx; 06255 context->creat = smbc_creat_ctx; 06256 context->read = smbc_read_ctx; 06257 context->write = smbc_write_ctx; 06258 context->close_fn = smbc_close_ctx; 06259 context->unlink = smbc_unlink_ctx; 06260 context->rename = smbc_rename_ctx; 06261 context->lseek = smbc_lseek_ctx; 06262 context->stat = smbc_stat_ctx; 06263 context->fstat = smbc_fstat_ctx; 06264 context->opendir = smbc_opendir_ctx; 06265 context->closedir = smbc_closedir_ctx; 06266 context->readdir = smbc_readdir_ctx; 06267 context->getdents = smbc_getdents_ctx; 06268 context->mkdir = smbc_mkdir_ctx; 06269 context->rmdir = smbc_rmdir_ctx; 06270 context->telldir = smbc_telldir_ctx; 06271 context->lseekdir = smbc_lseekdir_ctx; 06272 context->fstatdir = smbc_fstatdir_ctx; 06273 context->chmod = smbc_chmod_ctx; 06274 context->utimes = smbc_utimes_ctx; 06275 context->setxattr = smbc_setxattr_ctx; 06276 context->getxattr = smbc_getxattr_ctx; 06277 context->removexattr = smbc_removexattr_ctx; 06278 context->listxattr = smbc_listxattr_ctx; 06279 context->open_print_job = smbc_open_print_job_ctx; 06280 context->print_file = smbc_print_file_ctx; 06281 context->list_print_jobs = smbc_list_print_jobs_ctx; 06282 context->unlink_print_job = smbc_unlink_print_job_ctx; 06283 06284 context->callbacks.check_server_fn = smbc_check_server; 06285 context->callbacks.remove_unused_server_fn = smbc_remove_unused_server; 06286 06287 smbc_default_cache_functions(context); 06288 06289 return context; 06290 }
int smbc_free_context | ( | SMBCCTX * | context, | |
int | shutdown_ctx | |||
) |
Delete a SBMCCTX (a context) acquired from smbc_new_context().
The context will be deleted if possible.
context | A pointer to a SMBCCTX obtained from smbc_new_context() | |
shutdown_ctx | If 1, all connections and files will be closed even if they are busy. |
libsmbclient.c の 6300 行で定義されています。
参照先 smbc_internal_data::_files・smbc_internal_data::_servers・_SMBCCTX::callbacks・cli_shutdown()・_SMBCCTX::close_fn・errno・_SMBCCTX::internal・_SMBCCTX::netbios_name・_SMBCFILE::next・_SMBCSRV::next・_SMBCCTX::_smbc_callbacks::purge_cached_fn・_SMBCCTX::_smbc_callbacks::remove_cached_srv_fn・_SMBCCTX::user・_SMBCCTX::workgroup.
参照元 cac_FreeHandle()・smbc_init().
06302 { 06303 if (!context) { 06304 errno = EBADF; 06305 return 1; 06306 } 06307 06308 if (shutdown_ctx) { 06309 SMBCFILE * f; 06310 DEBUG(1,("Performing aggressive shutdown.\n")); 06311 06312 f = context->internal->_files; 06313 while (f) { 06314 (context->close_fn)(context, f); 06315 f = f->next; 06316 } 06317 context->internal->_files = NULL; 06318 06319 /* First try to remove the servers the nice way. */ 06320 if (context->callbacks.purge_cached_fn(context)) { 06321 SMBCSRV * s; 06322 SMBCSRV * next; 06323 DEBUG(1, ("Could not purge all servers, " 06324 "Nice way shutdown failed.\n")); 06325 s = context->internal->_servers; 06326 while (s) { 06327 DEBUG(1, ("Forced shutdown: %p (fd=%d)\n", 06328 s, s->cli->fd)); 06329 cli_shutdown(s->cli); 06330 (context->callbacks.remove_cached_srv_fn)(context, 06331 s); 06332 next = s->next; 06333 DLIST_REMOVE(context->internal->_servers, s); 06334 SAFE_FREE(s); 06335 s = next; 06336 } 06337 context->internal->_servers = NULL; 06338 } 06339 } 06340 else { 06341 /* This is the polite way */ 06342 if ((context->callbacks.purge_cached_fn)(context)) { 06343 DEBUG(1, ("Could not purge all servers, " 06344 "free_context failed.\n")); 06345 errno = EBUSY; 06346 return 1; 06347 } 06348 if (context->internal->_servers) { 06349 DEBUG(1, ("Active servers in context, " 06350 "free_context failed.\n")); 06351 errno = EBUSY; 06352 return 1; 06353 } 06354 if (context->internal->_files) { 06355 DEBUG(1, ("Active files in context, " 06356 "free_context failed.\n")); 06357 errno = EBUSY; 06358 return 1; 06359 } 06360 } 06361 06362 /* Things we have to clean up */ 06363 SAFE_FREE(context->workgroup); 06364 SAFE_FREE(context->netbios_name); 06365 SAFE_FREE(context->user); 06366 06367 DEBUG(3, ("Context %p successfully freed\n", context)); 06368 SAFE_FREE(context->internal); 06369 SAFE_FREE(context); 06370 return 0; 06371 }
void smbc_option_set | ( | SMBCCTX * | context, | |
char * | option_name, | |||
... | ||||
) |
Each time the context structure is changed, we have binary backward compatibility issues.
Instead of modifying the public portions of the context structure to add new options, instead, we put them in the internal portion of the context structure and provide a set function for these new options.
context | A pointer to a SMBCCTX obtained from smbc_new_context() | |
option_name | The name of the option for which the value is to be set | |
option_value | The new value of the option being set |
libsmbclient.c の 6382 行で定義されています。
参照先 smbc_internal_data::_auth_fn_with_context・smbc_internal_data::_debug_stderr・smbc_internal_data::_full_time_names・smbc_internal_data::_share_mode・smbc_internal_data::_user_data・auth_fn()・_SMBCCTX::internal.
06385 { 06386 va_list ap; 06387 union { 06388 int i; 06389 BOOL b; 06390 smbc_get_auth_data_with_context_fn auth_fn; 06391 void *v; 06392 } option_value; 06393 06394 va_start(ap, option_name); 06395 06396 if (strcmp(option_name, "debug_to_stderr") == 0) { 06397 /* 06398 * Log to standard error instead of standard output. 06399 */ 06400 option_value.b = (BOOL) va_arg(ap, int); 06401 context->internal->_debug_stderr = option_value.b; 06402 06403 } else if (strcmp(option_name, "full_time_names") == 0) { 06404 /* 06405 * Use new-style time attribute names, e.g. WRITE_TIME rather 06406 * than the old-style names such as M_TIME. This allows also 06407 * setting/getting CREATE_TIME which was previously 06408 * unimplemented. (Note that the old C_TIME was supposed to 06409 * be CHANGE_TIME but was confused and sometimes referred to 06410 * CREATE_TIME.) 06411 */ 06412 option_value.b = (BOOL) va_arg(ap, int); 06413 context->internal->_full_time_names = option_value.b; 06414 06415 } else if (strcmp(option_name, "open_share_mode") == 0) { 06416 /* 06417 * The share mode to use for files opened with 06418 * smbc_open_ctx(). The default is SMBC_SHAREMODE_DENY_NONE. 06419 */ 06420 option_value.i = va_arg(ap, int); 06421 context->internal->_share_mode = 06422 (smbc_share_mode) option_value.i; 06423 06424 } else if (strcmp(option_name, "auth_function") == 0) { 06425 /* 06426 * Use the new-style authentication function which includes 06427 * the context. 06428 */ 06429 option_value.auth_fn = 06430 va_arg(ap, smbc_get_auth_data_with_context_fn); 06431 context->internal->_auth_fn_with_context = 06432 option_value.auth_fn; 06433 } else if (strcmp(option_name, "user_data") == 0) { 06434 /* 06435 * Save a user data handle which may be retrieved by the user 06436 * with smbc_option_get() 06437 */ 06438 option_value.v = va_arg(ap, void *); 06439 context->internal->_user_data = option_value.v; 06440 } 06441 06442 va_end(ap); 06443 }
Initialize a SBMCCTX (a context).
Must be called before using any SMBCCTX API function
context | A pointer to a SMBCCTX obtained from smbc_new_context() |
libsmbclient.c の 6503 行で定義されています。
参照先 smbc_internal_data::_auth_fn_with_context・smbc_internal_data::_debug_stderr・smbc_internal_data::_initialized・_SMBCCTX::_smbc_callbacks::auth_fn・BlockSignals()・_SMBCCTX::callbacks・dbf・_SMBCCTX::debug・DEBUGLEVEL・dyn_CONFIGFILE・errno・global_myname・in_client・_SMBCCTX::internal・load_case_tables()・load_interfaces()・lp_workgroup()・_SMBCCTX::netbios_name・reopen_logs()・setup_logging()・smbc_initialized・sys_getpid()・_SMBCCTX::timeout・_SMBCCTX::user・_SMBCCTX::workgroup・x_setbuf()・x_stderr.
参照元 cac_Connect()・smbc_init().
06504 { 06505 pstring conf; 06506 int pid; 06507 char *user = NULL; 06508 char *home = NULL; 06509 06510 if (!context || !context->internal) { 06511 errno = EBADF; 06512 return NULL; 06513 } 06514 06515 /* Do not initialise the same client twice */ 06516 if (context->internal->_initialized) { 06517 return 0; 06518 } 06519 06520 if ((!context->callbacks.auth_fn && 06521 !context->internal->_auth_fn_with_context) || 06522 context->debug < 0 || 06523 context->debug > 100) { 06524 06525 errno = EINVAL; 06526 return NULL; 06527 06528 } 06529 06530 if (!smbc_initialized) { 06531 /* 06532 * Do some library-wide intializations the first time we get 06533 * called 06534 */ 06535 BOOL conf_loaded = False; 06536 06537 /* Set this to what the user wants */ 06538 DEBUGLEVEL = context->debug; 06539 06540 load_case_tables(); 06541 06542 setup_logging("libsmbclient", True); 06543 if (context->internal->_debug_stderr) { 06544 dbf = x_stderr; 06545 x_setbuf(x_stderr, NULL); 06546 } 06547 06548 /* Here we would open the smb.conf file if needed ... */ 06549 06550 in_client = True; /* FIXME, make a param */ 06551 06552 home = getenv("HOME"); 06553 if (home) { 06554 slprintf(conf, sizeof(conf), "%s/.smb/smb.conf", home); 06555 if (lp_load(conf, True, False, False, True)) { 06556 conf_loaded = True; 06557 } else { 06558 DEBUG(5, ("Could not load config file: %s\n", 06559 conf)); 06560 } 06561 } 06562 06563 if (!conf_loaded) { 06564 /* 06565 * Well, if that failed, try the dyn_CONFIGFILE 06566 * Which points to the standard locn, and if that 06567 * fails, silently ignore it and use the internal 06568 * defaults ... 06569 */ 06570 06571 if (!lp_load(dyn_CONFIGFILE, True, False, False, False)) { 06572 DEBUG(5, ("Could not load config file: %s\n", 06573 dyn_CONFIGFILE)); 06574 } else if (home) { 06575 /* 06576 * We loaded the global config file. Now lets 06577 * load user-specific modifications to the 06578 * global config. 06579 */ 06580 slprintf(conf, sizeof(conf), 06581 "%s/.smb/smb.conf.append", home); 06582 if (!lp_load(conf, True, False, False, False)) { 06583 DEBUG(10, 06584 ("Could not append config file: " 06585 "%s\n", 06586 conf)); 06587 } 06588 } 06589 } 06590 06591 load_interfaces(); /* Load the list of interfaces ... */ 06592 06593 reopen_logs(); /* Get logging working ... */ 06594 06595 /* 06596 * Block SIGPIPE (from lib/util_sock.c: write()) 06597 * It is not needed and should not stop execution 06598 */ 06599 BlockSignals(True, SIGPIPE); 06600 06601 /* Done with one-time initialisation */ 06602 smbc_initialized = 1; 06603 06604 } 06605 06606 if (!context->user) { 06607 /* 06608 * FIXME: Is this the best way to get the user info? 06609 */ 06610 user = getenv("USER"); 06611 /* walk around as "guest" if no username can be found */ 06612 if (!user) context->user = SMB_STRDUP("guest"); 06613 else context->user = SMB_STRDUP(user); 06614 } 06615 06616 if (!context->netbios_name) { 06617 /* 06618 * We try to get our netbios name from the config. If that 06619 * fails we fall back on constructing our netbios name from 06620 * our hostname etc 06621 */ 06622 if (global_myname()) { 06623 context->netbios_name = SMB_STRDUP(global_myname()); 06624 } 06625 else { 06626 /* 06627 * Hmmm, I want to get hostname as well, but I am too 06628 * lazy for the moment 06629 */ 06630 pid = sys_getpid(); 06631 context->netbios_name = (char *)SMB_MALLOC(17); 06632 if (!context->netbios_name) { 06633 errno = ENOMEM; 06634 return NULL; 06635 } 06636 slprintf(context->netbios_name, 16, 06637 "smbc%s%d", context->user, pid); 06638 } 06639 } 06640 06641 DEBUG(1, ("Using netbios name %s.\n", context->netbios_name)); 06642 06643 if (!context->workgroup) { 06644 if (lp_workgroup()) { 06645 context->workgroup = SMB_STRDUP(lp_workgroup()); 06646 } 06647 else { 06648 /* TODO: Think about a decent default workgroup */ 06649 context->workgroup = SMB_STRDUP("samba"); 06650 } 06651 } 06652 06653 DEBUG(1, ("Using workgroup %s.\n", context->workgroup)); 06654 06655 /* shortest timeout is 1 second */ 06656 if (context->timeout > 0 && context->timeout < 1000) 06657 context->timeout = 1000; 06658 06659 /* 06660 * FIXME: Should we check the function pointers here? 06661 */ 06662 06663 context->internal->_initialized = True; 06664 06665 return context; 06666 }
int smbc_init | ( | smbc_get_auth_data_fn | fn, | |
int | debug | |||
) |
Initialize the samba client library.
Must be called before using any of the smbclient API function
fn | The function that will be called to obtaion authentication credentials. | |
debug | Allows caller to set the debug level. Can be changed in smb.conf file. Allows caller to set debugging if no smb.conf. |
libsmb_compat.c の 116 行で定義されています。
参照先 _SMBCCTX::_smbc_callbacks::auth_fn・_SMBCCTX::callbacks・_SMBCCTX::debug・smbc_compat_initialized・smbc_free_context()・smbc_init_context()・smbc_new_context()・statcont.
00117 { 00118 if (!smbc_compat_initialized) { 00119 statcont = smbc_new_context(); 00120 if (!statcont) 00121 return -1; 00122 00123 statcont->debug = debug; 00124 statcont->callbacks.auth_fn = fn; 00125 00126 if (!smbc_init_context(statcont)) { 00127 smbc_free_context(statcont, False); 00128 return -1; 00129 } 00130 00131 smbc_compat_initialized = 1; 00132 00133 return 0; 00134 } 00135 return 0; 00136 }
Set or retrieve the compatibility library's context pointer
context | New context to use, or NULL. If a new context is provided, it must have allocated with smbc_new_context() and initialized with smbc_init_context(), followed, optionally, by some manual changes to some of the non-internal fields. |
libsmb_compat.c の 139 行で定義されています。
参照先 smbc_compat_initialized・statcont.
00140 { 00141 SMBCCTX *old_context = statcont; 00142 00143 if (context) { 00144 /* Save provided context. It must have been initialized! */ 00145 statcont = context; 00146 00147 /* You'd better know what you're doing. We won't help you. */ 00148 smbc_compat_initialized = 1; 00149 } 00150 00151 return old_context; 00152 }