本文整理汇总了C++中setpwent函数的典型用法代码示例。如果您正苦于以下问题:C++ setpwent函数的具体用法?C++ setpwent怎么用?C++ setpwent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setpwent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 ¤t_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 ¤t_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
示例16: init_chown
static void
init_chown (void)
{
int i;
struct passwd *l_pass;
struct group *l_grp;
do_refresh ();
end_chown = need_update = current_file = 0;
single_set = (cpanel->marked < 2) ? 3 : 0;
ch_dlg = create_dlg (0, 0, 18, 74, dialog_colors, chown_callback,
"[Chown]", "chown", DLG_CENTER);
#define XTRACT(i) BY+chown_but[i].y, BX+chown_but[i].x, chown_but[i].ret_cmd, chown_but[i].flags, _(chown_but[i].text), 0, 0, NULL
for (i = 0; i < BUTTONS-single_set; i++)
add_widget (ch_dlg, button_new (XTRACT (i)));
/* Add the widgets for the file information */
#define LX(i) chown_label [i].y, chown_label [i].x, "", NULL
for (i = 0; i < LABELS; i++){
chown_label [i].l = label_new (LX (i));
add_widget (ch_dlg, chown_label [i].l);
}
/* get new listboxes */
l_user = listbox_new (UY + 1, UX + 1, 19, 10, 0, l_call, NULL);
l_group = listbox_new (GY + 1, GX + 1, 19, 10, 0, l_call, NULL);
listbox_add_item (l_user, 0, 0, _("<Unknown user>"), NULL); /* add fields for unknown names (numbers) */
listbox_add_item (l_group, 0, 0, _("<Unknown group>"), NULL);
setpwent (); /* get and put user names in the listbox */
while ((l_pass = getpwent ())) {
listbox_add_item (l_user, 0, 0, l_pass->pw_name, NULL);
}
endpwent ();
setgrent (); /* get and put group names in the listbox */
while ((l_grp = getgrent ())) {
listbox_add_item (l_group, 0, 0, l_grp->gr_name, NULL);
}
endgrent ();
add_widget (ch_dlg, l_group);
add_widget (ch_dlg, l_user); /* add listboxes to the dialogs */
}
开发者ID:OS2World,项目名称:UTIL-SHELL-Midnight_Commander,代码行数:48,代码来源:chown.c
示例17: 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 = 0;
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) < BUFSIZ) {
char temp2[BUFSIZ]; /* argument size */
/* /home/user/... */
sprintf(temp2, "%s%s", home, ud);
strcpy(sav_ud, temp2);
}
}
} else {
/* "~[^/]*" */
setpwent();
while ((entry = getpwent()) != NULL) {
/* Null usernames should result in all users as possible completions. */
if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) {
add_match(xasprintf("~%s/", entry->pw_name));
}
}
endpwent();
}
}
开发者ID:AlickHill,项目名称:Lantern,代码行数:48,代码来源:cmdedit.c
示例18: pw_dbm_update
int
pw_dbm_update(const struct passwd *pw)
{
datum key;
datum content;
char data[BUFSIZ];
int len;
static int once;
if (! once) {
if (! pw_dbm)
setpwent ();
once++;
}
if (! pw_dbm)
return 0;
len = pw_pack (pw, data);
content.dsize = len;
content.dptr = data;
key.dsize = strlen (pw->pw_name);
key.dptr = pw->pw_name;
if (dbm_store(pw_dbm, key, content, DBM_REPLACE))
return 0;
/*
* XXX - on systems with 16-bit UIDs (such as Linux/x86)
* name "aa" and UID 24929 will give the same key. This
* happens only rarely, but code which only "works most
* of the time" is not good enough...
*
* This needs to be fixed in several places (pwdbm.c,
* grdbm.c, pwent.c, grent.c). Fixing it will cause
* incompatibility with existing dbm files.
*
* Summary: don't use this stuff for now. --marekm
*/
key.dsize = sizeof pw->pw_uid;
key.dptr = (char *) &pw->pw_uid;
if (dbm_store(pw_dbm, key, content, DBM_REPLACE))
return 0;
return 1;
}
开发者ID:TomDataworks,项目名称:smaller-than-busybox,代码行数:48,代码来源:pwdbm.c
示例19: QTreeWidget
KACLListView::KACLListView( QWidget* parent )
: QTreeWidget( parent ),
m_hasMask( false ), m_allowDefaults( false )
{
// Add the columns
setColumnCount( 6 );
QStringList headers;
headers << i18n( "Type" );
headers << i18n( "Name" );
headers << i18nc( "read permission", "r" );
headers << i18nc( "write permission", "w" );
headers << i18nc( "execute permission", "x" );
headers << i18n( "Effective" );
setHeaderLabels( headers );
setSortingEnabled( false );
setSelectionMode( QAbstractItemView::ExtendedSelection );
header()->setResizeMode( QHeaderView::ResizeToContents );
setRootIsDecorated( false );
// Load the avatars
for ( int i=0; i < LAST_IDX; ++i ) {
s_itemAttributes[i].pixmap = new QPixmap( QString::fromLatin1(":/images/%1").arg(s_itemAttributes[i].pixmapName) );
}
m_yesPixmap = new QPixmap( ":/images/yes.png" );
m_yesPartialPixmap = new QPixmap( ":/images/yespartial.png" );
// fill the lists of all legal users and groups
struct passwd *user = 0;
setpwent();
while ( ( user = getpwent() ) != 0 ) {
m_allUsers << QString::fromLatin1( user->pw_name );
}
endpwent();
struct group *gr = 0;
setgrent();
while ( ( gr = getgrent() ) != 0 ) {
m_allGroups << QString::fromLatin1( gr->gr_name );
}
endgrent();
m_allUsers.sort();
m_allGroups.sort();
connect( this, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ),
this, SLOT( slotItemClicked( QTreeWidgetItem*, int ) ) );
}
开发者ID:vasi,项目名称:kdelibs,代码行数:48,代码来源:kacleditwidget.cpp
示例20: setpwent
const char *homedirFromUid(uid_t uid) {
struct passwd *pw;
char *d = 0;
setpwent();
while((pw = getpwent()) != NULL) {
if(pw->pw_uid == uid) {
d = strdup(pw->pw_dir);
endpwent();
return d;
}
}
endpwent();
return d;
}
开发者ID:opieproject,项目名称:opie,代码行数:16,代码来源:runtests.cpp
注:本文中的setpwent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论