diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-12-16 21:50:51 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-12-16 21:50:51 +0000 |
commit | f67d6f67b84daa6acd33dd8f4192a72bc46c3a63 (patch) | |
tree | 5a2a84e90cbf80cd3f2ca1616a2d27b694c51d91 /nss/hosts.c | |
parent | 08f01639626bb2ec2537df7d9f8c5459867c0afb (diff) |
switch to a common back-end with a common constructor and destructor and put file pointer shared between {set,get,end}ent() calls in there
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd-solaris@1333 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss/hosts.c')
-rw-r--r-- | nss/hosts.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/nss/hosts.c b/nss/hosts.c index 019e2b5..eda7dc5 100644 --- a/nss/hosts.c +++ b/nss/hosts.c @@ -242,6 +242,13 @@ nss_status_t _nss_ldap_endhostent(void) #ifdef NSS_FLAVOUR_SOLARIS +struct nss_ldap_hosts_backend +{ + nss_backend_op_t *ops; + int n_ops; + TFILE *fp; +}; + #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN static nss_status_t read_hoststring(TFILE *fp,nss_XbyY_args_t *args,int erronempty) @@ -341,33 +348,24 @@ static nss_status_t hosts_gethostbyaddr(nss_backend_t UNUSED(*be),void *args) READ_RESULT_ERRONEMPTY(fp)); } -/* thread-local file pointer to an ongoing request */ -static __thread TFILE *hostentfp; - -static nss_status_t hosts_sethostent(nss_backend_t UNUSED(*be),void UNUSED(*args)) +static nss_status_t hosts_sethostent(nss_backend_t *be,void UNUSED(*args)) { - NSS_SETENT(hostentfp); + NSS_SETENT(LDAP_BE(be)->fp); } -static nss_status_t hosts_gethostent(nss_backend_t UNUSED(*be),void *args) +static nss_status_t hosts_gethostent(nss_backend_t *be,void *args) { - NSS_GETENT(hostentfp,NSLCD_ACTION_HOST_ALL, - READ_RESULT_NEXTONEMPTY(hostentfp)); -} - -static nss_status_t hosts_endhostent(nss_backend_t UNUSED(*be),void UNUSED(*args)) -{ - NSS_ENDENT(hostentfp); + NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_HOST_ALL, + READ_RESULT_NEXTONEMPTY(LDAP_BE(be)->fp)); } -static nss_status_t hosts_destructor(nss_backend_t *be,void UNUSED(*args)) +static nss_status_t hosts_endhostent(nss_backend_t *be,void UNUSED(*args)) { - free(be); - return NSS_STATUS_SUCCESS; + NSS_ENDENT(LDAP_BE(be)->fp); } -static nss_backend_op_t host_ops[]={ - hosts_destructor, +static nss_backend_op_t hosts_ops[]={ + nss_ldap_destructor, hosts_endhostent, hosts_sethostent, hosts_gethostent, @@ -378,12 +376,7 @@ static nss_backend_op_t host_ops[]={ nss_backend_t *_nss_ldap_hosts_constr(const char UNUSED(*db_name), const char UNUSED(*src_name),const char UNUSED(*cfg_args)) { - nss_backend_t *be; - if (!(be=(nss_backend_t *)malloc(sizeof(*be)))) - return NULL; - be->ops=host_ops; - be->n_ops=sizeof(host_ops)/sizeof(nss_backend_op_t); - return (nss_backend_t *)be; + return nss_ldap_constructor(hosts_ops,sizeof(hosts_ops)); } #endif /* NSS_FLAVOUR_SOLARIS */ |