-/*
- *Remove a server from the list smbc_srvs if it's unused -- Tom (tom@ninja.nl)
- *
- * We accept a *srv
- */
-BOOL smbc_remove_unused_server(struct smbc_server * s)
-{
- int p;
-
- /* are we being fooled ? */
- if (!s) return False;
-
- /* close all open files/directories on this server */
- for (p = 0; p < SMBC_MAX_FD; p++) {
- if (smbc_file_table[p] &&
- smbc_file_table[p]->srv == s) {
- /* Still used .. DARN */
- DEBUG(3, ("smbc_remove_usused_server: %x still used by %s (%d).\n", (int) s,
- smbc_file_table[p]->fname, smbc_file_table[p]->smbc_fd));
- return False;
- }
- }
-
- cli_shutdown(&s->cli);
-
- SAFE_FREE(s->username);
- SAFE_FREE(s->workgroup);
- SAFE_FREE(s->server_name);
- SAFE_FREE(s->share_name);
- DLIST_REMOVE(smbc_srvs, s);
- DEBUG(3, ("smbc_remove_usused_server: %x removed.\n", (int) s));
- SAFE_FREE(s);
- return True;
-}
-
-/*
- *Initialise the library etc
- *
- * We accept valid values for debug from 0 to 100,
- * and insist that fn must be non-null.
- */
-
-int smbc_init(smbc_get_auth_data_fn fn, int debug)
-{
- pstring conf;
- int p, pid;
- char *user = NULL, *home = NULL, *pname="libsmbclient";
-
- if (!fn || debug < 0 || debug > 100) {
-
- errno = EINVAL;
- return -1;
-
- }
-
- if (smbc_initialized) { /* Don't go through this if we have already done it */
-
- return 0;
-
- }
-
- smbc_initialized = 1;
- smbc_auth_fn = fn;
- /* smbc_debug = debug; */
-
- DEBUGLEVEL = -1;
-
- setup_logging(pname, False);
-
- /* Here we would open the smb.conf file if needed ... */
-
- home = getenv("HOME");
-
- slprintf(conf, sizeof(conf), "%s/.smb/smb.conf", home);
-
- load_interfaces(); /* Load the list of interfaces ... */
-
- in_client = True; /* FIXME, make a param */
-
- if (!lp_load(conf, True, False, False)) {
-
- /*
- * Hmmm, what the hell do we do here ... we could not parse the
- * config file ... We must return an error ... and keep info around
- * about why we failed
- */
-
- errno = ENOENT; /* FIXME: Figure out the correct error response */
- return -1;
-
- }
-
- reopen_logs(); /* Get logging working ... */
-
- /*
- * FIXME: Is this the best way to get the user info?
- */
-
- user = getenv("USER");
- /* walk around as "guest" if no username can be found */
- if (!user) user = strdup("guest");
- pstrcpy(smbc_user, user); /* Save for use elsewhere */
-
- /*
- * We try to get our netbios name from the config. If that fails we fall
- * back on constructing our netbios name from our hostname etc
- */
- if (global_myname) {
- pstrcpy(my_netbios_name, global_myname);
- }
- else {
- /*
- * Hmmm, I want to get hostname as well, but I am too lazy for the moment
- */
- pid = sys_getpid();
- slprintf(my_netbios_name, 16, "smbc%s%d", user, pid);
- }
- DEBUG(0,("Using netbios name %s.\n", my_netbios_name));
-
- /*
- * Now initialize the file descriptor array and figure out what the
- * max open files is, so we can return FD's that are above the max
- * open file, and separated by a guard band
- */
-
-#if (defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE))
- do {
- struct rlimit rlp;
-
- if (getrlimit(RLIMIT_NOFILE, &rlp)) {
-
- DEBUG(0, ("smbc_init: getrlimit(1) for RLIMIT_NOFILE failed with error %s\n", strerror(errno)));
-
- smbc_start_fd = 1000000;
-
- }
- else {
-
- smbc_start_fd = rlp.rlim_max + 10000; /* Leave a guard space of 10,000 */
-
- }
- } while ( 0 );
-#else /* !defined(HAVE_GETRLIMIT) || !defined(RLIMIT_NOFILE) */
-
- smbc_start_fd = 1000000;
-
-#endif
-
- smbc_file_table = malloc(SMBC_MAX_FD * sizeof(struct smbc_file *));
-
- for (p = 0; p < SMBC_MAX_FD; p++)
- smbc_file_table[p] = NULL;
-
- if (!smbc_file_table)
- return ENOMEM;
-
- return 0; /* Success */
-
-}
-