60
64
/* read a single network entry from the stream, ignoring entries
61
65
that are not AF_INET (IPv4), result is stored in result */
62
static enum nss_status read_netent(
66
static nss_status_t read_netent(
63
67
TFILE *fp,struct netent *result,
64
68
char *buffer,size_t buflen,int *errnop,int *h_errnop)
66
70
int32_t tmpint32,tmp2int32,tmp3int32;
70
enum nss_status retv=NSS_STATUS_NOTFOUND;
74
nss_status_t retv=NSS_STATUS_NOTFOUND;
71
75
/* read the network entry */
72
76
READ_BUF_STRING(fp,result->n_name);
73
77
READ_BUF_STRINGLIST(fp,result->n_aliases);
114
110
WRITE_INT32(fp,4); \
115
111
WRITE_INT32(fp,htonl(addr));
113
#ifdef NSS_FLAVOUR_GLIBC
115
/* get a network entry by name */
116
nss_status_t _nss_ldap_getnetbyname_r(
117
const char *name,struct netent *result,
118
char *buffer,size_t buflen,int *errnop,int *h_errnop)
120
NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
122
read_netent(fp,result,buffer,buflen,errnop,h_errnop));
117
125
/* Note: the af parameter is ignored and is assumed to be AF_INET */
118
126
/* TODO: implement handling of af parameter */
119
enum nss_status _nss_ldap_getnetbyaddr_r(uint32_t addr,int UNUSED(af),struct netent *result,char *buffer,size_t buflen,int *errnop,int *h_errnop)
127
nss_status_t _nss_ldap_getnetbyaddr_r(
128
uint32_t addr,int UNUSED(af),struct netent *result,
129
char *buffer,size_t buflen,int *errnop,int *h_errnop)
121
131
NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
122
132
WRITE_ADDRESS(fp,addr),
126
136
/* thread-local file pointer to an ongoing request */
127
137
static __thread TFILE *netentfp;
129
enum nss_status _nss_ldap_setnetent(int UNUSED(stayopen))
139
/* start a request to read all networks */
140
nss_status_t _nss_ldap_setnetent(int UNUSED(stayopen))
131
142
NSS_SETENT(netentfp);
134
enum nss_status _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t buflen,int *errnop,int *h_errnop)
145
/* get a single network entry from the stream */
146
nss_status_t _nss_ldap_getnetent_r(
147
struct netent *result,
148
char *buffer,size_t buflen,int *errnop,int *h_errnop)
136
150
NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,
137
151
read_netent(netentfp,result,buffer,buflen,errnop,h_errnop));
140
enum nss_status _nss_ldap_endnetent(void)
154
/* close the stream opened by setnetent() above */
155
nss_status_t _nss_ldap_endnetent(void)
142
157
NSS_ENDENT(netentfp);
160
#endif /* NSS_FLAVOUR_GLIBC */
162
#ifdef NSS_FLAVOUR_SOLARIS
164
#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
166
static nss_status_t read_netentstring(TFILE *fp,nss_XbyY_args_t *args)
168
struct netent result;
173
struct in_addr priv_in_addr;
174
/* read the netent */
175
retv=read_netent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno));
176
if (retv!=NSS_STATUS_SUCCESS)
178
/* allocate a temporary buffer */
179
buflen=args->buf.buflen;
180
buffer=(char *)malloc(buflen);
181
/* build the formatted string */
182
/* FIXME: implement proper buffer size checking */
183
priv_in_addr.s_addr = result.n_net;
184
sprintf(buffer,"%s %s",result.n_name,inet_ntoa(priv_in_addr)); /* ipNetworkNumber */
185
if (result.n_aliases)
186
for (i=0;result.n_aliases[i];i++)
189
strcat(buffer,result.n_aliases[i]);
191
/* copy the result back to the result buffer and free the temporary one */
192
strcpy(NSS_ARGS(args)->buf.buffer,buffer);
194
NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
195
NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
196
return NSS_STATUS_SUCCESS;
199
#define READ_RESULT(fp) \
200
NSS_ARGS(args)->buf.result? \
201
read_netent(fp,(struct netent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno)): \
202
read_netentstring(fp,args); \
203
if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
204
NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
206
#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
208
#define READ_RESULT(fp) \
209
read_netent(fp,(struct netent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno)); \
210
if (retv==NSS_STATUS_SUCCESS) \
211
NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
213
#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
215
/* more of a dirty hack */
216
#define h_errnop (&(NSS_ARGS(args)->h_errno))
218
static nss_status_t networks_getnetbyname(nss_backend_t UNUSED(*be),void *args)
220
NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
221
NSS_ARGS(args)->key.name,
225
static nss_status_t networks_getnetbyaddr(nss_backend_t UNUSED(*be),void *args)
227
NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
228
WRITE_ADDRESS(fp,NSS_ARGS(args)->key.netaddr.net),
232
static nss_status_t networks_setnetent(nss_backend_t *be,void UNUSED(*args))
234
NSS_SETENT(LDAP_BE(be)->fp);
237
static nss_status_t networks_getnetent(nss_backend_t *be,void *args)
239
NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_NETWORK_ALL,
240
READ_RESULT(LDAP_BE(be)->fp));
243
static nss_status_t networks_endnetent(nss_backend_t *be,void UNUSED(*args))
245
NSS_ENDENT(LDAP_BE(be)->fp);
248
static nss_backend_op_t networks_ops[]={
253
networks_getnetbyname,
254
networks_getnetbyaddr
257
nss_backend_t *_nss_ldap_networks_constr(const char UNUSED(*db_name),
258
const char UNUSED(*src_name),const char UNUSED(*cfg_args))
260
return nss_ldap_constructor(networks_ops,sizeof(networks_ops));
263
#endif /* NSS_FLAVOUR_SOLARIS */