File auto_uids.c of Package netqmail

/*
 * (C) 2011 Peter Conrad <conrad@quisquis.de>
 *
 * This file is licensed under the terms of the
 * GNU General Public License Version 2. A copy of these terms should be
 * enclosed as "gpl-2.0.txt" in the package containing this file.
 */
#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
#include "qlx.h"

static int have_uida = 0, uida;
static int have_uidd = 0, uidd;
static int have_uidl = 0, uidl;
static int have_uido = 0, uido;
static int have_uidp = 0, uidp;
static int have_uidq = 0, uidq;
static int have_uidr = 0, uidr;
static int have_uids = 0, uids;
static int have_gidq = 0, gidq;
static int have_gidn = 0, gidn;

static int get_auto_uid(const char *uname) {
    struct passwd *pwent = getpwnam(uname);
    if (pwent) { return pwent->pw_uid; }
    _exit(QLX_EXECPW);
}

static int get_auto_gid(const char *gname) {
    struct group *ent = getgrnam(gname);
    if (ent) { return ent->gr_gid; }
    _exit(QLX_EXECPW);
}

#define GET_AUTO_UID(type,name) \
int get_auto_uid##type() { \
    if (!have_uid##type) { \
	uid##type = get_auto_uid(name); \
	have_uid##type = 1; \
    } \
    return uid##type; \
}

GET_AUTO_UID(a, "alias")
GET_AUTO_UID(d, "qmaild")
GET_AUTO_UID(l, "qmaill")
GET_AUTO_UID(o, "root")
GET_AUTO_UID(p, "qmailp")
GET_AUTO_UID(q, "qmailq")
GET_AUTO_UID(r, "qmailr")
GET_AUTO_UID(s, "qmails")

#define GET_AUTO_GID(type,name) \
int get_auto_gid##type() { \
    if (!have_gid##type) { \
	gid##type = get_auto_gid(name); \
	have_gid##type = 1; \
    } \
    return gid##type; \
}

GET_AUTO_GID(n, "nofiles")
GET_AUTO_GID(q, "mail")

#undef GET_AUTO_UID
#undef GET_AUTO_GID

openSUSE Build Service is sponsored by