66 static const char *dict_unix_getpwnam(
DICT *dict,
const char *key)
70 static int sanity_checked;
83 if ((pwd = getpwnam(key)) == 0) {
84 if (sanity_checked == 0) {
87 if (getpwuid(0) == 0) {
88 msg_warn(
"cannot access UNIX password database: %m");
98 pwd->pw_name, pwd->pw_passwd, (
long) pwd->pw_uid,
99 (
long) pwd->pw_gid, pwd->pw_gecos, pwd->pw_dir,
107 static const char *dict_unix_getgrnam(
DICT *dict,
const char *key)
112 static int sanity_checked;
125 if ((grp = getgrnam(key)) == 0) {
126 if (sanity_checked == 0) {
129 if (getgrgid(0) == 0) {
130 msg_warn(
"cannot access UNIX group database: %m");
140 grp->gr_name, grp->gr_passwd, (
long) grp->gr_gid);
141 for (cpp = grp->gr_mem; *cpp; cpp++) {
153 static void dict_unix_close(
DICT *dict)
165 struct dict_unix_lookup {
167 const char *(*lookup) (
DICT *,
const char *);
169 static struct dict_unix_lookup dict_unix_lookup[] = {
170 "passwd.byname", dict_unix_getpwnam,
171 "group.byname", dict_unix_getgrnam,
174 struct dict_unix_lookup *lp;
179 if (open_flags != O_RDONLY)
181 "%s:%s map requires O_RDONLY access mode",
187 for (lp = dict_unix_lookup; ; lp++) {
191 if (strcmp(map, lp->name) == 0)
void(* close)(struct DICT *)
#define DICT_FLAG_FOLD_FIX
VSTRING * vstring_strcpy(VSTRING *vp, const char *src)
#define VSTRING_TERMINATE(vp)
#define VSTRING_ADDCH(vp, ch)
#define DICT_OWNER_TRUSTED
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
DICT * dict_unix_open(const char *map, int open_flags, int dict_flags)
char * lowercase(char *string)
const char *(* lookup)(struct DICT *, const char *)
VSTRING * vstring_free(VSTRING *vp)
DICT * dict_alloc(const char *, const char *, ssize_t)
VSTRING * vstring_strcat(VSTRING *vp, const char *src)
DICT * dict_surrogate(const char *dict_type, const char *dict_name, int open_flags, int dict_flags, const char *fmt,...)