diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-25 09:16:40 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-25 09:16:40 +0000 |
commit | 146b685aaec0a84a366f38b607c63e476d30f28a (patch) | |
tree | 5627f7723d8d64ef648a41fce43a5c2897ad1020 | |
parent | 7bf94f0a74226c083fc06f275703840d4063f4fc (diff) |
implement protocol handling (server side)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@118 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | nslcd-server.c | 2 | ||||
-rw-r--r-- | server/protocol.c | 131 | ||||
-rw-r--r-- | testnss.c | 47 |
3 files changed, 153 insertions, 27 deletions
diff --git a/nslcd-server.c b/nslcd-server.c index d8624d8..6038843 100644 --- a/nslcd-server.c +++ b/nslcd-server.c @@ -174,10 +174,10 @@ void nslcd_server_handlerequest(int sock) case NSLCD_ACTION_PASSWD_BYNAME: nslcd_passwd_byname(fp); break; case NSLCD_ACTION_PASSWD_BYUID: nslcd_passwd_byuid(fp); break; case NSLCD_ACTION_PASSWD_ALL: nslcd_passwd_all(fp); break; -/* case NSLCD_ACTION_PROTOCOL_BYNAME: nslcd_protocol_byname(fp); break; case NSLCD_ACTION_PROTOCOL_BYNUMBER:nslcd_protocol_bynumber(fp); break; case NSLCD_ACTION_PROTOCOL_ALL: nslcd_protocol_all(fp); break; +/* case NSLCD_ACTION_RPC_BYNAME: nslcd_rpc_byname(fp); break; case NSLCD_ACTION_RPC_BYNUMBER: nslcd_rpc_bynumber(fp); break; case NSLCD_ACTION_RPC_ALL: nslcd_rpc_all(fp); break; diff --git a/server/protocol.c b/server/protocol.c index 2300535..c953a85 100644 --- a/server/protocol.c +++ b/server/protocol.c @@ -50,8 +50,9 @@ #include "ldap-nss.h" #include "util.h" - -static struct ent_context *proto_context = NULL; +#include "nslcd-server.h" +#include "common.h" +#include "log.h" static enum nss_status _nss_ldap_parse_proto (LDAPMessage *e, struct ldap_state *pvt, @@ -85,36 +86,114 @@ static enum nss_status _nss_ldap_parse_proto (LDAPMessage *e, return NSS_STATUS_SUCCESS; } -enum nss_status _nss_ldap_getprotobyname_r(const char *name,struct protoent *result, - char *buffer,size_t buflen,int *errnop) -{ - LOOKUP_NAME (name, result, buffer, buflen, errnop, - _nss_ldap_filt_getprotobyname, LM_PROTOCOLS, - _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_getprotobynumber_r(int number,struct protoent *result, - char *buffer,size_t buflen,int *errnop) -{ - LOOKUP_NUMBER (number, result, buffer, buflen, errnop, - _nss_ldap_filt_getprotobynumber, LM_PROTOCOLS, - _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); -} +/* macros for expanding the LDF_PROTOCOL macro */ +#define LDF_STRING(field) WRITE_STRING(fp,field) +#define LDF_STRINGLIST(field) WRITE_STRINGLIST_NULLTERM(fp,field) +#define LDF_INT32(field) WRITE_INT32(fp,field) +#define PROTOCOL_NAME result.p_name +#define PROTOCOL_ALIASES result.p_aliases +#define PROTOCOL_NUMBER result.p_proto -enum nss_status _nss_ldap_setprotoent(void) +int nslcd_protocol_byname(FILE *fp) { - LOOKUP_SETENT (proto_context); + int32_t tmpint32,tmp2int32,tmp3int32; + char *name; + struct ldap_args a; + /* these are here for now until we rewrite the LDAP code */ + struct protoent result; + char buffer[1024]; + int errnop; + int retv; + /* read request parameters */ + READ_STRING_ALLOC(fp,name); + /* log call */ + log_log(LOG_DEBUG,"nslcd_protocol_byname(%s)",name); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_PROTOCOL_BYNAME); + /* do the LDAP request */ + LA_INIT(a); + LA_STRING(a)=name; + LA_TYPE(a)=LA_TYPE_STRING; + retv=nss2nslcd(_nss_ldap_getbyname(&a,&result,buffer,1024,&errnop,_nss_ldap_filt_getprotobyname,LM_PROTOCOLS,_nss_ldap_parse_proto)); + /* no more need for this string */ + free(name); + /* write the response */ + WRITE_INT32(fp,retv); + if (retv==NSLCD_RESULT_SUCCESS) + { + LDF_PROTOCOL; + } + WRITE_FLUSH(fp); + /* we're done */ + return 0; } -enum nss_status _nss_ldap_getprotoent_r(struct protoent *result,char *buffer,size_t buflen, - int *errnop) +int nslcd_protocol_bynumber(FILE *fp) { - LOOKUP_GETENT (proto_context, result, buffer, buflen, errnop, - _nss_ldap_filt_getprotoent, LM_PROTOCOLS, - _nss_ldap_parse_proto, LDAP_NSS_BUFLEN_DEFAULT); + int32_t tmpint32,tmp2int32,tmp3int32; + int protocol; + struct ldap_args a; + /* these are here for now until we rewrite the LDAP code */ + struct protoent result; + char buffer[1024]; + int errnop; + int retv; + /* read request parameters */ + READ_INT32(fp,protocol); + /* log call */ + log_log(LOG_DEBUG,"nslcd_protocol_bynumber(%d)",protocol); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_PROTOCOL_BYNUMBER); + /* do the LDAP request */ + LA_INIT(a); + LA_NUMBER(a)=protocol; + LA_TYPE(a)=LA_TYPE_NUMBER; + retv=nss2nslcd(_nss_ldap_getbyname(&a,&result,buffer,1024,&errnop,_nss_ldap_filt_getprotobynumber,LM_PROTOCOLS,_nss_ldap_parse_proto)); + /* write the response */ + WRITE_INT32(fp,retv); + if (retv==NSLCD_RESULT_SUCCESS) + { + LDF_PROTOCOL; + } + WRITE_FLUSH(fp); + /* we're done */ + return 0; } -enum nss_status _nss_ldap_endprotoent(void) +int nslcd_protocol_all(FILE *fp) { - LOOKUP_ENDENT (proto_context); + int32_t tmpint32,tmp2int32,tmp3int32; + static struct ent_context *protocol_context; + /* these are here for now until we rewrite the LDAP code */ + struct protoent result; + char buffer[1024]; + int errnop; + int retv; + /* log call */ + log_log(LOG_DEBUG,"nslcd_protocol_all()"); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_PROTOCOL_ALL); + /* initialize context */ + if (_nss_ldap_ent_context_init(&protocol_context)==NULL) + return -1; + /* loop over all results */ + while ((retv=nss2nslcd(_nss_ldap_getent(&protocol_context,&result,buffer,1024,&errnop,_nss_ldap_filt_getprotoent,LM_PROTOCOLS,_nss_ldap_parse_proto)))==NSLCD_RESULT_SUCCESS) + { + /* write the result code */ + WRITE_INT32(fp,retv); + /* write the entry */ + LDF_PROTOCOL; + fflush(fp); + } + /* write the final result code */ + WRITE_INT32(fp,retv); + /* FIXME: if a previous call returns what happens to the context? */ + _nss_ldap_enter(); + _nss_ldap_ent_context_release(protocol_context); + _nss_ldap_leave(); + /* we're done */ + return 0; } @@ -132,6 +132,20 @@ static void printether(struct etherent *ether) ether->e_name,ether_ntoa(&(ether->e_addr))); } +static void printproto(struct protoent *protocol) +{ + int i; + printf("struct protoent {\n" + " p_name=\"%s\",\n", + protocol->p_name); + for (i=0;protocol->p_aliases[i]!=NULL;i++) + printf(" p_aliases[%d]=\"%s\",\n", + i,protocol->p_aliases[i]); + printf(" p_aliases[%d]=NULL,\n" + " p_proto=%d\n" + "}\n",i,(int)(protocol->p_proto)); +} + static void printshadow(struct spwd *shadow) { printf("struct spwd {\n" @@ -189,6 +203,7 @@ int main(int argc,char *argv[]) struct etherent etherresult; struct spwd shadowresult; struct __netgrent netgroupresult; + struct protoent protoresult; char buffer[1024]; enum nss_status res; int errnocp,h_errnocp; @@ -447,5 +462,37 @@ int main(int argc,char *argv[]) res=_nss_ldap_endnetgrent(&netgroupresult); printf("status=%s\n",nssstatus(res)); + /* test getprotobyname() */ + printf("\nTEST getprotobyname()\n"); + res=_nss_ldap_getprotobyname_r("foo",&protoresult,buffer,1024,&errnocp); + printf("status=%s\n",nssstatus(res)); + if (res==NSS_STATUS_SUCCESS) + printproto(&protoresult); + else + printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp)); + + /* test getprotobynumber() */ + printf("\nTEST getprotobynumber()\n"); + res=_nss_ldap_getprotobynumber_r(10,&protoresult,buffer,1024,&errnocp); + printf("status=%s\n",nssstatus(res)); + if (res==NSS_STATUS_SUCCESS) + printproto(&protoresult); + else + printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp)); + + /* test {set,get,end}protoent() */ + printf("\nTEST {set,get,end}protoent()\n"); + res=_nss_ldap_setprotoent(1); + printf("status=%s\n",nssstatus(res)); + while ((res=_nss_ldap_getprotoent_r(&protoresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS) + { + printf("status=%s\n",nssstatus(res)); + printproto(&protoresult); + } + printf("status=%s\n",nssstatus(res)); + printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp)); + res=_nss_ldap_endprotoent(); + printf("status=%s\n",nssstatus(res)); + return 0; } |