diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2010-12-30 13:13:26 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2010-12-30 13:13:26 +0000 |
commit | 5c8779d3d77d7c9c076c9e1c48d048fba880c95f (patch) | |
tree | 3d8bc669c9eac732ecc39e33396511c2049e89ca /nss/protocols.c | |
parent | ed6bc27721075adf0215ad8b856fcdcf7b98b9b7 (diff) | |
parent | 7268fd2233a93f83b4acb2247fad2cc1645e5d36 (diff) |
integrate Solaris support developed by Ted C. Cheng of Symas Corporation that was developed on the -solaris branch
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1354 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss/protocols.c')
-rw-r--r-- | nss/protocols.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/nss/protocols.c b/nss/protocols.c index cb32923..c641eaa 100644 --- a/nss/protocols.c +++ b/nss/protocols.c @@ -3,6 +3,7 @@ Copyright (C) 2006 West Consulting Copyright (C) 2006, 2007, 2008, 2010 Arthur de Jong + Copyright (C) 2010 Symas Corporation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -42,6 +43,8 @@ static nss_status_t read_protoent( return NSS_STATUS_SUCCESS; } +#ifdef NSS_FLAVOUR_GLIBC + /* get a protocol entry by name */ nss_status_t _nss_ldap_getprotobyname_r( const char *name,struct protoent *result, @@ -85,3 +88,103 @@ nss_status_t _nss_ldap_endprotoent(void) { NSS_ENDENT(protoentfp); } + +#endif /* NSS_FLAVOUR_GLIBC */ + +#ifdef NSS_FLAVOUR_SOLARIS + +#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN + +static nss_status_t read_protostring(TFILE *fp,nss_XbyY_args_t *args) +{ + struct protoent result; + nss_status_t retv; + char *buffer; + size_t buflen; + int i; + /* read the protoent */ + retv=read_protoent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno); + if (retv!=NSS_STATUS_SUCCESS) + return retv; + /* allocate a temporary buffer */ + buflen=args->buf.buflen; + buffer=(char *)malloc(buflen); + /* build the formatted string */ + /* FIXME: implement proper buffer size checking */ + sprintf(buffer,"%s\t\t%d",result.p_name,result.p_proto); + if (result.p_aliases) + for (i=0; result.p_aliases[i]; i++) + { + strcat(buffer," "); + strcat(buffer,result.p_aliases[i]); + } + /* copy the result back to the result buffer and free the temporary one */ + strcpy(NSS_ARGS(args)->buf.buffer,buffer); + free(buffer); + NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer; + NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer); + return NSS_STATUS_SUCCESS; +} + +#define READ_RESULT(fp) \ + NSS_ARGS(args)->buf.result? \ + read_protoent(fp,(struct protoent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno): \ + read_protostring(fp,args); \ + if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \ + NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result; + +#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */ + +#define READ_RESULT(fp) \ + read_protoent(fp,(struct protoent *)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno); \ + if (retv==NSS_STATUS_SUCCESS) \ + NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result; + +#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */ + +static nss_status_t protocols_getprotobyname(nss_backend_t UNUSED(*be),void *args) +{ + NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME, + NSS_ARGS(args)->key.name, + READ_RESULT(fp)); +} + +static nss_status_t protocols_getprotobynumber(nss_backend_t UNUSED(*be),void *args) +{ + NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER, + NSS_ARGS(args)->key.number, + READ_RESULT(fp)); +} + +static nss_status_t protocols_setprotoent(nss_backend_t *be,void UNUSED(*args)) +{ + NSS_SETENT(LDAP_BE(be)->fp); +} + +static nss_status_t protocols_getprotoent(nss_backend_t *be,void *args) +{ + NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_PROTOCOL_ALL, + READ_RESULT(LDAP_BE(be)->fp)); +} + +static nss_status_t protocols_endprotoent(nss_backend_t *be,void UNUSED(*args)) +{ + NSS_ENDENT(LDAP_BE(be)->fp); +} + +static nss_backend_op_t protocols_ops[]={ + nss_ldap_destructor, + protocols_endprotoent, + protocols_setprotoent, + protocols_getprotoent, + protocols_getprotobyname, + protocols_getprotobynumber +}; + +nss_backend_t *_nss_ldap_protocols_constr(const char UNUSED(*db_name), + const char UNUSED(*src_name),const char UNUSED(*cfg_args)) +{ + return nss_ldap_constructor(protocols_ops,sizeof(protocols_ops)); +} + +#endif /* NSS_FLAVOUR_SOLARIS */ |