Пример #1
0
/**
 * Add an entry to the cache. If it does exist, then set it.
 * 
 * @param argv key, value and timeout are passed in command line
 * @return 0 on success, otherwise failure
 **/
static int net_cache_add(int argc, const char **argv)
{
	const char *keystr, *datastr, *timeout_str;
	time_t timeout;
	
	if (argc < 3) {
		d_printf("\nUsage: net cache add <key string> <data string> <timeout>\n");
		return -1;
	}
	
	keystr = argv[0];
	datastr = argv[1];
	timeout_str = argv[2];
	
	/* parse timeout given in command line */
	timeout = parse_timeout(timeout_str);
	if (!timeout) {
		d_fprintf(stderr, "Invalid timeout argument.\n");
		return -1;
	}
	
	if (gencache_set(keystr, datastr, timeout)) {
		d_printf("New cache entry stored successfully.\n");
		gencache_shutdown();
		return 0;
	}
	
	d_fprintf(stderr, "Entry couldn't be added. Perhaps there's already such a key.\n");
	gencache_shutdown();
	return -1;
}
Пример #2
0
/**
 * Set new value of an existing entry in the cache. Fail If the entry doesn't
 * exist.
 * 
 * @param argv key being searched and new value and timeout to set in the entry
 * @return 0 on success, otherwise failure
 **/
static int net_cache_set(int argc, const char **argv)
{
	const char *keystr, *datastr, *timeout_str;
	time_t timeout;
	
	if (argc < 3) {
		d_printf("\nUsage: net cache set <key string> <data string> <timeout>\n");
		return -1;
	}
	
	keystr = argv[0];
	datastr = argv[1];
	timeout_str = argv[2];
	
	/* parse timeout given in command line */
	timeout = parse_timeout(timeout_str);
	if (!timeout) {
		d_printf("Invalid timeout argument.\n");
		return -1;
	}
	
	if (gencache_set_only(keystr, datastr, timeout)) {
		d_printf("Cache entry set successfully.\n");
		gencache_shutdown();
		return 0;
	}

	d_printf("Entry couldn't be set. Perhaps there's no such a key.\n");
	gencache_shutdown();
	return -1;
}
Пример #3
0
/**
 * Flush the whole cache
 * 
 * @param argv ignored in this functionality
 * @return always returns 0
 **/
static int net_cache_flush(int argc, const char **argv)
{
	const char* pattern = "*";
	gencache_iterate(delete_cache_entry, NULL, pattern);
	gencache_shutdown();
	return 0;
}
Пример #4
0
/**
 * List the contents of the cache
 * 
 * @param argv ignored in this functionailty
 * @return always returns 0
 **/
static int net_cache_list(int argc, const char **argv)
{
	const char* pattern = "*";
	gencache_iterate(print_cache_entry, NULL, pattern);
	gencache_shutdown();
	return 0;
}
Пример #5
0
NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
{
	if (!ctx) {
		return NET_API_STATUS_SUCCESS;
	}

	libnetapi_samr_free(ctx);

	libnetapi_shutdown_cm(ctx);

	if (ctx->krb5_cc_env) {
		char *env = getenv(KRB5_ENV_CCNAME);
		if (env && (strequal(ctx->krb5_cc_env, env))) {
			unsetenv(KRB5_ENV_CCNAME);
		}
	}

	gfree_names();
	gfree_loadparm();
	gfree_case_tables();
	gfree_charcnv();
	gfree_interfaces();

	gencache_shutdown();
	secrets_shutdown();

	TALLOC_FREE(ctx);
	TALLOC_FREE(frame);

	gfree_debugsyms();

	return NET_API_STATUS_SUCCESS;
}
Пример #6
0
bool namecache_shutdown(void)
{
    if (!gencache_shutdown()) {
        DEBUG(2, ("namecache_shutdown: "
                  "Couldn't close namecache on top of gencache.\n"));
        return False;
    }

    DEBUG(5, ("namecache_shutdown: "
              "netbios namecache closed successfully.\n"));
    return True;
}
Пример #7
0
/**
 * Flush the whole cache
 *
 * @param c	A net_context structure
 * @param argv ignored in this functionality
 * @return always returns 0
 **/
static int net_cache_flush(struct net_context *c, int argc, const char **argv)
{
	const char* pattern = "*";
	if (c->display_usage) {
		d_printf("Usage:\n"
			 "net cache flush\n"
			 "    Delete all cache entries.\n");
		return 0;
	}
	gencache_iterate(delete_cache_entry, NULL, pattern);
	gencache_shutdown();
	return 0;
}
Пример #8
0
/*
 * Free a context
 *
 * Returns 0 on success. Otherwise returns 1, the SMBCCTX is _not_ freed
 * and thus you'll be leaking memory if not handled properly.
 *
 */
int
smbc_free_context(SMBCCTX *context,
                  int shutdown_ctx)
{
        if (!context) {
                errno = EBADF;
                return 1;
        }
        
        if (shutdown_ctx) {
                SMBCFILE * f;
                DEBUG(1,("Performing aggressive shutdown.\n"));
                
                f = context->internal->files;
                while (f) {
                        smbc_getFunctionClose(context)(context, f);
                        f = f->next;
                }
                context->internal->files = NULL;
                
                /* First try to remove the servers the nice way. */
                if (smbc_getFunctionPurgeCachedServers(context)(context)) {
                        SMBCSRV * s;
                        SMBCSRV * next;
                        DEBUG(1, ("Could not purge all servers, "
                                  "Nice way shutdown failed.\n"));
                        s = context->internal->servers;
                        while (s) {
                                DEBUG(1, ("Forced shutdown: %p (fd=%d)\n",
                                          s, s->cli->fd));
                                cli_shutdown(s->cli);
                                smbc_getFunctionRemoveCachedServer(context)(context,
                                                                         s);
                                next = s->next;
                                DLIST_REMOVE(context->internal->servers, s);
                                SAFE_FREE(s);
                                s = next;
                        }
                        context->internal->servers = NULL;
                }
        }
        else {
                /* This is the polite way */
                if (smbc_getFunctionPurgeCachedServers(context)(context)) {
                        DEBUG(1, ("Could not purge all servers, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
                if (context->internal->servers) {
                        DEBUG(1, ("Active servers in context, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
                if (context->internal->files) {
                        DEBUG(1, ("Active files in context, "
                                  "free_context failed.\n"));
                        errno = EBUSY;
                        return 1;
                }
        }
        
        /* Things we have to clean up */
        free(smbc_getWorkgroup(context));
        smbc_setWorkgroup(context, NULL);

        free(smbc_getNetbiosName(context));
        smbc_setNetbiosName(context, NULL);

        free(smbc_getUser(context));
        smbc_setUser(context, NULL);
        
        DEBUG(3, ("Context %p successfully freed\n", context));

	SAFE_FREE(context->internal);
        SAFE_FREE(context);

	if (initialized_ctx_count) {
		initialized_ctx_count--;
	}

	if (initialized_ctx_count == 0 && SMBC_initialized) {
		gencache_shutdown();
		secrets_shutdown();
		gfree_all();
		SMBC_initialized = false;
	}
        return 0;
}