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


C++ endpwent函数代码示例

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


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

示例1: KCModule

KDModule::KDModule(QWidget *parent, const char *name, const QStringList &)
    : KCModule(KDMFactory::instance(), parent, name), minshowuid(0), maxshowuid(0), updateOK(false)
{
    KAboutData *about = new KAboutData(I18N_NOOP("kcmkdm"), I18N_NOOP("KDE Login Manager Config Module"), 0, 0, KAboutData::License_GPL,
                                       I18N_NOOP("(c) 1996 - 2005 The KDM Authors"));

    about->addAuthor("Thomas Tanghus", I18N_NOOP("Original author"), "[email protected]");
    about->addAuthor("Steffen Hansen", 0, "[email protected]");
    about->addAuthor("Oswald Buddenhagen", I18N_NOOP("Current maintainer"), "[email protected]");

    setQuickHelp(
        i18n("<h1>Login Manager</h1> In this module you can configure the "
             "various aspects of the KDE Login Manager. This includes "
             "the look and feel as well as the users that can be "
             "selected for login. Note that you can only make changes "
             "if you run the module with superuser rights. If you have not started the KDE "
             "Control Center with superuser rights (which is absolutely the right thing to "
             "do, by the way), click on the <em>Modify</em> button to acquire "
             "superuser rights. You will be asked for the superuser password."
             "<h2>Appearance</h2> On this tab page, you can configure how "
             "the Login Manager should look, which language it should use, and which "
             "GUI style it should use. The language settings made here have no influence on "
             "the user's language settings."
             "<h2>Font</h2>Here you can choose the fonts that the Login Manager should use "
             "for various purposes like greetings and user names. "
             "<h2>Background</h2>If you want to set a special background for the login "
             "screen, this is where to do it."
             "<h2>Shutdown</h2> Here you can specify who is allowed to shutdown/reboot the machine "
             "and whether a boot manager should be used."
             "<h2>Users</h2>On this tab page, you can select which users the Login Manager "
             "will offer you for logging in."
             "<h2>Convenience</h2> Here you can specify a user to be logged in automatically, "
             "users not needing to provide a password to log in, and other convenience features.<br>"
             "Note, that these settings are security holes by their nature, so use them very carefully."));

    setAboutData(about);

    setlocale(LC_COLLATE, "C");

    KGlobal::locale()->insertCatalogue("kcmbackground");

    QStringList sl;
    QMap< gid_t, QStringList > tgmap;
    QMap< gid_t, QStringList >::Iterator tgmapi;
    QMap< gid_t, QStringList >::ConstIterator tgmapci;
    QMap< QString, QPair< int, QStringList > >::Iterator umapi;

    struct passwd *ps;
    for(setpwent(); (ps = getpwent());)
    {
        QString un(QFile::decodeName(ps->pw_name));
        if(usermap.find(un) == usermap.end())
        {
            usermap.insert(un, QPair< int, QStringList >(ps->pw_uid, sl));
            if((tgmapi = tgmap.find(ps->pw_gid)) != tgmap.end())
                (*tgmapi).append(un);
            else
                tgmap[ps->pw_gid] = un;
        }
    }
    endpwent();

    struct group *grp;
    for(setgrent(); (grp = getgrent());)
    {
        QString gn(QFile::decodeName(grp->gr_name));
        bool delme = false;
        if((tgmapi = tgmap.find(grp->gr_gid)) != tgmap.end())
        {
            if((*tgmapi).count() == 1 && (*tgmapi).first() == gn)
                delme = true;
            else
                for(QStringList::ConstIterator it = (*tgmapi).begin(); it != (*tgmapi).end(); ++it)
                    usermap[*it].second.append(gn);
            tgmap.remove(tgmapi);
        }
        if(!*grp->gr_mem || (delme && !grp->gr_mem[1] && gn == QFile::decodeName(*grp->gr_mem)))
            continue;
        do
        {
            QString un(QFile::decodeName(*grp->gr_mem));
            if((umapi = usermap.find(un)) != usermap.end())
            {
                if((*umapi).second.find(gn) == (*umapi).second.end())
                    (*umapi).second.append(gn);
            }
            else
                kdWarning() << "group '" << gn << "' contains unknown user '" << un << "'" << endl;
        } while(*++grp->gr_mem);
    }
    endgrent();

    for(tgmapci = tgmap.begin(); tgmapci != tgmap.end(); ++tgmapci)
        kdWarning() << "user(s) '" << tgmapci.data().join(",") << "' have unknown GID " << tgmapci.key() << endl;

    config = new KSimpleConfig(QString::fromLatin1(KDE_CONFDIR "/kdm/kdmrc"));

    QVBoxLayout *top = new QVBoxLayout(this);
    tab = new QTabWidget(this);

//.........这里部分代码省略.........
开发者ID:serghei,项目名称:kde3-kdebase,代码行数:101,代码来源:main.cpp

示例2: getperms

void
getperms (struct io_f *io, char *name)
{
  static uid_t notes;
  static short notes_is_set = FALSE;

  int permissions = 0;
  int matches = 0;
  int perfectmatch = 0;
  int ngroups = 0;        /* Actual number of groups the user belongs to. */
  GETGROUPS_T *gid;
  char **gname;
  struct flock alock;
  struct group *gr;
  char *filename;
  size_t length;
  int fid;
  struct perm_f entry;

  if (io == NULL || name == NULL)
    return;

  /* Notes is God.  If you're the notes user, you get all privs. */

  if (!notes_is_set)
    {
      struct passwd *pw = getpwnam (NOTES);

      notes = pw->pw_uid;
      notes_is_set = TRUE;
      endpwent ();
    }

  if (euid == notes)
    {
      io->access = READOK + RESPOK + WRITOK + DRCTOK;
      return;
    }

  /* Iterate through all the groups this user belongs to and grab the names.
   * If it doesn't work, we don't really care too much, because we can still
   * get a result.
   */

  ngroups = sysconf (_SC_NGROUPS_MAX);
  gid = newts_nmalloc (sizeof (GETGROUPS_T), ngroups);
  gname = newts_nmalloc (sizeof (char *), ngroups);

  if ((ngroups = getgroups (ngroups, gid)) >= 0)
    {
      register int i, j;

      for (i = 0, j = 0; i < ngroups; i++)
        {
          if ((gr = getgrgid (gid[i])) == NULL)
            {
              continue;   /* Bogus group, skip it and move on. */
            }
          gname[j++] = newts_strdup (gr->gr_name);
        }
      ngroups = j;
    }

  io->access = 0;         /* Clear the official list. */

  length = strlen (io->basedir) + strlen (io->nf) + strlen (ACCESS) + 3;
  filename = newts_nmalloc (sizeof (char), length);
  snprintf (filename, length, "%s/%s/%s", io->basedir, io->nf, ACCESS);

  fid = TEMP_FAILURE_RETRY (open (filename, O_RDONLY));

  alock.l_type = F_RDLCK;
  alock.l_whence = SEEK_SET;
  alock.l_start = 0;
  alock.l_len = 0;    /* All of it. */
  TEMP_FAILURE_RETRY (fcntl (fid, F_SETLKW, &alock));

  while ((TEMP_FAILURE_RETRY (read (fid, &entry, sizeof (struct perm_f))) ==
          sizeof (struct perm_f)) && !perfectmatch)
    {
      /* We're not dealing with system permissions yet. */

      if (entry.ptype == PERMSYSTEM)
        continue;

      /* In the actual UIUC notes distribution, "other" was capitalized.  We
       * use strcasecmp just to be sure.
       */

      if (strcasecmp (entry.name, "other") == 0)
        {
          if (matches == 0)
            {
              permissions = entry.perms;
              matches++;
            }
        }

      switch (entry.ptype)
        {
//.........这里部分代码省略.........
开发者ID:tylerberry,项目名称:newts,代码行数:101,代码来源:access.c

示例3: read_mtree

fsnode *
read_mtree(const char *fname, fsnode *node)
{
	struct mtree_fileinfo *fi;
	FILE *fp;
	int c, error;

	/* We do not yet support nesting... */
	assert(node == NULL);

	if (strcmp(fname, "-") == 0)
		fp = stdin;
	else {
		fp = fopen(fname, "r");
		if (fp == NULL)
			err(1, "Can't open `%s'", fname);
	}

	error = mtree_file_push(fname, fp);
	if (error)
		goto out;

	bzero(&mtree_global, sizeof(mtree_global));
	bzero(&mtree_global_inode, sizeof(mtree_global_inode));
	mtree_global.inode = &mtree_global_inode;
	mtree_global_inode.nlink = 1;
	mtree_global_inode.st.st_nlink = 1;
	mtree_global_inode.st.st_atime = mtree_global_inode.st.st_ctime =
	    mtree_global_inode.st.st_mtime = time(NULL);
	errors = warnings = 0;

	setgroupent(1);
	setpassent(1);

	mtree_root = node;
	mtree_current = node;
	do {
		/* Start of a new line... */
		fi = SLIST_FIRST(&mtree_fileinfo);
		fi->line++;

		error = skip_over(fp, " \t");
		if (error)
			break;

		c = getc(fp);
		if (c == EOF) {
			error = ferror(fp) ? errno : -1;
			break;
		}

		switch (c) {
		case '\n':		/* empty line */
			error = 0;
			break;
		case '#':		/* comment -- skip to end of line. */
			error = skip_to(fp, "\n");
			if (!error)
				(void)getc(fp);
			break;
		case '/':		/* special commands */
			error = read_mtree_command(fp);
			break;
		default:		/* specification */
			ungetc(c, fp);
			error = read_mtree_spec(fp);
			break;
		}
	} while (!error);

	endpwent();
	endgrent();

	if (error <= 0 && (errors || warnings)) {
		warnx("%u error(s) and %u warning(s) in mtree manifest",
		    errors, warnings);
		if (errors)
			exit(1);
	}

 out:
	if (error > 0)
		errc(1, error, "Error reading mtree file");

	if (fp != stdin)
		fclose(fp);

	if (mtree_root != NULL)
		return (mtree_root);

	/* Handle empty specifications. */
	node = create_node(".", S_IFDIR, NULL, &mtree_global);
	node->first = node;
	return (node);
}
开发者ID:littlepretty,项目名称:MyBSDReading,代码行数:95,代码来源:mtree.c

示例4: init_chown

static Dlg_head *
init_chown (void)
{
    int i;
    struct passwd *l_pass;
    struct group *l_grp;
    Dlg_head *ch_dlg;

    do_refresh ();
    end_chown = need_update = current_file = 0;
    single_set = (current_panel->marked < 2) ? 3 : 0;

    ch_dlg =
        create_dlg (TRUE, 0, 0, 18, 74, dialog_colors, chown_callback, "[Chown]",
                    _("Chown command"), DLG_CENTER | DLG_REVERSE);

    for (i = 0; i < BUTTONS - single_set; i++)
        add_widget (ch_dlg,
                    button_new (BY + chown_but[i].y, BX + chown_but[i].x,
                                chown_but[i].ret_cmd, chown_but[i].flags, _(chown_but[i].text), 0));

    /* Add the widgets for the file information */
    for (i = 0; i < LABELS; i++)
    {
        chown_label[i].l = label_new (chown_label[i].y, chown_label[i].x, "");
        add_widget (ch_dlg, chown_label[i].l);
    }

    /* get new listboxes */
    l_user = listbox_new (UY + 1, UX + 1, 10, 19, FALSE, NULL);
    l_group = listbox_new (GY + 1, GX + 1, 10, 19, FALSE, NULL);

    /* add fields for unknown names (numbers) */
    listbox_add_item (l_user, LISTBOX_APPEND_AT_END, 0, _("<Unknown user>"), NULL);
    listbox_add_item (l_group, LISTBOX_APPEND_AT_END, 0, _("<Unknown group>"), NULL);

    /* get and put user names in the listbox */
    setpwent ();
    while ((l_pass = getpwent ()) != NULL)
    {
        listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL);
    }
    endpwent ();

    /* get and put group names in the listbox */
    setgrent ();
    while ((l_grp = getgrent ()) != NULL)
    {
        listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL);
    }
    endgrent ();

    add_widget (ch_dlg, groupbox_new (TY, TX, 12, 19, _("File")));

    /* add listboxes to the dialogs */
    add_widget (ch_dlg, l_group);
    add_widget (ch_dlg, groupbox_new (GY, GX, 12, 21, _("Group name")));
    add_widget (ch_dlg, l_user);
    add_widget (ch_dlg, groupbox_new (UY, UX, 12, 21, _("User name")));

    return ch_dlg;
}
开发者ID:ilia-maslakov,项目名称:mc,代码行数:62,代码来源:chown.c

示例5: main


//.........这里部分代码省略.........
	    setreuid(geteuid(),pwd->pw_uid);
	    kerror = krb_get_pw_in_tkt(pwd->pw_name, "", realm,
				       "krbtgt", realm, DEFAULT_TKT_LIFE, pp);
	    setuid(0);
	    if (kerror == INTK_OK) {
		memset(pp, 0, strlen(pp));
		notickets = 0;	/* user got ticket */
		break;
	    }
	}
#  endif /* KERBEROS */
	memset(pp, 0, strlen(pp));

	if (pwd && !strcmp(p, pwd->pw_passwd))
	  break;
	
	printf(_("Login incorrect\n"));
	badlogin(username); /* log ALL bad logins */
	failures++;
	
	/* we allow 10 tries, but after 3 we start backing off */
	if (++cnt > 3) {
	    if (cnt >= 10) {
		sleepexit(1);
	    }
	    sleep((unsigned int)((cnt - 3) * 5));
	}
    }
#endif /* !HAVE_SECURITY_PAM_MISC_H */
    
    /* committed to login -- turn off timeout */
    alarm((unsigned int)0);
    
    endpwent();
    
    /* This requires some explanation: As root we may not be able to
       read the directory of the user if it is on an NFS mounted
       filesystem. We temporarily set our effective uid to the user-uid
       making sure that we keep root privs. in the real uid. 
       
       A portable solution would require a fork(), but we rely on Linux
       having the BSD setreuid() */
    
    {
	char tmpstr[MAXPATHLEN];
	uid_t ruid = getuid();
	gid_t egid = getegid();

	/* avoid snprintf - old systems do not have it, or worse,
	   have a libc in which snprintf is the same as sprintf */
	if (strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2 > MAXPATHLEN)
		quietlog = 0;
	else {
		sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN);
		setregid(-1, pwd->pw_gid);
		setreuid(0, pwd->pw_uid);
		quietlog = (access(tmpstr, R_OK) == 0);
		setuid(0); /* setreuid doesn't do it alone! */
		setreuid(ruid, 0);
		setregid(-1, egid);
	}
    }
    
    /* for linux, write entries in utmp and wtmp */
    {
	struct utmp ut;
开发者ID:Claruarius,项目名称:stblinux-2.6.37,代码行数:67,代码来源:login.c

示例6: do_test

int
do_test (void)
{
    /* Count the number of entries in the password database, and fetch
       data from the first and last entries.  */
    size_t count = 0;
    struct passwd * pw;
    char *first_name = NULL;
    uid_t first_uid = 0;
    char *last_name = NULL;
    uid_t last_uid = 0;
    setpwent ();
    while ((pw  = getpwent ()) != NULL)
    {
        if (first_name == NULL)
        {
            first_name = strdup (pw->pw_name);
            if (first_name == NULL)
            {
                printf ("strdup: %m\n");
                return 1;
            }
            first_uid = pw->pw_uid;
        }

        free (last_name);
        last_name = strdup (pw->pw_name);
        if (last_name == NULL)
        {
            printf ("strdup: %m\n");
            return 1;
        }
        last_uid = pw->pw_uid;
        ++count;
    }
    endpwent ();

    if (count == 0)
    {
        printf ("No entries in the password database.\n");
        return 0;
    }

    /* Try again, this time interleaving with name-based and UID-based
       lookup operations.  The counts do not match if the interleaved
       lookups affected the enumeration.  */
    size_t new_count = 0;
    setpwent ();
    while ((pw  = getpwent ()) != NULL)
    {
        if (new_count == count)
        {
            printf ("Additional entry in the password database.\n");
            return 1;
        }
        ++new_count;
        struct passwd *pw2 = getpwnam (first_name);
        if (pw2 == NULL)
        {
            printf ("getpwnam (%s) failed: %m\n", first_name);
            return 1;
        }
        pw2 = getpwnam (last_name);
        if (pw2 == NULL)
        {
            printf ("getpwnam (%s) failed: %m\n", last_name);
            return 1;
        }
        pw2 = getpwuid (first_uid);
        if (pw2 == NULL)
        {
            printf ("getpwuid (%llu) failed: %m\n",
                    (unsigned long long) first_uid);
            return 1;
        }
        pw2 = getpwuid (last_uid);
        if (pw2 == NULL)
        {
            printf ("getpwuid (%llu) failed: %m\n",
                    (unsigned long long) last_uid);
            return 1;
        }
    }
    endpwent ();
    if (new_count < count)
    {
        printf ("Missing entry in the password database.\n");
        return 1;
    }

    return 0;
}
开发者ID:JamesLinus,项目名称:glibc-mips,代码行数:92,代码来源:tst-nss-getpwent.c

示例7: main


//.........这里部分代码省略.........
		sleepexit(EXIT_FAILURE);
	}

	pwd = cxt.pwd;
	cxt.username = pwd->pw_name;

	/*
	 * Initialize the supplementary group list. This should be done before
	 * pam_setcred because the PAM modules might add groups during
	 * pam_setcred.
	 *
         * For root we don't call initgroups, instead we call setgroups with
	 * group 0. This avoids the need to step through the whole group file,
	 * which can cause problems if NIS, NIS+, LDAP or something similar
	 * is used and the machine has network problems.
	 */
	retcode = pwd->pw_uid ? initgroups(cxt.username, pwd->pw_gid) :	/* user */
			        setgroups(0, NULL);			/* root */
	if (retcode < 0) {
		syslog(LOG_ERR, _("groups initialization failed: %m"));
		warnx(_("\nSession setup problem, abort."));
		pam_end(cxt.pamh, PAM_SYSTEM_ERR);
		sleepexit(EXIT_FAILURE);
	}

	/*
	 * Open PAM session (after successful authentication and account check)
	 */
	loginpam_session(&cxt);

	/* committed to login -- turn off timeout */
	alarm((unsigned int)0);

	endpwent();

	cxt.quiet = get_hushlogin_status(pwd);

	log_utmp(&cxt);
	log_audit(&cxt, 1);
	log_lastlog(&cxt);

	chown_tty(&cxt);

	if (setgid(pwd->pw_gid) < 0 && pwd->pw_gid) {
		syslog(LOG_ALERT, _("setgid() failed"));
		exit(EXIT_FAILURE);
	}

	if (pwd->pw_shell == NULL || *pwd->pw_shell == '\0')
		pwd->pw_shell = _PATH_BSHELL;

	init_environ(&cxt);		/* init $HOME, $TERM ... */

	setproctitle("login", cxt.username);

	log_syslog(&cxt);

	if (!cxt.quiet) {
		motd();

#ifdef LOGIN_STAT_MAIL
		/*
		 * This turns out to be a bad idea: when the mail spool
		 * is NFS mounted, and the NFS connection hangs, the
		 * login hangs, even root cannot login.
		 * Checking for mail should be done from the shell.
开发者ID:bdwalton,项目名称:util-linux,代码行数:67,代码来源:login.c

示例8: main


//.........这里部分代码省略.........
			 * Not hacluster either.
			 * TODO: log this to syslog, to alert sysadmin
			 * of potential nefarious local user.
			 */
			die("ERROR: Permission denied\n");
		}
	}

	/* See who we're trying to become... */
	pwd = getpwnam(argv[1]);
	if (pwd == NULL) {
		die("ERROR: User '%s' not found\n", argv[1]);
	}

	/*
	 * Don't become root!
	 * (Is there really any sense checking for pw_name == "root"?
	 */
	if (pwd->pw_uid == 0 || strcmp(pwd->pw_name, "root") == 0) {
		die("ERROR: Thou shalt not become root\n");
	}

	/* Make sure the new user is in the haclient group */
	grp = getgrgid(pwd->pw_gid);
	if (grp == NULL) {
		die("ERROR: Can't determine group for user '%s'\n", pwd->pw_name);
	}
	if (strcmp(grp->gr_name, HACLIENT) != 0) {
		/* Not the primary group, let's check the others */
		grp = getgrnam(HACLIENT);
		if (grp == NULL) {
			die("ERROR: Group '%s' does not exist\n", HACLIENT);
		}
		i = 0;
		found = 0;
		while ((grp_user = grp->gr_mem[i]) != NULL) {
			if (strcmp(grp_user, pwd->pw_name) == 0) {
				found = 1;
				break;
			}
			i++;
		}
		if (!found) {
			die("ERROR: User '%s' is not in the '%s' group\n", pwd->pw_name, HACLIENT);
		}
	}

	/* Verify the command to execute is valid, and expand it */
	found = 0;
	for (cmd = commands; cmd->name != NULL; cmd++) {
		if (strcmp(cmd->name, argv[2]) == 0) {
			found = 1;
			break;
		}
	}
	if (!found) {
		die("ERROR: Invalid command '%s'\n", argv[2]);
	}
	/* (bit rough to drop const...) */
	argv[2] = (char *)cmd->path;

	/*
	 * Become the new user.  Note that at this point, grp still refers
	 * to the "haclient" group, either because that was the user's
	 * primary group, or because we looked that group up to search
	 * through its members.  Likewise pwd still refers to the user
	 * we're trying to become.
	 */
	if (setresgid(grp->gr_gid, grp->gr_gid, grp->gr_gid) != 0) {
		die("ERROR: Can't set group to '%s' (%d)\n", grp->gr_name, grp->gr_gid);
	}
	if (setresuid(pwd->pw_uid, pwd->pw_uid, pwd->pw_uid) != 0) {
		die("ERROR: Can't set user to '%s' (%d)\n", pwd->pw_name, pwd->pw_uid);
	}

	/*
	 * Bit of cleanup - is this in the right place, and is it really
	 * necessary?
	 */
	endpwent();
	endgrent();

	/* Clean up environment */
	home = getenv("HOME");
	if (home != NULL) {
		home = strdup(home);
	}
	if (clearenv() != 0) {
		die("ERROR: Can't clear environment");
	}
	setenv("PATH", SBINDIR":"BINDIR":/bin", 1);
	if (home != NULL) {
		setenv("HOME", home, 1);
	}

	/* And away we go... */
	execv(argv[2], &argv[2]);
	perror(argv[2]);
	return 1;
}
开发者ID:dizopsin,项目名称:deb-hawk,代码行数:101,代码来源:hawk_invoke.c

示例9: QAbstractListModel

    UserModel::UserModel(QObject *parent) : QAbstractListModel(parent), d(new UserModelPrivate()) {
        const QString facesDir = mainConfig.Theme.FacesDir.get();
        const QString defaultFace = QStringLiteral("file://%1/.face.icon").arg(facesDir);

        struct passwd *current_pw;
        while ((current_pw = getpwent()) != nullptr) {

            // skip entries with uids smaller than minimum uid
            if (int(current_pw->pw_uid) < mainConfig.Users.MinimumUid.get())
                continue;

            // skip entries with uids greater than maximum uid
            if (int(current_pw->pw_uid) > mainConfig.Users.MaximumUid.get())
                continue;
            // skip entries with user names in the hide users list
            if (mainConfig.Users.HideUsers.get().contains(QString::fromLocal8Bit(current_pw->pw_name)))
                continue;

            // skip entries with shells in the hide shells list
            if (mainConfig.Users.HideShells.get().contains(QString::fromLocal8Bit(current_pw->pw_shell)))
                continue;

            // skip duplicates
            // Note: getpwent() makes no attempt to suppress duplicate information
            // if multiple sources are specified in nsswitch.conf(5).
            if (d->users.cend()
                != std::find_if(d->users.cbegin(), d->users.cend(), [current_pw](const UserPtr & u) { return u->uid == current_pw->pw_uid; }))
                continue;

            // create user
            UserPtr user { new User() };
            user->name = QString::fromLocal8Bit(current_pw->pw_name);
            user->realName = QString::fromLocal8Bit(current_pw->pw_gecos).split(QLatin1Char(',')).first();
            user->homeDir = QString::fromLocal8Bit(current_pw->pw_dir);
            user->uid = int(current_pw->pw_uid);
            user->gid = int(current_pw->pw_gid);
            // if shadow is used pw_passwd will be 'x' nevertheless, so this
            // will always be true
            user->needsPassword = strcmp(current_pw->pw_passwd, "") != 0;

            // search for face icon
            user->icon = defaultFace;

            // add user
            d->users << user;
        }

        endpwent();

        // sort users by username
        std::sort(d->users.begin(), d->users.end(), [&](const UserPtr &u1, const UserPtr &u2) { return u1->name < u2->name; });

        bool avatarsEnabled = mainConfig.Theme.EnableAvatars.get();
        if (avatarsEnabled && mainConfig.Theme.EnableAvatars.isDefault()) {
            if (d->users.count() > mainConfig.Theme.DisableAvatarsThreshold.get()) avatarsEnabled=false;
        }

        // find out index of the last user
        for (int i = 0; i < d->users.size(); ++i) {
            UserPtr user { d->users.at(i) };
            if (user->name == stateConfig.Last.User.get())
                d->lastIndex = i;

            if (avatarsEnabled) {
                const QString userFace = QStringLiteral("%1/.face.icon").arg(user->homeDir);
                const QString systemFace = QStringLiteral("%1/%2.face.icon").arg(facesDir).arg(user->name);

                if (QFile::exists(userFace))
                    user->icon = QStringLiteral("file://%1").arg(userFace);
                else if (QFile::exists(systemFace))
                    user->icon = QStringLiteral("file://%1").arg(systemFace);
            }
        }
    }
开发者ID:MartinBriza,项目名称:sddm,代码行数:74,代码来源:UserModel.cpp

示例10: usr_add

int
usr_add(char *str)
{
	u_int indx;
	USRT *pt;
	struct passwd *pw;
	uid_t uid;

	/*
	 * create the table if it doesn't exist
	 */
	if ((str == NULL) || (*str == '\0'))
		return(-1);
	if ((usrtb == NULL) &&
	    ((usrtb = calloc(USR_TB_SZ, sizeof(USRT *))) == NULL)) {
		paxwarn(1, "Unable to allocate memory for user selection table");
		return(-1);
	}

	/*
	 * figure out user spec
	 */
	if (str[0] != '#') {
		/*
		 * it is a user name, \# escapes # as first char in user name
		 */
		if ((str[0] == '\\') && (str[1] == '#'))
			++str;
		if ((pw = getpwnam(str)) == NULL) {
			paxwarn(1, "Unable to find uid for user: %s", str);
			return(-1);
		}
		uid = (uid_t)pw->pw_uid;
	} else
		uid = (uid_t)strtoul(str+1, NULL, 10);
	endpwent();

	/*
	 * hash it and go down the hash chain (if any) looking for it
	 */
	indx = ((unsigned)uid) % USR_TB_SZ;
	if ((pt = usrtb[indx]) != NULL) {
		while (pt != NULL) {
			if (pt->uid == uid)
				return(0);
			pt = pt->fow;
		}
	}

	/*
	 * uid is not yet in the table, add it to the front of the chain
	 */
	if ((pt = malloc(sizeof(USRT))) != NULL) {
		pt->uid = uid;
		pt->fow = usrtb[indx];
		usrtb[indx] = pt;
		return(0);
	}
	paxwarn(1, "User selection table out of memory");
	return(-1);
}
开发者ID:a565109863,项目名称:src,代码行数:61,代码来源:sel_subs.c

示例11: init_chown

static WDialog *
init_chown (void)
{
    int lines, cols;
    int i;
    int y;
    struct passwd *l_pass;
    struct group *l_grp;
    WDialog *ch_dlg;

    do_refresh ();

    end_chown = need_update = current_file = 0;
    single_set = (current_panel->marked < 2) ? 3 : 0;

    cols = GW * 3 + 2 + 6;
    lines = GH + 4 + (single_set ? 2 : 4);

    ch_dlg =
        dlg_create (TRUE, 0, 0, lines, cols, dialog_colors, chown_callback, NULL, "[Chown]",
                    _("Chown command"), DLG_CENTER);

    add_widget (ch_dlg, groupbox_new (2, 3, GH, GW, _("User name")));
    l_user = listbox_new (3, 4, GH - 2, GW - 2, FALSE, NULL);
    add_widget (ch_dlg, l_user);
    /* add field for unknown names (numbers) */
    listbox_add_item (l_user, LISTBOX_APPEND_AT_END, 0, _("<Unknown user>"), NULL);
    /* get and put user names in the listbox */
    setpwent ();
    while ((l_pass = getpwent ()) != NULL)
        listbox_add_item (l_user, LISTBOX_APPEND_SORTED, 0, l_pass->pw_name, NULL);
    endpwent ();

    add_widget (ch_dlg, groupbox_new (2, 4 + GW, GH, GW, _("Group name")));
    l_group = listbox_new (3, 5 + GW, GH - 2, GW - 2, FALSE, NULL);
    add_widget (ch_dlg, l_group);
    /* add field for unknown names (numbers) */
    listbox_add_item (l_group, LISTBOX_APPEND_AT_END, 0, _("<Unknown group>"), NULL);
    /* get and put group names in the listbox */
    setgrent ();
    while ((l_grp = getgrent ()) != NULL)
        listbox_add_item (l_group, LISTBOX_APPEND_SORTED, 0, l_grp->gr_name, NULL);
    endgrent ();

    add_widget (ch_dlg, groupbox_new (2, 5 + GW * 2, GH, GW, _("File")));
    /* add widgets for the file information */
    for (i = 0; i < LABELS; i++)
    {
        chown_label[i].l = label_new (chown_label[i].y, 7 + GW * 2, "");
        add_widget (ch_dlg, chown_label[i].l);
    }

    if (!single_set)
    {
        int x;

        add_widget (ch_dlg, hline_new (lines - chown_but[0].y - 1, -1, -1));

        y = lines - chown_but[0].y;
        x = (cols - blen) / 2;

        for (i = 0; i < BUTTONS - 2; i++)
        {
            add_widget (ch_dlg,
                        button_new (y, x, chown_but[i].ret_cmd, chown_but[i].flags,
                                    chown_but[i].text, NULL));
            x += chown_but[i].len + 1;
        }
    }

    i = BUTTONS - 2;
    y = lines - chown_but[i].y;
    add_widget (ch_dlg, hline_new (y - 1, -1, -1));
    add_widget (ch_dlg,
                button_new (y, WIDGET (ch_dlg)->cols / 2 - chown_but[i].len, chown_but[i].ret_cmd,
                            chown_but[i].flags, chown_but[i].text, NULL));
    i++;
    add_widget (ch_dlg,
                button_new (y, WIDGET (ch_dlg)->cols / 2 + 1, chown_but[i].ret_cmd,
                            chown_but[i].flags, chown_but[i].text, NULL));

    /* select first listbox */
    dlg_select_widget (l_user);

    return ch_dlg;
}
开发者ID:ginggs,项目名称:maemo-mc,代码行数:86,代码来源:chown.c

示例12: assoc_ind

static int assoc_ind( struct tdu_user *usr, struct tdu_param *par)
{
	struct eft * eft = usr->priv;
	unsigned char calling[TDU_PLEN_ADDR+1]="", udata[TDU_PLEN_UDATA+1]="",
		*user="", *pass="";
	struct tdu_assoc_param *respar=par->res.assoc, *inpar=par->par.assoc;

	par->other_reason[0] = 0;
	par->other_reason[1] = 0;

	/*
	 * the tdu layer checks that the maximum udata len is not exceeded,
	 * which should prevent overflow attacks here.
	 */
	tdu_mk_printable(udata, inpar->udata, inpar->udata_len);
	tdu_mk_printable(calling, inpar->calling_addr, inpar->calling_len);

	tdu_printf(TDU_LOG_TRC," assoc_ind, ident_len=%d\n",inpar->ident_len);

	eft_set_flags(eft,eft_get_flags(eft)|EFT_FLAG_STRICT_TREE);

	if( inpar->ident_len > 0 ){
 		user = inpar->ident;
		/* Prevent possible buffer overflows by string functions
		 * depending on zero termination.
		 * The struct tdu_assoc_param contains space for adding
		 * an extra delimiting \0 charater.
		 * Be also careful with missing pass here
		 */
		user[inpar->ident_len]=0;
		pass = user;
		while( pass-user < inpar->ident_len ){
			if(*pass == '/'){
				*pass = 0;
				pass++;
				break;
			}
			pass++;
		};
		tdu_printf(TDU_LOG_AP1,"IND: ASSOC  id=%s calling=%s udata=%s\n",user,calling,udata ); 
		/* 
		 * A leading '+' is used to indicate that the server shall
		 * apply the case-insensitiveness or other compatibility
		 * hacks for transfer names.
		 * The '+' is not part of the user id, thus stripping it.
		 */
		if( user[0] == '+' ){
			long flags;
			user++;

			flags = eft_get_flags(eft);
			eft_set_flags(eft,flags|EFT_FLAG_CASEFIX_TN|
				      EFT_FLAG_CASEFIX_FS|EFT_FLAG_SLASHFIX);
		}
		/* 20.11.98, [email protected]: mapping to user eft_map_to_user, if 	  failed 
		 *
		 * Slightly modified and moved here (1999-01-07) -- HE:
		 *
		 * Now mapping to default user only if user is not in
		 * passwd database.
		 *
		 * FIXME:
		 * This check might be inappropriate if other authentication
		 * methods (not based on /etc/passwd) are used.
		 */
		
		if (eft_map_to_user) {
			struct passwd *pw;
			/*
			 */
			setpwent();
			while( (pw=getpwent()) ){
				if( strcmp(user,pw->pw_name) == 0) break;
			};
			endpwent();
			
			if( ! pw ){
				/* user is unknown (not in /etc/passwd).*/
				tdu_printf(TDU_LOG_LOG, "user %s not known, trying alternate authentication as user \"%s\" instead\n",
					   user, eft_map_to_user);
				user = eft_map_to_user;
				pass = "";
			}
		}

		strcpy(eft->user_name,user);
		par->reason = eft->check_user(eft,user,pass,eft_peer_phone(eft));
	} else {
		strcpy(eft->user_name,"(empty)");
		tdu_printf(TDU_LOG_AP1,"IND: ASSOC  with empty id" 
			   " calling=%s udata=%s\n", calling, udata ); 
		par->reason = eft->check_user(eft,"","",eft_peer_phone(eft));
	}
	
	respar->resp_timeout = 15;
	respar->called_len = LIMIT(strlen(eft->address), TDU_PLEN_ADDR);
	memcpy( respar->called_addr, eft->address, respar->called_len);

	if(! eft_signature ){
		respar->udata_len = -1;
//.........这里部分代码省略.........
开发者ID:marschap,项目名称:isdn4k-utils,代码行数:101,代码来源:eft_server.c

示例13: uim_helper_get_pathname

uim_bool
uim_helper_get_pathname(char *helper_path, int len)
{
  struct passwd *pw;
  char *runtimedir;

  if (len <= 0)
    return UIM_FALSE;

  if (UIM_CATCH_ERROR_BEGIN())
    return UIM_FALSE;

  runtimedir = getenv("XDG_RUNTIME_DIR");
  if (runtimedir && runtimedir[0]) {
    if (strlcpy(helper_path, runtimedir, len) >= (size_t)len)
      goto path_error;
    if (strlcat(helper_path, "/uim", len) >= (size_t)len)
      goto path_error;
  } else {
    pw = getpwuid(getuid());
    if (!pw) {
      endpwent();
      goto path_error;
    }

    if (strlcpy(helper_path, pw->pw_dir, len) >= (size_t)len) {
      endpwent();
      goto path_error;
    }
    if (strlcat(helper_path, "/.uim.d", len) >= (size_t)len) {
      endpwent();
      goto path_error;
    }
    endpwent();
  }

  /* check $XDG_RUNTIME_DIR/uim/ if $XDG_RUNTIME_DIR is available.
   * otherwise ~/.uim.d/
   */
  if (!check_dir(helper_path))
    goto path_error;

  /* check $XDG_RUNTIME_DIR/uim/socket/ if $XDG_RUNTIME_DIR is available.
   * otherwise ~/.uim.d/socket/
   */
  if (strlcat(helper_path, "/socket", len) >= (size_t)len)
    goto path_error;

  if (!check_dir(helper_path))
    goto path_error;

  if (strlcat(helper_path, "/uim-helper", len) >= (size_t)len)
    goto path_error;

  UIM_CATCH_ERROR_END();

  return UIM_TRUE;

 path_error:
#if USE_UIM_NOTIFY && !UIM_NON_LIBUIM_PROG
  uim_notify_fatal("uim_helper_get_pathname() failed");
#else
  fprintf(stderr, "uim_helper_get_pathname() failed\n");
#endif
  helper_path[0] = '\0';

  UIM_CATCH_ERROR_END();
  return UIM_FALSE;
}
开发者ID:TheSLinux-forks,项目名称:uim,代码行数:69,代码来源:uim-helper.c

示例14: smb_ctx_init

/*
 * Prescan command line for [-U user] argument
 * and fill context with defaults
 */
int
smb_ctx_init(struct smb_ctx *ctx, int argc, char *argv[],
	int minlevel, int maxlevel, int sharetype)
{
	int  opt, error = 0;
	uid_t euid;
	const char *arg, *cp;
	struct passwd *pwd;

	bzero(ctx,sizeof(*ctx));
	error = nb_ctx_create(&ctx->ct_nb);
	if (error)
		return error;
	ctx->ct_fd = -1;
	ctx->ct_parsedlevel = SMBL_NONE;
	ctx->ct_minlevel = minlevel;
	ctx->ct_maxlevel = maxlevel;

	ctx->ct_ssn.ioc_opt = SMBVOPT_CREATE;
	ctx->ct_ssn.ioc_timeout = 15;
	ctx->ct_ssn.ioc_retrycount = 4;
	ctx->ct_ssn.ioc_owner = SMBM_ANY_OWNER;
	ctx->ct_ssn.ioc_group = SMBM_ANY_GROUP;
	ctx->ct_ssn.ioc_mode = SMBM_EXEC;
	ctx->ct_ssn.ioc_rights = SMBM_DEFAULT;

	ctx->ct_sh.ioc_opt = SMBVOPT_CREATE;
	ctx->ct_sh.ioc_owner = SMBM_ANY_OWNER;
	ctx->ct_sh.ioc_group = SMBM_ANY_GROUP;
	ctx->ct_sh.ioc_mode = SMBM_EXEC;
	ctx->ct_sh.ioc_rights = SMBM_DEFAULT;
	ctx->ct_sh.ioc_owner = SMBM_ANY_OWNER;
	ctx->ct_sh.ioc_group = SMBM_ANY_GROUP;

	nb_ctx_setscope(ctx->ct_nb, "");
	euid = geteuid();
	if ((pwd = getpwuid(euid)) != NULL) {
		smb_ctx_setuser(ctx, pwd->pw_name);
		endpwent();
	} else if (euid == 0)
		smb_ctx_setuser(ctx, "root");
	else
		return 0;
	if (argv == NULL)
		return 0;
	for (opt = 1; opt < argc; opt++) {
		cp = argv[opt];
		if (strncmp(cp, "//", 2) != 0)
			continue;
		error = smb_ctx_parseunc(ctx, cp, sharetype, (const char**)&cp);
		if (error)
			return error;
		ctx->ct_uncnext = cp;
		break;
	}
	while (error == 0 && (opt = cf_getopt(argc, argv, ":E:L:U:")) != -1) {
		arg = cf_optarg;
		switch (opt) {
		    case 'E':
			error = smb_ctx_setcharset(ctx, arg);
			if (error)
				return error;
			break;
		    case 'L':
			error = nls_setlocale(optarg);
			if (error)
				break;
			break;
		    case 'U':
			error = smb_ctx_setuser(ctx, arg);
			break;
		}
	}
	cf_optind = cf_optreset = 1;
	return error;
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:80,代码来源:ctx.c

示例15: do_test

static int
do_test (void)
{
  int retval = 0;

  __nss_configure_lookup ("passwd", "test1");

  static const unsigned int pwdids[] = { 100, 30, 200, 60, 20000 };
#define npwdids (sizeof (pwdids) / sizeof (pwdids[0]))
  setpwent ();

  const unsigned int *np = pwdids;
  for (struct passwd *p = getpwent (); p != NULL; ++np, p = getpwent ())
    if (p->pw_uid != *np || strncmp (p->pw_name, "name", 4) != 0
	|| atol (p->pw_name + 4) != *np)
      {
	printf ("passwd entry %ju wrong (%s, %u)\n",
		np - pwdids, p->pw_name, p->pw_uid);
	retval = 1;
	break;
      }

  endpwent ();

  for (int i = npwdids - 1; i >= 0; --i)
    {
      char buf[30];
      snprintf (buf, sizeof (buf), "name%u", pwdids[i]);

      struct passwd *p = getpwnam (buf);
      if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
	{
	  printf ("passwd entry \"%s\" wrong\n", buf);
	  retval = 1;
	}

      p = getpwuid (pwdids[i]);
      if (p == NULL || p->pw_uid != pwdids[i] || strcmp (buf, p->pw_name) != 0)
	{
	  printf ("passwd entry %u wrong\n", pwdids[i]);
	  retval = 1;
	}

      snprintf (buf, sizeof (buf), "name%u", pwdids[i] + 1);

      p = getpwnam (buf);
      if (p != NULL)
	{
	  printf ("passwd entry \"%s\" wrong\n", buf);
	  retval = 1;
	}

      p = getpwuid (pwdids[i] + 1);
      if (p != NULL)
	{
	  printf ("passwd entry %u wrong\n", pwdids[i] + 1);
	  retval = 1;
	}
    }

  return retval;
}
开发者ID:AdvancedC,项目名称:glibc,代码行数:62,代码来源:tst-nss-test1.c


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