Beispiel #1
0
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);
}
Beispiel #2
0
Datei: pwd.c Projekt: passick/xv6
struct passwd*
getpwuid(uid_t uid)
{
    setpwent();
    while (getpwent()) {
        if (current_passwd.pw_uid == uid) {
            endpwent();
            return &current_passwd;
        }
    }
    endpwent();
    return 0;
}
Beispiel #3
0
Datei: pwd.c Projekt: passick/xv6
struct passwd*
getpwnam(const char* name)
{
    setpwent();
    while (getpwent()) {
        if (strcmp(name, current_passwd.pw_name) == 0) {
            endpwent();
            return &current_passwd;
        }
    }
    endpwent();
    return 0;
}
Beispiel #4
0
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;
		}
	}
}
Beispiel #5
0
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();
	}
}
Beispiel #6
0
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;
}
Beispiel #7
0
struct passwd *getpwent_base(void)
/*
 * Basic getpwent().
 */
{
	if (!_pw_file) {
		/* open file */
		setpwent();
		if (!_pw_file)
			return (NULL);
	}

	return (fgetpwent_base(_pw_file));
}
Beispiel #8
0
/* 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;
}
Beispiel #9
0
struct passwd *getpwuid_base(uid_t uid)
/*
 * Basic getpwuid(). This locates and returns the unprocessed passwd entry.
 */
{
	struct passwd *	pw;	/* return value */

	setpwent();
	while (((pw = getpwent_base()) != NULL) && (pw->pw_uid != uid))
		;
	endpwent();

	return (pw);
}
Beispiel #10
0
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;
}
Beispiel #11
0
int main(void)
{
    struct passwd *pwd;

    setpwent();

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

    endpwent();

    return 0;
}
Beispiel #12
0
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;
}
Beispiel #13
0
struct passwd *getpwnam_base(const char *name)
/*
 * Basic getpwnam(). This locates and returns the unprocessed passwd entry.
 */
{
	struct passwd *	pw;	/* return value */

	setpwent();
	while (((pw = getpwent_base()) != NULL) && strcmp(pw->pw_name, name))
		;
	endpwent();

	return (pw);
}
Beispiel #14
0
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
}
Beispiel #15
0
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;
}
/**
 * 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);
}
Beispiel #17
0
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;
}
Beispiel #18
0
QList<KUser> KUser::allUsers(uint maxCount)
{
    QList<KUser> result;

    passwd *p;
    setpwent();

    for (uint i = 0; i < maxCount && (p = getpwent()); ++i) {
        result.append(KUser(p));
    }

    endpwent();

    return result;
}
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 */
}
Beispiel #20
0
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();
	}
}
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;
}
Beispiel #22
0
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 ) ) );
}
Beispiel #23
0
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;
}
Beispiel #24
0
static void
_populate_users (Evas_Object *users_list)
{
    struct passwd *pent = NULL;

    setpwent ();
    while ((pent = getpwent ()) != NULL) {
        if (g_strcmp0 ("x", pent->pw_passwd) == 0 &&
                _is_valid_user (pent)) {
            elm_hoversel_item_add(users_list, pent->pw_name, NULL,
                    ELM_ICON_NONE, NULL, NULL);
        }
        pent = NULL;
    }
    endpwent ();
}
Beispiel #25
0
static struct userdb_iterate_context *
passwd_iterate_init(struct auth_request *auth_request,
		    userdb_iter_callback_t *callback, void *context)
{
	struct passwd_userdb_iterate_context *ctx;

	ctx = i_new(struct passwd_userdb_iterate_context, 1);
	ctx->ctx.auth_request = auth_request;
	ctx->ctx.callback = callback;
	ctx->ctx.context = context;
	setpwent();

	if (cur_userdb_iter == NULL)
		cur_userdb_iter = ctx;
	return &ctx->ctx;
}
Beispiel #26
0
int main(int argc, char **argv) {
	struct passwd *pw;
	int id, i, j;
	char **pp;

	for (j=0; j<2; j++) {
		switch (j) {
		case 0:
			printf("printing all entries\n");
			break;
		case 1:
			printf("resetting file pointer\n");
			setpwent();
			break;
		}
		while((pw = getpwent()) != NULL) {
			printf("entry: \"%s\" \"%s\" %u %u\n",
				pw->pw_name, pw->pw_passwd,
				pw->pw_uid, pw->pw_gid);
		}
	}

	if (argc > 1) {
		if (!strcmp(argv[1], WHOAMI)) {
			if ((pw = getpwnam(argv[1])) == NULL) {
				printf("%s not present in database\n",
					argv[1]);
			} else {
				printf("uid for %s is %u\n",
					argv[1], pw->pw_uid);
			}
		} else {
			id = atoi(argv[1]);
			if ((pw = getpwuid(id)) == NULL) {
				printf("uid %u not present in database\n",
					id);
			} else {
				printf("id for %u is %s using shell %s\n",
					id, pw->pw_name, pw->pw_shell ?
					pw->pw_shell : "(null)");
			}
		}
	}                                                 

	endpwent();
	return 0;
}
Beispiel #27
0
// Initialize users garray and fill it with os usernames.
// Return Ok for success, FAIL for failure.
int os_get_usernames(garray_T *users)
{
  if (users == NULL) {
    return FAIL;
  }
  ga_init(users, sizeof(char *), 20);

# if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
  struct passwd *pw;

  setpwent();
  while ((pw = getpwent()) != NULL) {
    // pw->pw_name shouldn't be NULL but just in case...
    if (pw->pw_name != NULL) {
      GA_APPEND(char *, users, xstrdup(pw->pw_name));
    }
  }
Beispiel #28
0
int main(int argc, char *argv[]) {
	struct passwd *pwd;
	int i;

	get_options(argc, argv);

	if (stress == 1) {
		pthread_t thread; 

		for (i = 0; i < num_threads; i++) {
			pthread_create (&thread, NULL, &getpw, NULL); 
		}
		pthread_join (thread, NULL);
	}
	if (user != NULL) {
		pwd = getpwnam (user);
		if (pwd == NULL) {
			printf ("user %s not found\n", user);
		}
		else {
			printf ("user=%s, uid=%u, gid=%u\n", pwd->pw_name, pwd->pw_uid, pwd->pw_gid);
		}
		exit (0);	
	}
	if (uid != 0xffffffff) {
		pwd = getpwuid (uid);
		if (pwd == NULL) {
			printf ("userid %u not found\n", uid);
		}
		else {
			printf ("user=%s, uid=%u, gid=%u\n", pwd->pw_name, pwd->pw_uid, pwd->pw_gid);
		}
		exit (0);	
	}
	else {
		setpwent ();
		while (1) {
			pwd = getpwent();
			if (pwd == NULL) {
				exit (0);
			}
			printf ("user=%s, uid=%u, gid=%u\n", pwd->pw_name, pwd->pw_uid, pwd->pw_gid);
		}
	}
	return (0);
}
Beispiel #29
0
char *
logname()
{
	register struct passwd *pw;
	register char *cp;

	cp = getenv("USER");
	if (cp != 0 && *cp != '\0')
		return (cp);
	cp = getlogin();
	if (cp != 0 && *cp != '\0')
		return (cp);
	setpwent();
	pw=getpwuid(getuid());
	endpwent();
	return(pw->pw_name);
}
Beispiel #30
0
/* pick a valid uid+gid and a valid gid that isn't in its supplementary
 * groups.
 */
static void
pick_user (uid_t *up, gid_t *gp, gid_t *ngp)
{
    gid_t sg[64];
    uid_t uid;
    uid_t gid, ngid = 0;
    int i, nsg = 64;
    struct passwd *pw;
    struct group *gr;
    char *uname;

    setpwent ();
    while ((pw = getpwent ())) {
        if (pw->pw_uid != 0)
            break;
    }
    endpwent ();
    if (!pw)
        msg_exit ("could not select uid");
    uid = pw->pw_uid;
    gid = pw->pw_gid;
    uname = strdup (pw->pw_name);
    if (getgrouplist (uname, gid, sg, &nsg) < 0)
        err_exit ("could not get supplementary groups for %s", uname);

    setgrent ();
    while ((gr = getgrent ())) {
        for (i = 0; i < nsg; i++) {
            if (gr->gr_gid == sg[i])
                break;
        }
        if (i == nsg) {
            ngid = gr->gr_gid;
            break;
        }
    }
    if (gr == NULL)
        msg_exit ("could not select ngid");
    endgrent ();
     
    free (uname); 
    *up = uid;
    *gp = gid;
    *ngp = ngid;
}