diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-08-18 14:19:07 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-08-18 14:19:07 +0300 |
commit | 4ceb28836e5231c79da5a936cfe2f5416c9b05e0 (patch) | |
tree | 4354dc2d36bb295d1b5d0c00f3ffe5b7551a9300 | |
parent | 8e25ff1846acd82e522e32dddd7cc298018eca0c (diff) | |
download | mailfromd-4ceb28836e5231c79da5a936cfe2f5416c9b05e0.tar.gz mailfromd-4ceb28836e5231c79da5a936cfe2f5416c9b05e0.tar.bz2 |
Add mfd/bi_getpw.m4
-rw-r--r-- | mfd/bi_getpw.m4 | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/mfd/bi_getpw.m4 b/mfd/bi_getpw.m4 new file mode 100644 index 00000000..1c5ab821 --- /dev/null +++ b/mfd/bi_getpw.m4 @@ -0,0 +1,77 @@ +/* This file is part of Mailfromd. -*- c -*- + Copyright (C) 2009 Sergey Poznyakoff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "inttostr.h" + +static void +return_passwd(eval_environ_t env, struct passwd *pw) +{ + char buf[NUMERIC_BUFSIZE_BOUND]; + + MF_OBSTACK_BEGIN(); + MF_OBSTACK_GROW(pw->pw_name); + MF_OBSTACK_1GROW(':'); + MF_OBSTACK_GROW(pw->pw_passwd); + MF_OBSTACK_1GROW(':'); + MF_OBSTACK_GROW(umaxtostr(pw->pw_uid, buf)); + MF_OBSTACK_1GROW(':'); + MF_OBSTACK_GROW(umaxtostr(pw->pw_gid, buf)); + MF_OBSTACK_1GROW(':'); + MF_OBSTACK_GROW(pw->pw_gecos); + MF_OBSTACK_1GROW(':'); + MF_OBSTACK_GROW(pw->pw_dir); + MF_OBSTACK_1GROW(':'); + MF_OBSTACK_GROW(pw->pw_shell); + MF_OBSTACK_1GROW(0); + MF_RETURN_OBSTACK(); +} + +MF_DEFUN(mappwnam, NUMBER, STRING name) +{ + struct passwd *pw = getpwnam(name); + MF_RETURN(pw != NULL); +} +END + +MF_DEFUN(getpwnam, STRING, STRING name) +{ + struct passwd *pw = getpwnam(name); + MF_ASSERT(pw != NULL, + mfe_not_found, + _("%s: user not found"), name); + return_passwd(env, pw); +} +END + +MF_DEFUN(mappwuid, NUMBER, NUMBER uid) +{ + struct passwd *pw = getpwuid(uid); + MF_RETURN(pw != NULL); +} +END + +MF_DEFUN(getpwuid, STRING, NUMBER uid) +{ + struct passwd *pw = getpwuid(uid); + MF_ASSERT(pw != NULL, + mfe_not_found, + _("%lu: uid not found"), (unsigned long) uid); + return_passwd(env, pw); +} +END + + +MF_INIT |