当前位置: 首页>>代码示例>>C++>>正文


C++ safe_getenv函数代码示例

本文整理汇总了C++中safe_getenv函数的典型用法代码示例。如果您正苦于以下问题:C++ safe_getenv函数的具体用法?C++ safe_getenv怎么用?C++ safe_getenv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了safe_getenv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_server_client_disconnect

static void
on_server_client_disconnect(int is_tun)
{
	FILE *fp1, *fp2;
	char ifname[16], addr_l[64], addr_r[64], peer_name[64];
	char *clients_l1 = VPN_SERVER_LEASE_FILE;
	char *clients_l2 = "/tmp/.vpns.leases";
	char *common_name = safe_getenv("common_name");
	char *peer_addr_r = safe_getenv("trusted_ip");
	char *peer_addr_l = safe_getenv("ifconfig_pool_remote_ip");
	uint64_t llsent = strtoll(safe_getenv("bytes_sent"), NULL, 10);
	uint64_t llrecv = strtoll(safe_getenv("bytes_received"), NULL, 10);

	logmessage(SERVER_LOG_NAME, "peer %s (%s) disconnected, sent: %llu KB, received: %llu KB",
		peer_addr_r, common_name, llsent / 1024, llrecv / 1024);

	fp1 = fopen(clients_l1, "r");
	fp2 = fopen(clients_l2, "w");
	if (fp1) {
		while(fscanf(fp1, "%s %s %s %[^\n]\n", ifname, addr_l, addr_r, peer_name) == 4) {
			if (strcmp(peer_addr_r, addr_r) != 0 || strcmp(peer_addr_l, addr_l) != 0) {
				if (fp2)
					fprintf(fp2, "%s %s %s %s\n", ifname, addr_l, addr_r, peer_name);
			}
		}
		
		fclose(fp1);
	}

	if (fp2) {
		fclose(fp2);
		rename(clients_l2, clients_l1);
		unlink(clients_l2);
	}
}
开发者ID:PterX,项目名称:rt-n56u,代码行数:35,代码来源:vpn_openvpn.c

示例2: on_server_client_connect

static void
on_server_client_connect(int is_tun)
{
    FILE *fp;
    char *common_name = safe_getenv("common_name");
    char *peer_addr_r = safe_getenv("trusted_ip");
    char *peer_addr_l = safe_getenv("ifconfig_pool_remote_ip");
    char *dev_ifname = safe_getenv("dev");
    const char *script_name = VPN_SERVER_UPDOWN_SCRIPT;

#if defined (USE_IPV6)
    if (!is_valid_ipv4(peer_addr_r))
        peer_addr_r = safe_getenv("trusted_ip6");
#endif

    if (strlen(dev_ifname) == 0)
        dev_ifname = (is_tun) ? IFNAME_SERVER_TUN : IFNAME_SERVER_TAP;

    logmessage(SERVER_LOG_NAME, "peer %s (%s) connected - local IP: %s",
               peer_addr_r, common_name, peer_addr_l);

    fp = fopen(VPN_SERVER_LEASE_FILE, "a+");
    if (fp) {
        fprintf(fp, "%s %s %s %s\n", "-", peer_addr_l, peer_addr_r, common_name);
        fclose(fp);
    }

    if (check_if_file_exist(script_name))
        doSystem("%s %s %s %s %s %s", script_name, "up", dev_ifname, peer_addr_l, peer_addr_r, common_name);
}
开发者ID:andy-padavan,项目名称:rt-n56u,代码行数:30,代码来源:vpn_openvpn.c

示例3: get_peer_verify_level

static int get_peer_verify_level(const struct tls_info *info)
{
	int peer_verify_level=SSL_VERIFY_PEER;
		/* SSL_VERIFY_NONE */
		/* SSL_VERIFY_PEER */
		/* SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT */
	const char *s=safe_getenv(info, "TLS_VERIFYPEER");

	if (info->peer_verify_domain)
		return SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT;

	switch (*s)	{
	case 'n':
	case 'N':		/* NONE */
		peer_verify_level=SSL_VERIFY_NONE;
		break;
	case 'p':
	case 'P':		/* PEER */
		peer_verify_level=SSL_VERIFY_PEER;
		break;
	case 'r':
	case 'R':		/* REQUIREPEER */
		peer_verify_level=
			SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
		break;
	}
	return (peer_verify_level);
}
开发者ID:MhdAlyan,项目名称:courier,代码行数:28,代码来源:libcouriertls.c

示例4: init_debug

static void init_debug(void)
{
	char	*dstr, *fn, *tmp;
	int	fd, flags;

	if (debug_mask & DEBUG_INIT)
		return;

	dstr = getenv("COMERR_DEBUG");
	if (dstr) {
		debug_mask = strtoul(dstr, &tmp, 0);
		if (*tmp || errno)
			debug_mask = 0;
	}

	debug_mask |= DEBUG_INIT;
	if (debug_mask == DEBUG_INIT)
		return;

	fn = safe_getenv("COMERR_DEBUG_FILE");
	if (fn)
		debug_f = fopen(fn, "a");
	if (!debug_f)
		debug_f = fopen("/dev/tty", "a");
	if (debug_f) {
		fd = fileno(debug_f);
		if (fd >= 0) {
			flags = fcntl(fd, F_GETFD);
			if (flags >= 0)
				fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
		}
	} else
		debug_mask = DEBUG_INIT;

}
开发者ID:Polyconseil,项目名称:e2fsprogs,代码行数:35,代码来源:error_message.c

示例5: mail_conf_suck

void    mail_conf_suck(void)
{
    char   *config_dir;
    char   *path;

    /*
     * Permit references to unknown configuration variable names. We rely on
     * a separate configuration checking tool to spot misspelled names and
     * other kinds of trouble. Enter the configuration directory into the
     * default dictionary.
     */
    if (var_config_dir)
	myfree(var_config_dir);
    if ((config_dir = getenv(CONF_ENV_PATH)) == 0)
	config_dir = DEF_CONFIG_DIR;
    var_config_dir = mystrdup(config_dir);
    set_mail_conf_str(VAR_CONFIG_DIR, var_config_dir);

    /*
     * If the configuration directory name comes from a different trust
     * domain, require that it is listed in the default main.cf file.
     */
    if (strcmp(var_config_dir, DEF_CONFIG_DIR) != 0	/* non-default */
	&& safe_getenv(CONF_ENV_PATH) == 0	/* non-default */
	&& geteuid() != 0)			/* untrusted */
	mail_conf_checkdir(var_config_dir);
    path = concatenate(var_config_dir, "/", "main.cf", (char *) 0);
    if (dict_load_file_xt(CONFIG_DICT, path) == 0)
	msg_fatal("open %s: %m", path);
    myfree(path);
}
开发者ID:teonsystems,项目名称:postfix,代码行数:31,代码来源:mail_conf.c

示例6: on_server_client_connect

static void
on_server_client_connect(int is_tun)
{
	FILE *fp;
	char *common_name = safe_getenv("common_name");
	char *peer_addr_r = safe_getenv("trusted_ip");
	char *peer_addr_l = safe_getenv("ifconfig_pool_remote_ip");

	logmessage(SERVER_LOG_NAME, "peer %s (%s) connected - local IP: %s",
		peer_addr_r, common_name, peer_addr_l);

	fp = fopen(VPN_SERVER_LEASE_FILE, "a+");
	if (fp) {
		fprintf(fp, "%s %s %s %s\n", "-", peer_addr_l, peer_addr_r, common_name);
		fclose(fp);
	}
}
开发者ID:PterX,项目名称:rt-n56u,代码行数:17,代码来源:vpn_openvpn.c

示例7: assert

/*
 * Search for @name kernel command parametr.
 *
 * Returns newly allocated string with parameter argument if the @name is
 * specified as "name=" or returns pointer to @name or returns NULL if not
 * found.
 *
 * For example cmdline: "aaa bbb=BBB ccc"
 *
 *	@name is "aaa"	--returns--> "aaa" (pointer to @name)
 *	@name is "bbb=" --returns--> "BBB" (allocated)
 *	@name is "foo"  --returns--> NULL
 */
char *mnt_get_kernel_cmdline_option(const char *name)
{
	FILE *f;
	size_t len;
	int val = 0;
	char *p, *res = NULL;
	char buf[BUFSIZ];	/* see kernel include/asm-generic/setup.h: COMMAND_LINE_SIZE */
	const char *path = _PATH_PROC_CMDLINE;

	assert(name);
	assert(*name);

#ifdef TEST_PROGRAM
	path = safe_getenv("LIBMOUNT_KERNEL_CMDLINE");
	if (!path)
		path = _PATH_PROC_CMDLINE;
#endif
	f = fopen(path, "r");
	if (!f)
		return NULL;

	p = fgets(buf, sizeof(buf), f);
	fclose(f);

	if (!p || !*p || *p == '\n')
		return NULL;

	len = strlen(buf);
	*(buf + len - 1) = '\0';	/* remove last '\n' */

	len = strlen(name);
	if (len && *(name + len - 1) == '=')
		val = 1;

	while (p && *p) {
		if (p != buf)
			p++;
		if (!(p = strstr(p, name)))
			break;			/* not found the option */
		if (p != buf && !isblank(*(p - 1)))
			continue;		/* no space before the option */
		if (!val && *(p + len) != '\0' && !isblank(*(p + len)))
			continue;		/* no space behind the option */
		if (val) {
			char *v = p + len;

			while (*p && !isblank(*p))	/* jump to the end of the argument */
				p++;
			*p = '\0';
			res = strdup(v);
			break;
		} else
			res = (char *) name;	/* option without '=' */
		break;
	}

	return res;
}
开发者ID:yaccz,项目名称:util-linux,代码行数:71,代码来源:utils.c

示例8: set_config_dir

void set_config_dir(void)
{
    char   *config_dir;

    if (var_config_dir)
        myfree(var_config_dir);
    var_config_dir = mystrdup((config_dir = safe_getenv(CONF_ENV_PATH)) != 0 ?
                              config_dir : DEF_CONFIG_DIR);     /* XXX */
    set_mail_conf_str(VAR_CONFIG_DIR, var_config_dir);
}
开发者ID:Gelma,项目名称:Postfix,代码行数:10,代码来源:postconf_misc.c

示例9: ipdown_vpns_main

int
ipdown_vpns_main(int argc, char **argv)
{
	FILE *fp1, *fp2;
	int i_clients;
	char ifname[16], addr_l[64], addr_r[64], name_p[64];
	char *peer_name;
	char *clients_l1 = VPN_SERVER_LEASE_FILE;
	char *clients_l2 = "/tmp/.vpns.leases";
	char *script_name = VPN_SERVER_UPDOWN_SCRIPT;
	char *svcs[] = { "bcrelay", NULL };

	if (argc < 7)
		return -1;

	peer_name = safe_getenv("PEERNAME");

	logmessage(VPNS_LOG_NAME, "peer %s (%s) disconnected", argv[6], peer_name);

	umask(0000);

	vpns_firewall_permission(argv[1], 0);
	vpns_route_to_remote_lan(peer_name, argv[1], NULL, 0);

	i_clients = 0;
	fp1 = fopen(clients_l1, "r");
	fp2 = fopen(clients_l2, "w");
	if (fp1) {
		while(fscanf(fp1, "%15s %63s %63s %63[^\n]\n", ifname, addr_l, addr_r, name_p) == 4) {
			if (strcmp(ifname, argv[1])) {
				i_clients++;
				if (fp2)
					fprintf(fp2, "%s %s %s %s\n", ifname, addr_l, addr_r, name_p);
			}
		}
		
		fclose(fp1);
	}

	if (fp2) {
		fclose(fp2);
		rename(clients_l2, clients_l1);
		unlink(clients_l2);
	}

	if (check_if_file_exist(script_name))
		doSystem("%s %s %s %s %s %s", script_name, "down", argv[1], argv[5], argv[6], peer_name);

	if (i_clients == 0 && pids(svcs[0]))
		kill_services(svcs, 3, 1);

	return 0;
}
开发者ID:jing-git,项目名称:rt-n56u,代码行数:53,代码来源:vpn_server.c

示例10: call_client_script

static void
call_client_script(const char *script_name, const char *arg)
{
    int i;
    const char *env;

    if (!check_if_file_exist(script_name))
        return;

    for (i = 0; i < ARRAY_SIZE(env_ovpn); i++) {
        env = env_ovpn[i];
        if (strlen(safe_getenv(env)) < 1 && env_ovpn_alt[i])
            env = env_ovpn_alt[i];
        setenv(env_pppd[i], safe_getenv(env), 1);
    }

    doSystem("%s %s", script_name, arg);

    for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
        unsetenv(env_pppd[i]);
}
开发者ID:andy-padavan,项目名称:rt-n56u,代码行数:21,代码来源:vpn_openvpn.c

示例11: safe_getenv

/*
 * Don't export this to libmount API -- utab is private library stuff.
 *
 * Returns: path to /run/mount/utab (or /dev/.mount/utab) or $LIBMOUNT_UTAB.
 */
const char *mnt_get_utab_path(void)
{
	struct stat st;
	const char *p = safe_getenv("LIBMOUNT_UTAB");

	if (p)
		return p;

	if (stat(MNT_RUNTIME_TOPDIR, &st) == 0)
		return MNT_PATH_UTAB;

	return MNT_PATH_UTAB_OLD;
}
开发者ID:yaccz,项目名称:util-linux,代码行数:18,代码来源:utils.c

示例12: DftEnv

static const char *
DftEnv(const char *name, const char *dft)
{
    const char *result;

#if OPT_EVAL && OPT_SHELL
    name = safe_getenv(name);
    result = isEmpty(name) ? dft : name;
#else
    result = dft;
#endif
    return result;
}
开发者ID:ricksladkey,项目名称:vile,代码行数:13,代码来源:statevar.c

示例13: deconfig_lan

/*
 * deconfig: This argument is used when udhcpc starts, and when a
 * leases is lost. The script should put the interface in an up, but
 * deconfigured state.
*/
static int
deconfig_lan(void)
{
	char *lan_ifname = safe_getenv("interface");

	ifconfig(lan_ifname, IFUP, "0.0.0.0", NULL);
	expires_lan(lan_ifname, 0);

	lan_down(lan_ifname);

	dprintf("done\n");
	return 0;
}
开发者ID:hajuuk,项目名称:R7000,代码行数:18,代码来源:udhcpc.c

示例14: on_client_ifup

static void
on_client_ifup(void)
{
	int i, i_dns = 0;
	char buf[256];
	char *script_name = VPN_CLIENT_UPDOWN_SCRIPT;

	nvram_set_int_temp("vpnc_state_t", 1);

	buf[0] = 0;
	if (nvram_get_int("vpnc_pdns") > 0) {
		int buf_len;
		char *value;
		char foption[32], fdns[128];
		
		for (i = 0; i < 20 && i_dns < 3; i++) {
			sprintf(foption, "foreign_option_%d", i);
			value = getenv(foption);
			if (value) {
				fdns[0] = 0;
				if (sscanf(value, "dhcp-option DNS %s", fdns) == 1) {
					buf_len = strlen(buf);
					snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s%s", (buf_len) ? " " : "", fdns);
					i_dns++;
					if (i_dns == 1)
						setenv("DNS1", fdns, 1);
					else if (i_dns == 2)
						setenv("DNS2", fdns, 1);
				}
			}
		}
	}

	nvram_set_temp("vpnc_dns_t", buf);
	if (strlen(buf) > 0)
		update_resolvconf(0, 0);

	if (check_if_file_exist(script_name)) {
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			setenv(env_pppd[i], safe_getenv(env_ovpn[i]), 1);
		doSystem("%s %s", script_name, "up");
		for (i = 0; i < ARRAY_SIZE(env_ovpn); i++)
			unsetenv(env_pppd[i]);
	}

	if (i_dns > 1)
		unsetenv("DNS2");
	if (i_dns > 0)
		unsetenv("DNS1");
}
开发者ID:PterX,项目名称:rt-n56u,代码行数:50,代码来源:vpn_openvpn.c

示例15: bound

static int bound(char *ifname)
{
	_dprintf("%s: begin\n", __FUNCTION__);

	unlink(renewing);

	env2nv("ip", "wan_ipaddr");
	env2nv("subnet", "wan_netmask");
	env2nv_gateway("wan_gateway");
	env2nv("dns", "wan_get_dns");
	env2nv("domain", "wan_get_domain");
	env2nv("lease", "wan_lease");
	expires(atoi(safe_getenv("lease")));
	
	_dprintf("wan_ipaddr=%s\n", nvram_safe_get("wan_ipaddr"));
	_dprintf("wan_netmask=%s\n", nvram_safe_get("wan_netmask"));
	_dprintf("wan_gateway=%s\n", nvram_safe_get("wan_gateway"));
	_dprintf("wan_get_domain=%s\n", nvram_safe_get("wan_get_domain"));
	_dprintf("wan_get_dns=%s\n", nvram_safe_get("wan_get_dns"));
	_dprintf("wan_lease=%s\n", nvram_safe_get("wan_lease"));
	

	ifconfig(ifname, IFUP, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask"));

	if (get_wan_proto() == WP_L2TP) {
		int i = 0;

		/* Delete all default routes */
		while ((route_del(ifname, 0, NULL, NULL, NULL) == 0) || (i++ < 10));

		/* Set default route to gateway if specified */
		route_add(ifname, 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0");

		/* Backup the default gateway. It should be used if L2TP connection is broken */
		nvram_set("wan_gateway_buf", nvram_get("wan_gateway"));

		/* clear dns from the resolv.conf */
		nvram_set("wan_get_dns","");
		dns_to_resolv();

		start_firewall();
		start_l2tp();
	}
	else {
		start_wan_done(ifname);
	}

	_dprintf("%s: end\n", __FUNCTION__);
	return 0;
}
开发者ID:twtomato,项目名称:twtomato,代码行数:50,代码来源:dhcp.c


注:本文中的safe_getenv函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。