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


C++ setegid函数代码示例

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


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

示例1: priv_cred_setegid

void
priv_cred_setegid(int asroot, int injail, struct test *test)
{
	int error;

	error = setegid(GID_OTHER);
	if (asroot && injail)
		expect("priv_setegid(asroot, injail)", error, 0, 0);
	if (asroot && !injail)
		expect("priv_setegid(asroot, !injail)", error, 0, 0);
	if (!asroot && injail)
		expect("priv_setegd(!asroot, injail)", error, -1, EPERM);
	if (!asroot && !injail)
		expect("priv_setegid(!asroot, !injail)", error, -1, EPERM);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:15,代码来源:priv_cred.c

示例2: Privsep_SetGroup

int Privsep_SetGroup(gid_t gid)
{
    if (setgroups(1, &gid) == -1)
        return(OS_INVALID);

    #ifndef HPUX
    if(setegid(gid) < 0)
        return(OS_INVALID);
    #endif

    if(setgid(gid) < 0)
        return(OS_INVALID);

    return(OS_SUCCESS);
}
开发者ID:RobertoD91,项目名称:ossec,代码行数:15,代码来源:privsep_op.c

示例3: OS_Set_EGID

//
//  OS_Set_EGID: C
// 
// Set the effective group ID
//
REBINT OS_Set_EGID(REBINT gid)
{
    if (setegid(gid) < 0) {
        switch (errno) {
            case EINVAL:
                return OS_EINVAL;
            case EPERM:
                return OS_EPERM;
            default:
                return -errno;
        }
    } else {
        return 0;
    }
}
开发者ID:kjanz1899,项目名称:ren-c,代码行数:20,代码来源:host-process.c

示例4: initialize

void
initialize(iter_t iterations, void* cookie)
{
	state_t	*state = (state_t *) cookie;
	char path[PATH_MAX];
	int ret;
	int fd;
	int rw = state->write ? O_WRONLY: 0;
	if (iterations) return;

	/* Use isolated directories to eliminate locking contetion on path,
	 * from measurements */
	if (state->isolate) {
		sprintf(path, "%s/%d", state->path, benchmp_childid());
 		if (chdir(path))
			DO_ABORT("chdir() failed");
	} else {
		sprintf(path, "%s/%s", state->path, state->filename);
		strcpy(state->filename, path);
	}

	if (state->use_uid) {
		setegid(benchmp_childid_gid());
		seteuid(benchmp_childid_uid());
	}
	if (state->lock_uid) {
		if (state->lock_uid > sizeof(state->qfd[0]) / sizeof(int))
			state->lock_uid = sizeof(state->qfd[0]) / sizeof(int);
		ret = get_quota_n(state->filename,
				geteuid(), getegid(),
				state->qfd[0], state->lock_uid);
		if (ret)
			DO_ABORT("Cant get quota");
	}
	state->fd = -1;
	if (state->clone) {
		char buf[128];
		char* s;
		sprintf(buf, "%d", (int)getpid());
		s = (char*)malloc(strlen(state->filename) + strlen(buf) + 1);
		sprintf(s, "%s%d", state->filename, (int)getpid());
		strcpy(state->filename, s);
	}
	fd = open(state->filename, O_CREAT|rw, 0666);
	if (fd < 0)
		DO_ABORT("open");
	state->fd = fd;
}
开发者ID:chitranshi,项目名称:lmbench,代码行数:48,代码来源:lat_fs_write_truncate.c

示例5: do_cmd_pass

void do_cmd_pass(session_t *pses)
{
    if(pses == NULL)
        handle_error_str("do_cmd_user: pses is NULL.");
    //收到密码后,开始用户验证
    //根据用户uid获取用户信息
    struct passwd *pw = getpwuid(pses->uid);    //尝试获取要登陆用户的信息
    if(pw == NULL)
    {
        //用户不存在
        ftp_reply(pses->ctrl_fd, FTP_LOGINERR, "Login incorrect."); //530
        return;
    }
    //根据用户名字获取密码信息
    struct spwd *sp = getspnam(pw->pw_name);
    if(sp == NULL)
    {
        //用户不存在
        ftp_reply(pses->ctrl_fd, FTP_LOGINERR, "Login incorrect."); //530
        return;
    }

    //将明文密码进行加密
    struct crypt_data data;
    data.initialized = 0;
    char *encrupted_pass = crypt_r(pses->arg, sp->sp_pwdp,&data);

    //加密结果对比
    if(strcmp(encrupted_pass, sp->sp_pwdp) != 0)
    {
        //验证失败
        ftp_reply(pses->ctrl_fd, FTP_LOGINERR, "Login incorrect."); //530
        return;
    }
    //密码验证成功
    ftp_reply(pses->ctrl_fd, FTP_LOGINOK, "Login successful."); //230

    //更改umask
    umask(tunable_local_umask);
    //更改进程属性
    if(setegid(pw->pw_gid) < 0)
        handle_error("setegid");
    if(seteuid(pw->pw_uid) < 0)
        handle_error("seteuid");
    //更改当前工作目录到用户家目录
    if(chdir(pw->pw_dir) < 0)
        handle_error("chdir");
}
开发者ID:cmbug,项目名称:Mftp,代码行数:48,代码来源:ftpprotocol.c

示例6: drop_privileges

int drop_privileges(struct passwd *pw, pam_handle_t *pamh) {
#ifdef HAVE_PAM_MODUTIL_DROP_PRIV
  int res;
  res = pam_modutil_drop_priv(pamh, _privs_location(0), pw);
  if (res)
    D (("pam_modutil_drop_priv: %i", res));
  return res;
#else
    saved_euid = geteuid();
    saved_egid = getegid();

    saved_groups_length = getgroups(0, NULL);
    if (saved_groups_length < 0) {
        D (("getgroups: %s", strerror(errno)));
        return -1;
    }

    if (saved_groups_length > 0) {
        saved_groups = malloc(saved_groups_length * sizeof(gid_t));
        if (saved_groups == NULL) {
            D (("malloc: %s", strerror(errno)));
            return -1;
        }

        if (getgroups(saved_groups_length, saved_groups) < 0) {
            D (("getgroups: %s", strerror(errno)));
            return -1;
        }
    }

    if (initgroups(pw->pw_name, pw->pw_gid) < 0) {
        D (("initgroups: %s", strerror(errno)));
        return -1;
    }

    if (setegid(pw->pw_gid) < 0) {
        D (("setegid: %s", strerror(errno)));
        return -1;
    }

    if (seteuid(pw->pw_uid) < 0) {
        D (("seteuid: %s", strerror(errno)));
        return -1;
    }

    return 0;
#endif /* HAVE_PAM_MODUTIL_DROP_PRIV */
}
开发者ID:BinetReseau,项目名称:yubico-pam,代码行数:48,代码来源:drop_privs.c

示例7: enter_user_context_effective

static inline void enter_user_context_effective()
{
	gid_t *groups;
	size_t ngroups;
	struct fuse_context *c = fuse_get_context();

	if (!single_threaded || getuid())
		return;
	if ((ngroups = get_groups(c->pid, &groups))) {
		setgroups(ngroups, groups);
		free(groups);
	}

	setegid(c->gid);
	seteuid(c->uid);
}
开发者ID:Equidamoid,项目名称:ciopfs,代码行数:16,代码来源:ciopfs.c

示例8: safe_setuid_drop

/*
 * Drop permissions
 */
void safe_setuid_drop(void)
{
#ifdef SET_UID
# if defined(HAVE_SETRESGID)

	if (setresgid(-1, getgid(), -1) != 0)
		quit("setegid(): cannot drop permissions correctly!");

# else

	if (setegid(getgid()) != 0)
		quit("setegid(): cannot drop permissions correctly!");

# endif
#endif /* SET_UID */
}
开发者ID:cinereaste,项目名称:angband,代码行数:19,代码来源:z-file.c

示例9: cleanup

/*
 * void
 * cleanup() - performs all ONE TIME cleanup for this test at
 *		completion or premature exit.
 *  Close the test directory opened in the setup().
 *  Remove the test directory and temporary directory created in
 *  in the setup().
 */
void cleanup(void)
{

	/* Close the test directory opened in the setup() */
	if (close(fd) == -1) {
		tst_brkm(TBROK, NULL,
			 "close(%s) Failed, errno=%d : %s",
			 TESTDIR, errno, strerror(errno));
	}

	setegid(0);
	seteuid(0);

	tst_rmdir();

}
开发者ID:AbhiramiP,项目名称:ltp,代码行数:24,代码来源:fchmod05.c

示例10: safe_setuid_grab

/*
 * Grab permissions
 */
void safe_setuid_grab(void)
{
#ifdef SET_UID
# if defined(HAVE_SETRESGID)

	if (setresgid(-1, player_egid, -1) != 0)
		quit("setegid(): cannot grab permissions correctly!");

# elif defined(HAVE_SETEGID)

	if (setegid(player_egid) != 0)
		quit("setegid(): cannot grab permissions correctly!");

# endif
#endif /* SET_UID */
}
开发者ID:cinereaste,项目名称:angband,代码行数:19,代码来源:z-file.c

示例11: main

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

	dump_stdin_to_file();

	setuid ( 0 );
	setgid ( 0 );

	seteuid ( 0 );
	setegid ( 0 );

	execvp( QNS_BINARY, argv );

	fprintf ( stderr, "443 qns_loader error\n" );
	return 150;
}
开发者ID:zixia,项目名称:nospam,代码行数:16,代码来源:qns_loader.c

示例12: setreuid

/* Loads the game dll */
void *Sys_GetGameAPI(void *parms){
	gameapi_t * GetGameAPI;
	FILE * fp;
	char name[MAX_OSPATH];
	char * path;
	
	setreuid(getuid(), getuid());
	setegid(getgid());
	
	if(game_library)
		Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadGame");
		
	Com_Printf("------- Loading game.so -------\n");
	
	/* now run through the search paths */
	path = NULL;
	while(1){
		path = FS_NextPath(path);
		if(!path)
			return NULL;
		snprintf(name, MAX_OSPATH, "%s/game.so", path);
		
		/* skip it if it doesn't exist */
		fp = fopen(name, "rb");
		if(fp == NULL)
			continue;
		fclose(fp);
		
		game_library = dlopen(name, RTLD_NOW);
		if(game_library){
			Com_MDPrintf("LoadLibrary(%s)\n", name);
			break;
		} else {
			Com_MDPrintf("LoadLibrary(%s)\n", name);
			Com_MDPrintf("%s\n", dlerror());
		}
	}
	
	GetGameAPI =(gameapi_t *) dlsym(game_library, "GetGameAPI");
	
	if(!GetGameAPI){
		Sys_UnloadGame();
		return NULL;
	}
	
	return GetGameAPI(parms);
}
开发者ID:luaman,项目名称:qforge-2,代码行数:48,代码来源:main.c

示例13: send_intent

int send_intent() {
 
  char command[PATH_MAX];

  sprintf(command, "/system/bin/am start -n info.guardianproject.gpg.pinentry/info.guardianproject.gpg.pinentry.PINEntry > /dev/null"); 
  
      static const char* const unsec_vars[] = {
        "GCONV_PATH",
        "GETCONF_DIR",
        "HOSTALIASES",
        "LD_AUDIT",
        "LD_DEBUG",
        "LD_DEBUG_OUTPUT",
        "LD_DYNAMIC_WEAK",
        "LD_LIBRARY_PATH",
        "LD_ORIGIN_PATH",
        "LD_PRELOAD",
        "LD_PROFILE",
        "LD_SHOW_AUXV",
        "LD_USE_LOAD_BIAS",
        "LOCALDOMAIN",
        "LOCPATH",
        "MALLOC_TRACE",
        "MALLOC_CHECK_",
        "NIS_PATH",
        "NLSPATH",
        "RESOLV_HOST_CONF",
        "RES_OPTIONS",
        "TMPDIR",
        "TZDIR",
        "LD_AOUT_LIBRARY_PATH",
        "LD_AOUT_PRELOAD",
        // not listed in linker, used due to system() call
        "IFS",
    };
    const char* const* cp = unsec_vars;
    const char* const* endp = cp + sizeof(unsec_vars)/sizeof(unsec_vars[0]);
    while (cp < endp) {
        unsetenv(*cp);
        cp++;
    }
    // sane value so "am" works
    setenv("LD_LIBRARY_PATH", "/vendor/lib:/system/lib", 1);
    setegid(getgid());
    seteuid(getuid());
    return system(command);
}
开发者ID:abeluck,项目名称:pinentry-android,代码行数:47,代码来源:pinentry-android.c

示例14: setup_uid

void setup_uid(int euid_or_uid) {
#ifndef HAVE_WINDOWS_H
  if(getuid()==0) {
    char *uid_str=getenv("SUDO_UID"),*gid_str=getenv("SUDO_GID");
    uid_t uid=uid_str?atoi(uid_str):0;
    gid_t gid=gid_str?atoi(gid_str):0;

    if(euid_or_uid) {
      setegid(gid);
      seteuid(uid);
    }else {
      setgid(gid);
      setuid(uid);
    }
  }
#endif
}
开发者ID:JamesTFarrington,项目名称:roswell,代码行数:17,代码来源:util.c

示例15: escalate_privs

int escalate_privs(void) {

    message(DEBUG, "Called escalate_privs(void)\n");

    if ( seteuid(0) < 0 ) {
        message(ERROR, "Could not escalate effective user privileges: %s\n", strerror(errno));
        ABORT(255);
    }

    if ( setegid(0) < 0 ) {
        message(ERROR, "Could not escalate effective group privileges: %s\n", strerror(errno));
        ABORT(255);
    }

    message(DEBUG, "Returning escalate_privs(void) = 0\n");
    return(0);
}
开发者ID:nl384,项目名称:singularity,代码行数:17,代码来源:privilege.c


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