Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/libsmb/libsmb_context.c

    r414 r745  
    88   Copyright (C) Derrell Lipman 2003-2008
    99   Copyright (C) Jeremy Allison 2007, 2008
    10    
     10
    1111   This program is free software; you can redistribute it and/or modify
    1212   it under the terms of the GNU General Public License as published by
    1313   the Free Software Foundation; either version 3 of the License, or
    1414   (at your option) any later version.
    15    
     15
    1616   This program is distributed in the hope that it will be useful,
    1717   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1919   GNU General Public License for more details.
    20    
     20
    2121   You should have received a copy of the GNU General Public License
    2222   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2424
    2525#include "includes.h"
     26#include "libsmb/libsmb.h"
    2627#include "libsmbclient.h"
    2728#include "libsmb_internal.h"
     29#include "secrets.h"
    2830
    2931
     
    4446    char *home = NULL;
    4547    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);
    5052
    5153    /* Here we would open the smb.conf file if needed ... */
    52                
     54
    5355    lp_set_in_client(True);
    54                
     56
    5557    home = getenv("HOME");
    5658    if (home) {
     
    6668        }
    6769    }
    68                
     70
    6971    if (!conf_loaded) {
    7072        /*
     
    7476         * defaults ...
    7577         */
    76                        
     78
    7779        if (!lp_load(get_dyn_CONFIGFILE(), True, False, False, False)) {
    7880            DEBUG(5, ("Could not load config file: %s\n",
     
    98100        }
    99101    }
    100                
     102
    101103    load_interfaces();  /* Load the list of interfaces ... */
    102                
     104
    103105    reopen_logs();  /* Get logging working ... */
    104                
     106
    105107    /*
    106108     * Block SIGPIPE (from lib/util_sock.c: write())
     
    108110     */
    109111    BlockSignals(True, SIGPIPE);
    110                
     112
    111113    /* Create the mutex we'll use to protect initialized_ctx_count */
    112114    if (SMB_THREAD_CREATE_MUTEX("initialized_ctx_count_mutex",
     
    137139{
    138140        SMBCCTX *context;
    139        
     141
    140142        /* The first call to this function should initialize the module */
    141143        SMB_THREAD_ONCE(&SMBC_initialized, SMBC_module_init, NULL);
     
    150152                return NULL;
    151153        }
    152        
     154
    153155        ZERO_STRUCTP(context);
    154        
     156
    155157        context->internal = SMB_MALLOC_P(struct SMBC_internal_data);
    156158        if (!context->internal) {
     
    159161                return NULL;
    160162        }
    161        
     163
    162164        /* Initialize the context and establish reasonable defaults */
    163165        ZERO_STRUCTP(context->internal);
    164        
     166
    165167        smbc_setDebug(context, 0);
    166168        smbc_setTimeout(context, 20000);
    167        
     169
    168170        smbc_setOptionFullTimeNames(context, False);
    169171        smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE);
     
    177179                smbc_setOptionUseCCache(context, true);
    178180        }
    179        
     181
    180182        smbc_setFunctionAuthData(context, SMBC_get_auth_data);
    181183        smbc_setFunctionCheckServer(context, SMBC_check_server);
    182184        smbc_setFunctionRemoveUnusedServer(context, SMBC_remove_unused_server);
    183        
     185
    184186        smbc_setOptionUserData(context, NULL);
    185187        smbc_setFunctionAddCachedServer(context, SMBC_add_cached_server);
     
    187189        smbc_setFunctionRemoveCachedServer(context, SMBC_remove_cached_server);
    188190        smbc_setFunctionPurgeCachedServers(context, SMBC_purge_cached_servers);
    189        
     191
    190192        smbc_setFunctionOpen(context, SMBC_open_ctx);
    191193        smbc_setFunctionCreat(context, SMBC_creat_ctx);
     
    216218        smbc_setFunctionRemovexattr(context, SMBC_removexattr_ctx);
    217219        smbc_setFunctionListxattr(context, SMBC_listxattr_ctx);
    218        
     220
    219221        smbc_setFunctionOpenPrintJob(context, SMBC_open_print_job_ctx);
    220222        smbc_setFunctionPrintFile(context, SMBC_print_file_ctx);
    221223        smbc_setFunctionListPrintJobs(context, SMBC_list_print_jobs_ctx);
    222224        smbc_setFunctionUnlinkPrintJob(context, SMBC_unlink_print_job_ctx);
    223        
     225
    224226        return context;
    225227}
     
    240242                return 1;
    241243        }
    242        
     244
    243245        if (shutdown_ctx) {
    244246                SMBCFILE * f;
    245247                DEBUG(1,("Performing aggressive shutdown.\n"));
    246                
     248
    247249                f = context->internal->files;
    248250                while (f) {
     
    251253                }
    252254                context->internal->files = NULL;
    253                
     255
    254256                /* First try to remove the servers the nice way. */
    255257                if (smbc_getFunctionPurgeCachedServers(context)(context)) {
     
    294296                }
    295297        }
    296        
     298
    297299        /* Things we have to clean up */
    298300        smbc_setWorkgroup(context, NULL);
    299301        smbc_setNetbiosName(context, NULL);
    300302        smbc_setUser(context, NULL);
    301        
     303
    302304        DEBUG(3, ("Context %p successfully freed\n", context));
    303305
     
    325327                smb_panic("error unlocking 'initialized_ctx_count'");
    326328        }
    327        
     329
    328330        return 0;
    329331}
     
    347349                const char *s;
    348350        } option_value;
    349        
     351
    350352        va_start(ap, option_name);
    351        
     353
    352354        if (strcmp(option_name, "debug_to_stderr") == 0) {
    353355                option_value.b = (bool) va_arg(ap, int);
    354356                smbc_setOptionDebugToStderr(context, option_value.b);
    355                
     357
    356358        } else if (strcmp(option_name, "full_time_names") == 0) {
    357359                option_value.b = (bool) va_arg(ap, int);
    358360                smbc_setOptionFullTimeNames(context, option_value.b);
    359                
     361
    360362        } else if (strcmp(option_name, "open_share_mode") == 0) {
    361363                option_value.i = va_arg(ap, int);
    362364                smbc_setOptionOpenShareMode(context, option_value.i);
    363                
     365
    364366        } else if (strcmp(option_name, "auth_function") == 0) {
    365367                option_value.auth_fn =
    366368                        va_arg(ap, smbc_get_auth_data_with_context_fn);
    367369                smbc_setFunctionAuthDataWithContext(context, option_value.auth_fn);
    368                
     370
    369371        } else if (strcmp(option_name, "user_data") == 0) {
    370372                option_value.v = va_arg(ap, void *);
    371373                smbc_setOptionUserData(context, option_value.v);
    372                
     374
    373375        } else if (strcmp(option_name, "smb_encrypt_level") == 0) {
    374376                option_value.s = va_arg(ap, const char *);
     
    383385                                                         SMBC_ENCRYPTLEVEL_REQUIRE);
    384386                }
    385                
     387
    386388        } else if (strcmp(option_name, "browse_max_lmb_count") == 0) {
    387389                option_value.i = va_arg(ap, int);
    388390                smbc_setOptionBrowseMaxLmbCount(context, option_value.i);
    389                
     391
    390392        } else if (strcmp(option_name, "urlencode_readdir_entries") == 0) {
    391393                option_value.b = (bool) va_arg(ap, int);
    392394                smbc_setOptionUrlEncodeReaddirEntries(context, option_value.b);
    393                
     395
    394396        } else if (strcmp(option_name, "one_share_per_server") == 0) {
    395397                option_value.b = (bool) va_arg(ap, int);
    396398                smbc_setOptionOneSharePerServer(context, option_value.b);
    397                
     399
    398400        } else if (strcmp(option_name, "use_kerberos") == 0) {
    399401                option_value.b = (bool) va_arg(ap, int);
    400402                smbc_setOptionUseKerberos(context, option_value.b);
    401                
     403
    402404        } else if (strcmp(option_name, "fallback_after_kerberos") == 0) {
    403405                option_value.b = (bool) va_arg(ap, int);
    404406                smbc_setOptionFallbackAfterKerberos(context, option_value.b);
    405                
     407
    406408        } else if (strcmp(option_name, "use_ccache") == 0) {
    407409                option_value.b = (bool) va_arg(ap, int);
     
    412414                smbc_setOptionNoAutoAnonymousLogin(context, option_value.b);
    413415        }
    414        
     416
    415417        va_end(ap);
    416418}
     
    431433                return (void *) smbc_getOptionDebugToStderr(context);
    432434#endif
    433                
     435
    434436        } else if (strcmp(option_name, "full_time_names") == 0) {
    435437#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    438440                return (void *) smbc_getOptionFullTimeNames(context);
    439441#endif
    440                
     442
    441443        } else if (strcmp(option_name, "open_share_mode") == 0) {
    442444#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    445447                return (void *) smbc_getOptionOpenShareMode(context);
    446448#endif
    447                
     449
    448450        } else if (strcmp(option_name, "auth_function") == 0) {
    449451                return (void *) smbc_getFunctionAuthDataWithContext(context);
    450                
     452
    451453        } else if (strcmp(option_name, "user_data") == 0) {
    452454                return smbc_getOptionUserData(context);
    453                
     455
    454456        } else if (strcmp(option_name, "smb_encrypt_level") == 0) {
    455457                switch(smbc_getOptionSmbEncryptionLevel(context))
     
    462464                        return (void *) "require";
    463465                }
    464                
     466
    465467        } else if (strcmp(option_name, "smb_encrypt_on") == 0) {
    466468                SMBCSRV *s;
    467469                unsigned int num_servers = 0;
    468                
     470
    469471                for (s = context->internal->servers; s; s = s->next) {
    470472                        num_servers++;
     
    478480                return (void *) (bool) (num_servers > 0);
    479481#endif
    480                
     482
    481483        } else if (strcmp(option_name, "browse_max_lmb_count") == 0) {
    482484#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    485487                return (void *) smbc_getOptionBrowseMaxLmbCount(context);
    486488#endif
    487                
     489
    488490        } else if (strcmp(option_name, "urlencode_readdir_entries") == 0) {
    489491#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    492494                return (void *) (bool) smbc_getOptionUrlEncodeReaddirEntries(context);
    493495#endif
    494                
     496
    495497        } else if (strcmp(option_name, "one_share_per_server") == 0) {
    496498#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    499501                return (void *) (bool) smbc_getOptionOneSharePerServer(context);
    500502#endif
    501                
     503
    502504        } else if (strcmp(option_name, "use_kerberos") == 0) {
    503505#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    506508                return (void *) (bool) smbc_getOptionUseKerberos(context);
    507509#endif
    508                
     510
    509511        } else if (strcmp(option_name, "fallback_after_kerberos") == 0) {
    510512#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    513515                return (void *) (bool) smbc_getOptionFallbackAfterKerberos(context);
    514516#endif
    515                
     517
    516518        } else if (strcmp(option_name, "use_ccache") == 0) {
    517519#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
     
    528530#endif
    529531        }
    530        
     532
    531533        return NULL;
    532534}
     
    544546{
    545547        int pid;
    546        
     548
    547549        if (!context) {
    548550                errno = EBADF;
    549551                return NULL;
    550552        }
    551        
     553
    552554        /* Do not initialise the same client twice */
    553555        if (context->internal->initialized) {
    554556                return NULL;
    555557        }
    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
    567559        if ((!smbc_getFunctionAuthData(context) &&
    568560             !smbc_getFunctionAuthDataWithContext(context)) ||
    569561            smbc_getDebug(context) < 0 ||
    570562            smbc_getDebug(context) > 100) {
    571                
     563
    572564                errno = EINVAL;
    573565                return NULL;
    574                
    575         }
    576        
     566
     567        }
     568
    577569        if (!smbc_getUser(context)) {
    578570                /*
    579571                 * FIXME: Is this the best way to get the user info?
    580572                 */
    581                 char *user = getenv("USER");
     573                char *user = getenv("USER");
    582574                /* walk around as "guest" if no username can be found */
    583575                if (!user) {
     
    595587                SAFE_FREE(user);
    596588
    597                 if (!smbc_getUser(context)) {
     589                if (!smbc_getUser(context)) {
    598590                        errno = ENOMEM;
    599591                        return NULL;
    600592                }
    601593        }
    602        
     594
    603595        if (!smbc_getNetbiosName(context)) {
    604596                /*
     
    629621                        return NULL;
    630622                }
    631                
     623
    632624                smbc_setNetbiosName(context, netbios_name);
    633625                SAFE_FREE(netbios_name);
     
    638630                }
    639631        }
    640        
     632
    641633        DEBUG(1, ("Using netbios name %s.\n", smbc_getNetbiosName(context)));
    642        
     634
    643635        if (!smbc_getWorkgroup(context)) {
    644636                char *workgroup;
     
    665657                }
    666658        }
    667        
     659
    668660        DEBUG(1, ("Using workgroup %s.\n", smbc_getWorkgroup(context)));
    669        
     661
    670662        /* shortest timeout is 1 second */
    671663        if (smbc_getTimeout(context) > 0 && smbc_getTimeout(context) < 1000)
    672664                smbc_setTimeout(context, 1000);
    673        
     665
    674666        context->internal->initialized = True;
    675667
     
    685677                smb_panic("error unlocking 'initialized_ctx_count'");
    686678        }
    687        
     679
    688680        return context;
    689681}
Note: See TracChangeset for help on using the changeset viewer.