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


C++ setpwent函数代码示例

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


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

示例1: uam_authuserpass

int uam_authuserpass(char *user, char *pass)
{	int		ok = 0;
	struct passwd	*pwd= NULL;

	if(user != NULL && pass != NULL)
	{
		setpwent();
		ok = ((pwd = getpwnam(user)) != NULL && strcmp((char *)crypt(pass,pwd->pw_passwd),pwd->pw_passwd) == 0);
		endpwent();
	}

	return(ok);
}
开发者ID:nkhorman,项目名称:spamilter,代码行数:13,代码来源:uam.c

示例2: getpwuid

struct passwd*
getpwuid(uid_t uid)
{
    setpwent();
    while (getpwent()) {
        if (current_passwd.pw_uid == uid) {
            endpwent();
            return &current_passwd;
        }
    }
    endpwent();
    return 0;
}
开发者ID:passick,项目名称:xv6,代码行数:13,代码来源:pwd.c

示例3: getpwnam

struct passwd*
getpwnam(const char* name)
{
    setpwent();
    while (getpwent()) {
        if (strcmp(name, current_passwd.pw_name) == 0) {
            endpwent();
            return &current_passwd;
        }
    }
    endpwent();
    return 0;
}
开发者ID:passick,项目名称:xv6,代码行数:13,代码来源:pwd.c

示例4: dump_limits_any_type

static void
dump_limits_any_type(
	FILE		*fp,
	uint		type,
	char		*dir,
	uint		lower,
	uint		upper)
{
	fs_path_t	*mount;
	uint		id;

	if ((mount = fs_table_lookup(dir, FS_MOUNT_POINT)) == NULL) {
		exitcode = 1;
		fprintf(stderr, "%s: cannot find mount point %s\n",
			progname, dir);
		return;
	}

	if (upper) {
		for (id = lower; id <= upper; id++)
			dump_file(fp, id, type, mount->fs_name);
		return;
	}

	switch (type) {
	case XFS_GROUP_QUOTA: {
			struct group *g;
			setgrent();
			while ((g = getgrent()) != NULL)
				dump_file(fp, g->gr_gid, type, mount->fs_name);
			endgrent();
			break;
		}
	case XFS_PROJ_QUOTA: {
			struct fs_project *p;
			setprent();
			while ((p = getprent()) != NULL)
				dump_file(fp, p->pr_prid, type, mount->fs_name);
			endprent();
			break;
		}
	case XFS_USER_QUOTA: {
			struct passwd *u;
			setpwent();
			while ((u = getpwent()) != NULL)
				dump_file(fp, u->pw_uid, type, mount->fs_name);
			endpwent();
			break;
		}
	}
}
开发者ID:ystk,项目名称:debian-xfsprogs,代码行数:51,代码来源:report.c

示例5: username_tab_completion

static void username_tab_completion(char *ud, char *with_shash_flg)
{
	struct passwd *entry;
	int userlen;

	ud++;                           /* ~user/... to user/... */
	userlen = strlen(ud);

	if (with_shash_flg) {           /* "~/..." or "~user/..." */
		char *sav_ud = ud - 1;
		char *home = NULL;
		char *temp;

		if (*ud == '/') {       /* "~/..."     */
			home = home_pwd_buf;
		} else {
			/* "~user/..." */
			temp = strchr(ud, '/');
			*temp = 0;              /* ~user\0 */
			entry = getpwnam(ud);
			*temp = '/';            /* restore ~user/... */
			ud = temp;
			if (entry)
				home = entry->pw_dir;
		}
		if (home) {
			if ((userlen + strlen(home) + 1) < MAX_LINELEN) {
				char temp2[MAX_LINELEN];     /* argument size */

				/* /home/user/... */
				sprintf(temp2, "%s%s", home, ud);
				strcpy(sav_ud, temp2);
			}
		}
	} else {
		/* "~[^/]*" */
		/* Using _r function to avoid pulling in static buffers */
		char line_buff[256];
		struct passwd pwd;
		struct passwd *result;

		setpwent();
		while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) {
			/* Null usernames should result in all users as possible completions. */
			if (/*!userlen || */ strncmp(ud, pwd.pw_name, userlen) == 0) {
				add_match(xasprintf("~%s/", pwd.pw_name));
			}
		}
		endpwent();
	}
}
开发者ID:hajuuk,项目名称:R7000,代码行数:51,代码来源:lineedit.c

示例6: getenv

int FileSystem::parse_tildas(char *new_dir)
{
	if(new_dir[0] == 0) return 1;

// Our home directory
	if(new_dir[0] == '~')
	{

		if(new_dir[1] == '/' || new_dir[1] == 0)
		{
// user's home directory
			char *home;
			char string[BCTEXTLEN];
			home = getenv("HOME");

// print starting after tilda
			if(home) sprintf(string, "%s%s", home, &new_dir[1]);
			strcpy(new_dir, string);
			return 0;
		}
		else
// Another user's home directory
		{                
			char string[BCTEXTLEN], new_user[BCTEXTLEN];
			struct passwd *pw;
			int i, j;
      
			for(i = 1, j = 0; new_dir[i] != 0 && new_dir[i] != '/'; i++, j++)
			{                // copy user name
				new_user[j] = new_dir[i];
			}
			new_user[j] = 0;
      
			setpwent();
			while(pw = getpwent())
			{
// get info for user
				if(!strcmp(pw->pw_name, new_user))
				{
// print starting after tilda
      				sprintf(string, "%s%s", pw->pw_dir, &new_dir[i]);
      				strcpy(new_dir, string);
      				break;
      			}
			}
			endpwent();
			return 0;
		}
	}
	return 0;
}
开发者ID:beequ7et,项目名称:cinelerra-cv,代码行数:51,代码来源:filesystem.C

示例7: setpwent

struct passwd *getpwent_base(void)
/*
 * Basic getpwent().
 */
{
	if (!_pw_file) {
		/* open file */
		setpwent();
		if (!_pw_file)
			return (NULL);
	}

	return (fgetpwent_base(_pw_file));
}
开发者ID:OS2World,项目名称:UTIL-SYSTEM-Pwd-2,代码行数:14,代码来源:pw2base.c

示例8: find_home_for_username

/* Lookup username (of length ulen), return home directory if found,
 * or NULL if not found.
 */
static const char *
find_home_for_username (const char *username, size_t ulen)
{
  struct passwd *pw;

  setpwent ();
  while ((pw = getpwent ()) != NULL) {
    if (strlen (pw->pw_name) == ulen &&
        STREQLEN (username, pw->pw_name, ulen))
      return pw->pw_dir;
  }

  return NULL;
}
开发者ID:gaowanlong,项目名称:libguestfs,代码行数:17,代码来源:tilde.c

示例9: setpwent

QStringList KUser::allUserNames(uint maxCount)
{
    QStringList result;

    passwd *p;
    setpwent();

    for (uint i = 0; i < maxCount && (p = getpwent()); ++i) {
        result.append(QString::fromLocal8Bit(p->pw_name));
    }

    endpwent();
    return result;
}
开发者ID:mathieusab,项目名称:kcoreaddons,代码行数:14,代码来源:kuser_unix.cpp

示例10: main

int main(void)
{
    struct passwd *pwd;

    setpwent();

    while ((pwd = getpwent())) {
        printf("%s\n", pwd->pw_name);
    }

    endpwent();

    return 0;
}
开发者ID:tridge,项目名称:junkcode,代码行数:14,代码来源:getpwent_replace.c

示例11: find_home_for_current_user

static const char *
find_home_for_current_user (void)
{
  struct passwd *pw;
  uid_t euid = geteuid ();

  setpwent ();
  while ((pw = getpwent ()) != NULL) {
    if (pw->pw_uid == euid)
      return pw->pw_dir;
  }

  return NULL;
}
开发者ID:gaowanlong,项目名称:libguestfs,代码行数:14,代码来源:tilde.c

示例12: pwd_check_functions

void pwd_check_functions()
{
#if __XSI_VISIBLE
    (void)endpwent();
    (void)getpwent();
#endif
    (void)getpwnam((const char *)0);
    (void)getpwnam_r((const char *)0, (struct passwd *)0, (char *)0, (size_t)0, (struct passwd **)0);
    (void)getpwuid((uid_t)0);
    (void)getpwuid_r((uid_t)0, (struct passwd *)0, (char *)0, (size_t)0, (struct passwd **)0);
#if __XSI_VISIBLE
    (void)setpwent();
#endif
}
开发者ID:senlinms,项目名称:android-platform-ndk,代码行数:14,代码来源:pwd.c

示例13: my_getpwnam

struct passwd *
my_getpwnam(const char *name)
{
  struct passwd *ptr = NULL;

  setpwent();

  while ( (ptr = getpwent()) != NULL)
    if (strcmp(ptr->pw_name, name) == 0)
      break;

  endpwent();

  return ptr;
}
开发者ID:Arkham,项目名称:c_examples,代码行数:15,代码来源:getpwent.c

示例14: eel_get_user_names

/**
 * eel_get_user_names:
 *
 * Get a list of user names.
 * The caller is responsible for freeing this list and its contents.
 */
GList *
eel_get_user_names (void)
{
	GList *list;
	struct passwd *user;

	list = NULL;
	setpwent ();
	while ((user = getpwent ()) != NULL) {
		list = g_list_prepend (list, g_strdup (user->pw_name));
	}
	endpwent ();

	return eel_g_str_list_alphabetize (list);
}
开发者ID:antonio-malcolm,项目名称:pantheon-files-forked,代码行数:21,代码来源:eel-fcts.c

示例15: uidFromName

int uidFromName(const char *uname) {
  struct passwd *pw;

  setpwent();
  while((pw = getpwent()) != NULL) {
    if(strcmp(uname, pw->pw_name) == 0) {
      int uid = pw->pw_uid;
      endpwent();
      return uid;
    }
  }

  endpwent();
  return -1;
}
开发者ID:opieproject,项目名称:opie,代码行数:15,代码来源:runtests.cpp


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