passwd.c revision fcef1231eea30ee9cdc75f3f39f4b9207a84ea1d
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * System Security Services Daemon. NSS client interface
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * Copyright (C) Simo Sorce 2007
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * This program is free software; you can redistribute it and/or modify
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * it under the terms of the GNU Lesser General Public License as
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * published by the Free Software Foundation; either version 2.1 of the
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * License, or (at your option) any later version.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * This program is distributed in the hope that it will be useful,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * GNU Lesser General Public License for more details.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * You should have received a copy of the GNU Lesser General Public
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * License along with this program; if not, write to the Free Software
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/* PASSWD database NSS interface */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic void sss_nss_getpwent_data_clean(void) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen/* GETPWNAM Request:
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 0-X: string with name
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * GERTPWUID Request:
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 0-7: 64bit number with uid
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 0-3: 32bit unsigned number of results
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 4-7: 32bit unsigned (reserved/padding)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * For each result:
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 0-7: 64bit number uid
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 8-15: 64bit number gid
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen * 16-X: sequence of 5, 0 terminated, strings (name, passwd, gecos, dir, shell)
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenstatic int sss_nss_getpw_readrep(struct sss_nss_pw_rep *pr,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen if (*len < 21) { /* not enough space for data, bad packet */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen while (i < slen) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen while (i < slen) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen while (i < slen) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen while (i < slen) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen while (i < slen) {
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen if (pr->buffer[i] != '\0') { /* premature end of buf */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenenum nss_status _nss_sss_getpwnam_r(const char *name, struct passwd *result,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen nret = sss_nss_make_request(SSS_NSS_GETPWNAM, &rd,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* no results if not found */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* only 1 result is accepted for this function */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ret = sss_nss_getpw_readrep(&pwrep, repbuf+8, &len);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenenum nss_status _nss_sss_getpwuid_r(uid_t uid, struct passwd *result,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen nret = sss_nss_make_request(SSS_NSS_GETPWUID, &rd,
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* no results if not found */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* only 1 result is accepted for this function */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen ret = sss_nss_getpw_readrep(&pwrep, repbuf+8, &len);
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainen /* make sure we do not have leftovers, and release memory */
c1252a5812eb11fcb81508b9ed37597a5bc84100Timo Sirainenenum nss_status _nss_sss_getpwent_r(struct passwd *result,
int ret;
if (ret) {
return NSS_STATUS_TRYAGAIN;
return NSS_STATUS_SUCCESS;
return nret;
return NSS_STATUS_NOTFOUND;
int errnop;
return nret;
return NSS_STATUS_SUCCESS;