1
/* cvm/getpwnam.c - Handles getpwnam+getspnam+getuserpw combinations
2
* Copyright (C) 2001 Bruce Guenter <bruceg@em.ca>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#include "hasuserpw.h"
29
static struct spwd* spw;
34
static struct userpw* uwp;
37
static char* actbuf = 0;
38
static unsigned actlen = 0;
40
static const char* copyact(const char* account)
44
if ((len = strlen(account)) > actlen)
45
if ((actbuf = realloc(actbuf, actlen+1)) == 0) return 0;
46
for (ptr = actbuf; *account != 0; ++ptr, ++account)
47
*ptr = isupper(*account) ? tolower(*account) : *account;
52
int cvm_getpwnam(const char* account, struct passwd** pwp)
56
account = copyact(account);
57
if ((pw = getpwnam(account)) == 0)
58
return (errno == ETXTBSY) ? CVME_IO : CVME_PERMFAIL;
61
if ((upw = getuserpw(account)) == 0) {
62
if (errno == ETXTBSY) return CVME_IO;
64
else if (upw->upw_passwd)
65
pw->pw_passwd = upw->upw_passwd;
69
if ((spw = getspnam(account)) == 0) {
70
if (errno == ETXTBSY) return CVME_IO;
72
else if (spw->sp_pwdp)
73
pw->pw_passwd = spw->sp_pwdp;