common.c revision 6748a4c9d75db997c724c1dcea541e0047742f52
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * System Security Services Daemon. NSS client interface
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * Copyright (C) Simo Sorce 2007
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * Winbind derived code:
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * Copyright (C) Tim Potter 2000
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * Copyright (C) Andrew Tridgell 2000
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * Copyright (C) Andrew Bartlett 2002
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * This program is free software; you can redistribute it and/or modify
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * it under the terms of the GNU Lesser General Public License as
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * published by the Free Software Foundation; either version 2.1 of the
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * License, or (at your option) any later version.
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * This program is distributed in the hope that it will be useful,
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * but WITHOUT ANY WARRANTY; without even the implied warranty of
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * GNU Lesser General Public License for more details.
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * You should have received a copy of the GNU Lesser General Public License
e7ccfb139388c947ec2dee16cfe3005f5643b90dPetr Cech * along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <poll.h>
#include <time.h>
#include <libintl.h>
#include "sss_cli.h"
#if HAVE_PTHREAD
#include <pthread.h>
#ifdef MSG_NOSIGNAL
#define SSS_DEFAULT_WRITE_FLAGS 0
static void sss_cli_close_socket(void)
int *errnop)
datasent = 0;
int rdsent;
*errnop = 0;
errno = 0;
switch (res) {
if (*errnop) {
return SSS_STATUS_UNAVAIL;
errno = 0;
return SSS_STATUS_UNAVAIL;
return SSS_STATUS_SUCCESS;
int *errnop)
bool pollhup = false;
int len;
int ret;
datarecv = 0;
len = 0;
*errnop = 0;
int bufrecv;
errno = 0;
switch (res) {
pollhup = true;
if (*errnop) {
goto failed;
errno = 0;
goto failed;
goto failed;
goto failed;
goto failed;
if (!buf) {
goto failed;
if (pollhup) {
return SSS_STATUS_SUCCESS;
return ret;
int *errnop)
int len = 0;
return ret;
return ret;
if (replen) {
if (replen) {
*replen = 0;
return SSS_STATUS_SUCCESS;
int errnop;
if (!repbuf) {
/* this 2 functions are adapted from samba3 winbinbd's wb_common.c */
int new_fd;
#ifdef F_DUPFD
return new_fd;
if (limit <= 0)
return new_fd;
return fd;
Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available,
#ifdef O_NONBLOCK
#ifdef SYSV
#ifdef FD_CLOEXEC
if (flags >= 0) {
if (result < 0) {
return new_fd;
bool inprogress = true;
bool connected = false;
unsigned int wait_time;
unsigned int sleep_time;
int ret;
int sd;
wait_time = 0;
sleep_time = 0;
while (inprogress) {
int connect_errno = 0;
sizeof(nssaddr));
if (ret == 0) {
connected = true;
switch(errno) {
case EINPROGRESS:
if (ret > 0) {
connected = true;
case EAGAIN:
inprogress = false;
inprogress = false;
if (connected) {
inprogress = false;
if (!connected) {
if (ret != 0) {
return sd;
int mysd;
int ret;
if (ret == 0) {
*errnop = 0;
errno = 0;
switch (res) {
if (*errnop == 0) {
return SSS_STATUS_SUCCESS;
return SSS_STATUS_UNAVAIL;
return SSS_STATUS_SUCCESS;
return SSS_STATUS_UNAVAIL;
int *errnop)
char *envval;
return NSS_STATUS_NOTFOUND;
*errnop = 0;
errno = 0;
return NSS_STATUS_NOTFOUND;
return NSS_STATUS_UNAVAIL;
*errnop = 0;
errno = 0;
return NSS_STATUS_NOTFOUND;
return NSS_STATUS_UNAVAIL;
switch (ret) {
case SSS_STATUS_TRYAGAIN:
return NSS_STATUS_TRYAGAIN;
case SSS_STATUS_SUCCESS:
return NSS_STATUS_SUCCESS;
case SSS_STATUS_UNAVAIL:
*errnop = 0;
errno = 0;
return NSS_STATUS_NOTFOUND;
return NSS_STATUS_UNAVAIL;
int sss_pac_check_and_open(void)
int errnop;
return EIO;
return EOK;
int *errnop)
char *envval;
return NSS_STATUS_NOTFOUND;
return NSS_STATUS_UNAVAIL;
return NSS_STATUS_UNAVAIL;
switch (ret) {
case SSS_STATUS_TRYAGAIN:
return NSS_STATUS_TRYAGAIN;
case SSS_STATUS_SUCCESS:
return NSS_STATUS_SUCCESS;
case SSS_STATUS_UNAVAIL:
return NSS_STATUS_UNAVAIL;
#ifdef HAVE_UCRED
int ret;
if (ret != 0) {
return errno;
return ESSS_BAD_CRED_MSG;
return ESSS_SERVER_NOT_TRUSTED;
int *errnop)
char *envval;
const char *socket_name;
sss_pam_lock();
goto out;
if (statret != 0) {
goto out;
goto out;
if (statret != 0) {
goto out;
goto out;
goto out;
if (error != 0) {
goto out;
goto out;
out:
return ret;
void sss_pam_close_fd(void)
sss_pam_lock();
static enum sss_status
int *errnop,
const char *socket_name)
return SSS_STATUS_UNAVAIL;
return SSS_STATUS_UNAVAIL;
return ret;
int *errnop)
int *errnop)
int *errnop)
switch(err) {
case ESSS_BAD_PRIV_SOCKET:
case ESSS_BAD_PUB_SOCKET:
case ESSS_BAD_CRED_MSG:
case ESSS_SERVER_NOT_TRUSTED:
if (m == NULL) {
if (!str) {
return EINVAL;
#if defined __USE_GNU
*len = 0;
(*len)++;
return EFBIG;
#if HAVE_PTHREAD
typedef void (*sss_mutex_init)(void);
struct sss_mutex {
static void sss_nss_mt_init(void);
static void sss_pam_mt_init(void);
static void sss_nss_mc_mt_init(void);
static void sss_nss_mt_init(void)
void sss_nss_lock(void)
void sss_nss_unlock(void)
static void sss_pam_mt_init(void)
void sss_pam_lock(void)
void sss_pam_unlock(void)
static void sss_nss_mc_mt_init(void)
void sss_nss_mc_lock(void)
void sss_nss_mc_unlock(void)
void sss_nss_lock(void) { return; }
void sss_nss_unlock(void) { return; }
void sss_pam_lock(void) { return; }
void sss_pam_unlock(void) { return; }
void sss_nss_mc_lock(void) { return; }
void sss_nss_mc_unlock(void) { return; }
char **out,
size_t i = 0;
(*offset)++;
(*dlen)--;
return EBADMSG;
(*offset)++;
(*dlen)--;
if (size) {
*size = i;
return EOK;