本文整理汇总了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);
}
示例2: getpwuid
struct passwd*
getpwuid(uid_t uid)
{
setpwent();
while (getpwent()) {
if (current_passwd.pw_uid == uid) {
endpwent();
return ¤t_passwd;
}
}
endpwent();
return 0;
}
示例3: getpwnam
struct passwd*
getpwnam(const char* name)
{
setpwent();
while (getpwent()) {
if (strcmp(name, current_passwd.pw_name) == 0) {
endpwent();
return ¤t_passwd;
}
}
endpwent();
return 0;
}
示例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;
}
}
}
示例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();
}
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例10: main
int main(void)
{
struct passwd *pwd;
setpwent();
while ((pwd = getpwent())) {
printf("%s\n", pwd->pw_name);
}
endpwent();
return 0;
}
示例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;
}
示例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
}
示例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;
}
示例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);
}
示例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;
}