nss_services.c revision b481712148b36362e09d7611be1f36be6b962ca0
/*
SSSD
Authors:
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2012 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, 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 <nss.h>
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "sss_cli.h"
static struct sss_nss_getservent_data {
static void sss_nss_getservent_data_clean(void) {
}
}
/* GETSERVBYNAME Request
*
* 0-X: Sequence of two, zero-terminated strings (name, protocol).
* Protocol may be zero-length to imply "any"
*
* GETSERVBYPORT Request:
* 0-3: 16-bit port number in network byte order
* 16-X: Zero-terminated string (protocol)
* Protocol may be zero-length to imply "any"
*
* Replies:
* 0-3: 32-bit unsigned number of results
* 7-X: Result data (blocks equal to number of results)
*
* Result data:
* 0-3: 32-bit unsigned port number in network byte order
* 4-7: 32-bit unsigned number of aliases
* 8-X: sequence of zero-terminated strings
* (name, protocol, zero or more aliases)
*/
struct sss_nss_svc_rep {
char *buffer;
};
#define SVC_METADATA_COUNT 8
static errno_t
{
uint32_t c;
char *sbuf;
/* Buffer must contain two 32-bit integers,
* at least one character and null-terminator
* for the name, and at least a null-
* terminator for the protocol.
*/
if (*len < 11) {
/* not enough space for data, bad packet */
return EBADMSG;
}
/* Get the port */
/* Get the number of aliases */
/* Copy in the name */
i = 0;
NULL);
/* Copy in the protocol */
NULL);
/* Make sure sr->buffer[i+pad] is 32-bit aligned */
pad = 0;
while((i + pad) % 4) {
pad++;
}
/* Copy in the aliases */
return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */
}
ptaliases += i;
for (l = 0; l < num_aliases; l++) {
&alen);
}
return EOK;
}
enum nss_status
_nss_sss_getservbyname_r(const char *name,
const char *protocol,
int *errnop)
{
struct sss_cli_req_data rd;
struct sss_nss_svc_rep svcrep;
enum nss_status nret;
int ret;
/* Caught once glibc passing in buffer == 0x0 */
if (ret != 0) {
return NSS_STATUS_NOTFOUND;
}
if (protocol) {
if (ret != 0) {
return NSS_STATUS_NOTFOUND;
}
}
goto out;
}
if (protocol) {
} else {
/* No protocol specified, pass empty string */
}
sss_nss_lock();
if (nret != NSS_STATUS_SUCCESS) {
goto out;
}
/* no results if not found */
goto out;
}
/* only 1 result is accepted for this function */
goto out;
}
&len);
if (ret) {
goto out;
}
out:
return nret;
}
enum nss_status
int *errnop)
{
struct sss_cli_req_data rd;
struct sss_nss_svc_rep svcrep;
size_t p = 0;
enum nss_status nret;
int ret;
/* Caught once glibc passing in buffer == 0x0 */
if (protocol) {
if (ret != 0) {
return NSS_STATUS_NOTFOUND;
}
}
goto out;
}
/* Padding */
SAFEALIGN_SET_UINT16(data + p, 0, &p);
SAFEALIGN_SET_UINT32(data + p, 0, &p);
if (protocol) {
} else {
/* No protocol specified, pass empty string */
data[p] = '\0';
}
sss_nss_lock();
if (nret != NSS_STATUS_SUCCESS) {
goto out;
}
/* no results if not found */
goto out;
}
/* only 1 result is accepted for this function */
goto out;
}
&len);
if (ret) {
goto out;
}
out:
return nret;
}
enum nss_status
_nss_sss_setservent(void)
{
enum nss_status nret;
int errnop;
sss_nss_lock();
/* make sure we do not have leftovers, and release memory */
if (nret != NSS_STATUS_SUCCESS) {
}
return nret;
}
int *errnop);
enum nss_status
int *errnop)
{
enum nss_status nret;
sss_nss_lock();
return nret;
}
int *errnop)
{
struct sss_cli_req_data rd;
struct sss_nss_svc_rep pwrep;
enum nss_status nret;
int ret;
/* Caught once glibc passing in buffer == 0x0 */
/* if there are leftovers return the next one */
if (ret) {
return NSS_STATUS_TRYAGAIN;
}
/* advance buffer pointer */
return NSS_STATUS_SUCCESS;
}
/* release memory if any */
/* retrieve no more than SSS_NSS_MAX_ENTRIES at a time */
if (nret != NSS_STATUS_SUCCESS) {
return nret;
}
/* no results if not found */
|| (replen - SVC_METADATA_COUNT == 0)) {
return NSS_STATUS_NOTFOUND;
}
/* skip metadata fields */
/* call again ourselves, this will return the first result */
}
enum nss_status
_nss_sss_endservent(void)
{
enum nss_status nret;
int errnop;
sss_nss_lock();
/* make sure we do not have leftovers, and release memory */
if (nret != NSS_STATUS_SUCCESS) {
}
return nret;
}