summaryrefslogtreecommitdiff
path: root/nslcd/hackers_parse.h
blob: 1a092f68a64c943cbb0a2fae3971b9feab0224ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef _HACKERS_PARSE_H
#define _HACKERS_PARSE_H

#include <string.h> /* for memset(3) */
#include <stdlib.h> /* for free(3) */
#include <pwd.h> /* for 'struct passwd' */

#define ZERO(var) memset(&(var), 0, sizeof(var))

/* Free+zero a 'struct passwd' */
#define PASSWD_FREE(user) \
	(__extension__ ({ \
		free((user).pw_name); \
		free((user).pw_passwd); \
		free((user).pw_gecos); \
		free((user).pw_dir); \
		free((user).pw_shell); \
		ZERO(user); \
	}))

/** Returns 0 on error, or the UID on success.  Only handles "normal
 *  user" UIDs; that is in the range [1000,9999]. */
uid_t	filename2uid(const char *filename);

/** Returns 0 on success, < 0 on failure.  Sets
    userp->pw_passwd. */
int	load_user_password(struct passwd *userp);
/** Returns 0 on success, non-zero on failere.
    May set userp->pw_uid even on failure. */
int	load_user_yaml(const char *filename, struct passwd *userp);

#endif