45
47
return NSS_STATUS_SUCCESS;
48
enum nss_status _nss_ldap_getservbyname_r(const char *name,const char *protocol,struct servent *result,char *buffer,size_t buflen,int *errnop)
50
#ifdef NSS_FLAVOUR_GLIBC
52
/* get a service entry by name and protocol */
53
nss_status_t _nss_ldap_getservbyname_r(
54
const char *name,const char *protocol,struct servent *result,
55
char *buffer,size_t buflen,int *errnop)
50
57
NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
51
58
WRITE_STRING(fp,name);WRITE_STRING(fp,protocol),
52
59
read_servent(fp,result,buffer,buflen,errnop));
56
enum nss_status _nss_ldap_getservbyport_r(int port,const char *protocol,struct servent *result,char *buffer,size_t buflen,int *errnop)
62
/* get a service entry by port and protocol */
63
nss_status_t _nss_ldap_getservbyport_r(
64
int port,const char *protocol,struct servent *result,
65
char *buffer,size_t buflen,int *errnop)
58
67
NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
59
68
WRITE_INT32(fp,ntohs(port));WRITE_STRING(fp,protocol),
63
72
/* thread-local file pointer to an ongoing request */
64
static __thread TFILE *protoentfp;
66
enum nss_status _nss_ldap_setservent(int UNUSED(stayopen))
68
NSS_SETENT(protoentfp);
71
enum nss_status _nss_ldap_getservent_r(struct servent *result,char *buffer,size_t buflen,int *errnop)
73
NSS_GETENT(protoentfp,NSLCD_ACTION_SERVICE_ALL,
74
read_servent(protoentfp,result,buffer,buflen,errnop));
77
enum nss_status _nss_ldap_endservent(void)
79
NSS_ENDENT(protoentfp);
73
static __thread TFILE *serventfp;
75
/* open request to get all services */
76
nss_status_t _nss_ldap_setservent(int UNUSED(stayopen))
78
NSS_SETENT(serventfp);
81
/* read a single returned service definition */
82
nss_status_t _nss_ldap_getservent_r(
83
struct servent *result,
84
char *buffer,size_t buflen,int *errnop)
86
NSS_GETENT(serventfp,NSLCD_ACTION_SERVICE_ALL,
87
read_servent(serventfp,result,buffer,buflen,errnop));
90
/* close the stream opened by setservent() above */
91
nss_status_t _nss_ldap_endservent(void)
93
NSS_ENDENT(serventfp);
96
#endif /* NSS_FLAVOUR_GLIBC */
98
#ifdef NSS_FLAVOUR_SOLARIS
100
#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
102
static nss_status_t read_servstring(TFILE *fp,nss_XbyY_args_t *args)
104
struct servent result;
109
/* read the servent */
110
retv=read_servent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
111
if (retv!=NSS_STATUS_SUCCESS)
113
/* allocate a temporary buffer */
114
buflen=args->buf.buflen;
115
buffer=(char *)malloc(buflen);
116
/* build the formatted string */
117
/* FIXME: implement proper buffer size checking */
118
sprintf(buffer,"%s %d/%s",result.s_name,result.s_port,result.s_proto);
119
if (result.s_aliases)
120
for (i=0;result.s_aliases[i];i++)
123
strcat(buffer,result.s_aliases[i]);
125
/* copy the result back to the result buffer and free the temporary one */
126
strcpy(NSS_ARGS(args)->buf.buffer,buffer);
128
NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
129
NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
130
return NSS_STATUS_SUCCESS;
133
#define READ_RESULT(fp) \
134
NSS_ARGS(args)->buf.result? \
135
read_servent(fp,(struct servent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno): \
136
read_servstring(fp,args); \
137
if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
138
NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
140
#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
142
#define READ_RESULT(fp) \
143
read_servent(fp,(struct servent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno); \
144
if (retv==NSS_STATUS_SUCCESS) \
145
NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
147
#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
149
static nss_status_t services_getservbyname(nss_backend_t UNUSED(*be),void *args)
151
NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
152
WRITE_STRING(fp,NSS_ARGS(args)->key.serv.serv.name);
153
WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
157
static nss_status_t services_getservbyport(nss_backend_t UNUSED(*be),void *args)
159
NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
160
WRITE_INT32(fp,ntohs(NSS_ARGS(args)->key.serv.serv.port));
161
WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
165
static nss_status_t services_setservent(nss_backend_t *be,void UNUSED(*args))
167
NSS_SETENT(LDAP_BE(be)->fp);
170
static nss_status_t services_getservent(nss_backend_t *be,void *args)
172
NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_SERVICE_ALL,
173
READ_RESULT(LDAP_BE(be)->fp));
176
static nss_status_t services_endservent(nss_backend_t *be,void UNUSED(*args))
178
NSS_ENDENT(LDAP_BE(be)->fp);
181
static nss_backend_op_t services_ops[]={
186
services_getservbyname,
187
services_getservbyport
190
nss_backend_t *_nss_ldap_services_constr(const char UNUSED(*db_name),
191
const char UNUSED(*src_name),const char UNUSED(*cfg_args))
193
return nss_ldap_constructor(services_ops,sizeof(services_ops));
196
#endif /* NSS_FLAVOUR_SOLARIS */