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


C++ pledge函数代码示例

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


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

示例1: main

int
main(int argc, char *argv[])
{
	if (pledge("stdio rpath inet dns getpw tty", NULL) == -1)
		err(1, "pledge");

	get_names(argc, argv);
	init_display();
	open_ctl();
	open_sockt();
	start_msgs();
	if (!check_local())
		invite_remote();
	end_msgs();
	set_edit_chars();

	if (his_machine_addr.s_addr == my_machine_addr.s_addr) {
		if (pledge("stdio tty", NULL) == -1)
			err(1, "pledge");
	} else {
		if (pledge("stdio inet tty", NULL) == -1)
			err(1, "pledge");
	}

	talk();
	return (0);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:27,代码来源:talk.c

示例2: main

/*
 * rm --
 *	This rm is different from historic rm's, but is expected to match
 *	POSIX 1003.2 behavior.  The most visible difference is that -f
 *	has two specific effects now, ignore non-existent files and force
 * 	file removal.
 */
int
main(int argc, char *argv[])
{
	int ch, rflag;

	setlocale(LC_ALL, "");

	Pflag = rflag = 0;
	while ((ch = getopt(argc, argv, "dfiPRr")) != -1)
		switch(ch) {
		case 'd':
			dflag = 1;
			break;
		case 'f':
			fflag = 1;
			iflag = 0;
			break;
		case 'i':
			fflag = 0;
			iflag = 1;
			break;
		case 'P':
			Pflag = 1;
			break;
		case 'R':
		case 'r':			/* Compatibility. */
			rflag = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (Pflag) {
		if (pledge("stdio rpath wpath cpath getpw", NULL) == -1)
			err(1, "pledge");
	} else {
		if (pledge("stdio rpath cpath getpw", NULL) == -1)
			err(1, "pledge");
	}

	if (argc < 1 && fflag == 0)
		usage();

	checkdot(argv);

	if (*argv) {
		stdin_ok = isatty(STDIN_FILENO);

		if (rflag)
			rm_tree(argv);
		else
			rm_file(argv);
	}

	exit(eval);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:65,代码来源:rm.c

示例3: drop_privileges

/*
 * this section of code will drop all (OpenBSD) privileges including
 * those normally granted to all userland process (basic privileges). The
 * effect of this is that after running this code, the process will not able
 * to fork(), exec(), etc.  See pledge(2) for more information.
 */
void drop_privileges() {
    extern char *__progname;

    if (settings.socketpath != NULL) {
       if (pledge("stdio unix", NULL) == -1) {
          fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
          exit(EXIT_FAILURE);
       }
    } else {
       if (pledge("stdio inet", NULL) == -1) {
          fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
          exit(EXIT_FAILURE);
       }
     }
}
开发者ID:dormando,项目名称:memcached,代码行数:21,代码来源:openbsd_priv.c

示例4: main

int
main(int argc, char *argv[])
{
    int ret_val;

    if (pledge("stdio rpath", NULL) == -1) {
	perror("pledge");
	exit(1);
    }

    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
	(void)signal(SIGINT, terminate);
    ret_val = setup(argc, argv);
    if (!ret_val) {
	/*
	 * select the output format based on options
	 */
	if (merge)
	    ret_val = mulfile(argc, argv);
	else if (clcnt == 1)
	    ret_val = onecol(argc, argv);
	else if (across)
	    ret_val = horzcol(argc, argv);
	else
	    ret_val = vertcol(argc, argv);
    } else
	usage();
    flsh_errs();
    if (errcnt || ret_val)
	exit(1);
    return(0);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:32,代码来源:pr.c

示例5: irr_main

__dead void
irr_main(u_int32_t AS, int flags, char *outdir)
{
	char	*query;
	int	 r;

	if (pledge("stdio rpath wpath cpath inet dns", NULL) == -1)
		err(1, "pledge");

	fprintf(stderr, "irrfilter for: %u, writing to %s\n", AS, outdir);

	irrflags = flags;
	irrverbose = 0;
	TAILQ_INIT(&router_head);

	/* send query for own AS, parse policy */
	if (asprintf(&query, "AS%u", AS) == -1)
		err(1, "parse_policy asprintf");
	if ((r = whois(query, QTYPE_OWNAS)) == -1)
		exit(1);
	if (r == 0)
		errx(1, "aut-num object %s not found", query);
	free(query);

	write_filters(outdir);

	exit(0);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:28,代码来源:irrfilter.c

示例6: main

int
main(int argc, char *argv[])
{
    if (pledge("stdio rpath tty", NULL) == -1)
        err(1, "pledge");

    do_options(argc, argv);

    intro();
    do {
	initgame();
	while(awinna() == -1)
	{
	    if (!blitz)
	    {
		if (!salvo)
		{
	    	    if(turn)
			(void) cputurn();
		    else
			(void) plyturn();
		}
		else  /* salvo */
		{
		    int i;

		    i = scount(turn);
		    while (i--)
		    {
			if (turn)
			{
			    if (cputurn() && awinna() != -1)
				i = 0;
			}
			else
			{
			    if (plyturn() && awinna() != -1)
				i = 0;
			}
		    }
		}
	    }
	    else  /* blitz */
	    	while(turn ? cputurn() : plyturn())
		{
		    if (turn)   /* Pause between successive computer shots */
		    {
			(void)refresh();
			(void)sleep(1);
		    }
		    if (awinna() != -1)
		     break;
		}
	    turn = OTHER;
	}
    } while
	(playagain());
    uninitgame(0);
    return 0;
}
开发者ID:a565109863,项目名称:src,代码行数:60,代码来源:bs.c

示例7: main

int
main(int argc, char *argv[])
{
	int ch;
	char *p;

	setlocale(LC_ALL, "");

	if (pledge("stdio", NULL) == -1)
		err(1, "pledge");

	while ((ch = getopt(argc, argv, "")) != -1)
		switch (ch) {
		case '?':
		default:
			usage();
			/* NOTREACHED */
		}

	if (argc != optind) {
		usage();
		/* NOTREACHED */
	}

	if ((p = getlogin()) == NULL)
		err(1, NULL);
	(void)printf("%s\n", p);
	exit(0);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:29,代码来源:logname.c

示例8: main

int
main(int argc, char **argv)
{
	struct passwd *pw;
	struct skey key;
	char *name = NULL;
	int error, ch, verbose = 0;

	if (pledge("stdio rpath wpath flock getpw", NULL) == -1)
		err(1, "pledge");

	while ((ch = getopt(argc, argv, "v")) != -1)
		switch(ch) {
		case 'v':
			verbose = 1;
			break;
		default:
			usage();
	}
	argc -= optind;
	argv += optind;

	if (argc == 1)
		name = argv[0];
	else if (argc > 1)
		usage();

	if (name && getuid() != 0)
		errx(1, "only root may specify an alternate user");

	if (name) {
		if ((pw = getpwnam(name)) == NULL)
			errx(1, "no passwd entry for %s", name);
	} else {
		if ((pw = getpwuid(getuid())) == NULL)
			errx(1, "no passwd entry for uid %u", getuid());
	}

	if ((name = strdup(pw->pw_name)) == NULL)
		err(1, "cannot allocate memory");
	sevenbit(name);

	error = skeylookup(&key, name);
	switch (error) {
		case 0:		/* Success! */
			if (verbose)
				(void)printf("otp-%s ", skey_get_algorithm());
			(void)printf("%d %s\n", key.n - 1, key.seed);
			break;
		case -1:	/* File error */
			err(1, "cannot open %s/%s", _PATH_SKEYDIR, name);
			break;
		case 1:		/* Unknown user */
			errx(1, "%s is not listed in %s", name, _PATH_SKEYDIR);
			break;
	}
	(void)fclose(key.keyfile);

	exit(error ? 1 : 0);
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:60,代码来源:skeyinfo.c

示例9: main

int
main(int argc, char *argv[])
{
	struct val     *vp;

	(void) setlocale(LC_ALL, "");

	if (pledge("stdio", NULL) == -1)
		err(1, "pledge");

	if (argc > 1 && !strcmp(argv[1], "--"))
		argv++;

	av = argv + 1;

	nexttoken(0);
	vp = eval0();

	if (token != EOI) {
		error();
		/* NOTREACHED */
	}

	if (vp->type == integer)
		printf("%d\n", vp->u.i);
	else
		printf("%s\n", vp->u.s);

	exit(is_zero_or_null(vp));
}
开发者ID:radixo,项目名称:openbsd-src,代码行数:30,代码来源:expr.c

示例10: main

int
main(int argc, char *argv[])
{
	int			 ch;
	struct parse_result	*result;

	while ((ch = getopt(argc, argv, "")) != -1)
		switch (ch) {
		default:
			usage();
			return (EXIT_FAILURE);
		}
	argc -= optind;
	argv += optind;

	if ((result = parse(argc, argv)) == NULL)
		return (EXIT_FAILURE);

	switch (result->action) {
	case NONE:
		break;
	case TEST:
		if (pledge("stdio dns inet", NULL) == -1)
			err(EXIT_FAILURE, "pledge");
		radius_test(result);
		break;
	}

	return (EXIT_SUCCESS);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:30,代码来源:radiusctl.c

示例11: main

int
main(int argc, char *argv[])
{
	int ch, c, fd, ret = 1;
	struct stat sb;
	char *pr_form;
	time_t mtime;
	FILE *fp;

	if (pledge("stdio rpath wpath cpath tmppath getpw proc exec", NULL) == -1)
		err(1, "pledge");

	while ((ch = getopt(argc, argv, "DEP")) != -1)
		switch (ch) {
		case 'D':
			Dflag = 1;
			break;
		case 'E':
			debase();
			exit(0);
		case 'P':
			Pflag = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc > 0)
		usage();

	if (Pflag) {
		init();
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:34,代码来源:sendbug.c

示例12: main

int
main(int argc, char *argv[])
{
	f = -1;

	if (pledge("stdio rpath wpath cpath dns inet", NULL) == -1)
		err(1, "pledge");

	/* set default transfer mode */
	strlcpy(mode, "netascii", sizeof(mode));

	/* set peer if given */
	if (argc > 1)
		parsearg(argc, argv);

	/* catch SIGINT */
	signal(SIGINT, intr);

	/* allocate memory for packets */
	if ((ackbuf = malloc(SEGSIZE_MAX + 4)) == NULL)
		err(1, "malloc");

	/* command prompt */
	command();

	return (0);
}
开发者ID:darksoul42,项目名称:bitrig,代码行数:27,代码来源:main.c

示例13: main

int
main(int argc, char *argv[])
{
	FILE *fp;
	int c;

	if (pledge("stdio rpath", NULL) == -1)
		err(1, "pledge");

	fp = NULL;
	while ((c = getopt(argc, argv, "Ddpt:w:")) != -1) {
		switch (c) {
#ifdef DEBUG
		case 'D':
			Debug = 1;
			break;
#endif
		case 'd':
			Flags |= AC_D;
			break;
		case 'p':
			Flags |= AC_P;
			break;
		case 't':			/* only do specified ttys */
			add_tty(optarg);
			break;
		case 'w':
			fp = file(optarg);
			break;
		case '?':
		default:
			usage();
			break;
		}
	}
	if (optind < argc) {
		/*
		 * initialize user list
		 */
		for (; optind < argc; optind++) {
			Users = update_user(Users, argv[optind], 0L);
		}
		Flags |= AC_U;			/* freeze user list */
	}
	if (Flags & AC_D)
		Flags &= ~AC_P;
	if (fp == NULL) {
		/*
		 * if _PATH_WTMP does not exist, exit quietly
		 */
		if (access(_PATH_WTMP, 0) != 0 && errno == ENOENT)
			return 0;

		fp = file(_PATH_WTMP);
	}
	ac(fp);

	return 0;
}
开发者ID:ajinkya93,项目名称:OpenBSD,代码行数:59,代码来源:ac.c

示例14: sandbox_after

int
sandbox_after(void)
{

	switch (proccomp) {
	case (COMP_ACCOUNT):
	case (COMP_CERT):
	case (COMP_KEY):
	case (COMP_REVOKE):
	case (COMP__MAX):
		if (-1 == pledge("stdio", NULL)) {
			warn("pledge");
			return(0);
		}
		break;
	case (COMP_CHALLENGE):
		if (-1 == pledge("stdio cpath wpath", NULL)) {
			warn("pledge");
			return(0);
		}
		break;
	case (COMP_DNS):
		if (-1 == pledge("stdio dns", NULL)) {
			warn("pledge");
			return(0);
		}
		break;
	case (COMP_FILE):
		/* 
		 * Rpath and cpath for rename, wpath and cpath for
		 * writing to the temporary.
		 */
		if (-1 == pledge("stdio cpath wpath rpath", NULL)) {
			warn("pledge");
			return(0);
		}
		break;
	case (COMP_NET):
		if (-1 == pledge("stdio inet", NULL)) {
			warn("pledge");
			return(0);
		}
		break;
	}
	return(1);
}
开发者ID:ehasting,项目名称:letskencrypt-portable,代码行数:46,代码来源:sandbox-pledge.c

示例15: main

int
main(void)
{
	if (-1 == pledge("stdio", NULL)) {
		perror("pledge");
		return(1);
	}
	return(0);
}
开发者ID:StAlphonsos,项目名称:kcgi,代码行数:9,代码来源:test-pledge.c


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