Exemple #1
0
struct passwd *fgetpwent(FILE *f)
{
    static char *line = NULL;
    static struct passwd pw = {0};
	size_t size=0;
	return __getpwent_a(f, &pw, &line, &size);
}
Exemple #2
0
struct passwd* getpwent() {
  struct passwd* res;
  if (!f)
    f = fopen("/etc/passwd", "rbe");
  if (!f)
    return 0;
  __getpwent_a(f, &pw, &line, &size, &res);
  return res;
}
Exemple #3
0
struct passwd *getpwent()
{
	static char *line;
	static struct passwd pw;
	size_t size=0;
	if (!f) f = fopen("/etc/passwd", "rbe");
	if (!f) return 0;
	return __getpwent_a(f, &pw, &line, &size);
}
Exemple #4
0
int __getpw_a(const char *name, uid_t uid, struct passwd *pw, char **buf, size_t *size, struct passwd **res)
{
	FILE *f;
	int cs;
	int rv = 0;

	*res = 0;

	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);

	f = fopen("/etc/passwd", "rbe");
	if (!f) {
		rv = errno;
		goto done;
	}

	while (!(rv = __getpwent_a(f, pw, buf, size, res)) && *res) {
		if ((name && !strcmp(name, (*res)->pw_name))
		|| (!name && (*res)->pw_uid == uid))
			break;
	}
	fclose(f);

	if (!*res && (rv == 0 || rv == ENOENT || rv == ENOTDIR)) {
		int32_t req = name ? GETPWBYNAME : GETPWBYUID;
		const char *key;
		int32_t passwdbuf[PW_LEN] = {0};
		size_t len = 0;
		char uidbuf[11] = {0};

		if (name) {
			key = name;
		} else {
			/* uid outside of this range can't be queried with the
			 * nscd interface, but might happen if uid_t ever
			 * happens to be a larger type (this is not true as of
			 * now)
			 */
			if(uid > UINT32_MAX) {
				rv = 0;
				goto done;
			}
			key = itoa(uidbuf, uid);
		}

		f = __nscd_query(req, key, passwdbuf, sizeof passwdbuf, (int[]){0});
Exemple #5
0
static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res)
{
	FILE *f;
	char *line = 0;
	size_t len = 0;
	int rv = 0;
	int cs;

	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);

	f = fopen("/etc/passwd", "rb");
	if (!f) {
		rv = errno;
		goto done;
	}

	*res = 0;
	while (__getpwent_a(f, pw, &line, &len)) {
		if (name && !strcmp(name, pw->pw_name)
		|| !name && pw->pw_uid == uid) {
			if (size < len) {
				rv = ERANGE;
				break;
			}
			*res = pw;
			memcpy(buf, line, len);
			FIX(name);
			FIX(passwd);
			FIX(gecos);
			FIX(dir);
			FIX(shell);
			break;
		}
	}
 	free(line);
	fclose(f);
done:
	pthread_setcancelstate(cs, 0);
	return rv;
}