diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-25 10:09:20 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2006-11-25 10:09:20 +0000 |
commit | eb3793f2f0de767d8c93d4fb9a0d4282dac2483d (patch) | |
tree | 3ad4d8873934874a68b0cfec277bd9be764b470a | |
parent | 7b33779ed14bf544bad05321c7f241aed8712677 (diff) |
implement rpc service on server side
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@121 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | nslcd-server.c | 2 | ||||
-rw-r--r-- | server/rpc.c | 137 | ||||
-rw-r--r-- | testnss.c | 55 |
3 files changed, 162 insertions, 32 deletions
diff --git a/nslcd-server.c b/nslcd-server.c index 6038843..eece9de 100644 --- a/nslcd-server.c +++ b/nslcd-server.c @@ -177,10 +177,10 @@ void nslcd_server_handlerequest(int sock) 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; +/* case NSLCD_ACTION_SERVICE_BYNAME: nslcd_service_byname(fp); break; case NSLCD_ACTION_SERVICE_BYNUMBER: nslcd_service_bynumber(fp); break; case NSLCD_ACTION_SERVICE_ALL: nslcd_service_all(fp); break; diff --git a/server/rpc.c b/server/rpc.c index 2f33f1c..79f6575 100644 --- a/server/rpc.c +++ b/server/rpc.c @@ -54,8 +54,25 @@ #include "ldap-nss.h" #include "util.h" - -static struct ent_context *rpc_context = NULL; +#include "nslcd-server.h" +#include "common.h" +#include "log.h" + +/* macros for expanding the LDF_RPC 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 RPC_NAME result->r_name +#define RPC_ALIASES result->r_aliases +#define RPC_NUMBER result->r_number + +/* write a single host entry to the stream */ +static int write_rpcent(FILE *fp,struct rpcent *result) +{ + int32_t tmpint32,tmp2int32,tmp3int32; + LDF_RPC; + return 0; +} static enum nss_status _nss_ldap_parse_rpc (LDAPMessage * e, struct ldap_state * pvt, @@ -89,36 +106,102 @@ static enum nss_status _nss_ldap_parse_rpc (LDAPMessage * e, return NSS_STATUS_SUCCESS; } -enum nss_status _nss_ldap_getrpcbyname_r(const char *name,struct rpcent *result, - char *buffer,size_t buflen,int *errnop) -{ - LOOKUP_NAME(name, result, buffer, buflen, errnop, - _nss_ldap_filt_getrpcbyname, LM_RPC, _nss_ldap_parse_rpc, - LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_getrpcbynumber_r(int number,struct rpcent *result, - char *buffer,size_t buflen,int *errnop) -{ - LOOKUP_NUMBER(number, result, buffer, buflen, errnop, - _nss_ldap_filt_getrpcbynumber, LM_RPC, _nss_ldap_parse_rpc, - LDAP_NSS_BUFLEN_DEFAULT); -} - -enum nss_status _nss_ldap_setrpcent(void) +int nslcd_rpc_byname(FILE *fp) { - LOOKUP_SETENT(rpc_context); + int32_t tmpint32; + char *name; + struct ldap_args a; + /* these are here for now until we rewrite the LDAP code */ + struct rpcent result; + char buffer[1024]; + int errnop; + int retv; + /* read request parameters */ + READ_STRING_ALLOC(fp,name); + /* log call */ + log_log(LOG_DEBUG,"nslcd_rpc_byname(%s)",name); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_RPC_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_getrpcbyname,LM_RPC,_nss_ldap_parse_rpc)); + /* no more need for this string */ + free(name); + /* write the response */ + WRITE_INT32(fp,retv); + if (retv==NSLCD_RESULT_SUCCESS) + write_rpcent(fp,&result); + WRITE_FLUSH(fp); + /* we're done */ + return 0; } -enum nss_status _nss_ldap_getrpcent_r(struct rpcent *result,char *buffer,size_t buflen, - int *errnop) +int nslcd_rpc_bynumber(FILE *fp) { - LOOKUP_GETENT(rpc_context,result,buffer,buflen,errnop, - _nss_ldap_filt_getrpcent,LM_RPC,_nss_ldap_parse_rpc, - LDAP_NSS_BUFLEN_DEFAULT); + int32_t tmpint32; + int number; + struct ldap_args a; + /* these are here for now until we rewrite the LDAP code */ + struct rpcent result; + char buffer[1024]; + int errnop; + int retv; + /* read request parameters */ + READ_INT32(fp,number); + /* log call */ + log_log(LOG_DEBUG,"nslcd_rpc_bynumber(%d)",number); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_RPC_BYNUMBER); + /* do the LDAP request */ + LA_INIT(a); + LA_NUMBER(a)=number; + LA_TYPE(a)=LA_TYPE_NUMBER; + retv=nss2nslcd(_nss_ldap_getbyname(&a,&result,buffer,1024,&errnop,_nss_ldap_filt_getrpcbynumber,LM_RPC,_nss_ldap_parse_rpc)); + /* write the response */ + WRITE_INT32(fp,retv); + if (retv==NSLCD_RESULT_SUCCESS) + write_rpcent(fp,&result); + WRITE_FLUSH(fp); + /* we're done */ + return 0; } -enum nss_status _nss_ldap_endrpcent(void) +int nslcd_rpc_all(FILE *fp) { - LOOKUP_ENDENT(rpc_context); + int32_t tmpint32; + static struct ent_context *rpc_context; + /* these are here for now until we rewrite the LDAP code */ + struct rpcent result; + char buffer[1024]; + int errnop; + int retv; + /* log call */ + log_log(LOG_DEBUG,"nslcd_rpccol_all()"); + /* write the response header */ + WRITE_INT32(fp,NSLCD_VERSION); + WRITE_INT32(fp,NSLCD_ACTION_RPC_ALL); + /* initialize context */ + if (_nss_ldap_ent_context_init(&rpc_context)==NULL) + return -1; + /* loop over all results */ + while ((retv=nss2nslcd(_nss_ldap_getent(&rpc_context,&result,buffer,1024,&errnop,_nss_ldap_filt_getrpcent,LM_RPC,_nss_ldap_parse_rpc)))==NSLCD_RESULT_SUCCESS) + { + /* write the result code */ + WRITE_INT32(fp,retv); + /* write the entry */ + write_rpcent(fp,&result); + } + /* write the final result code */ + WRITE_INT32(fp,retv); + WRITE_FLUSH(fp); + /* FIXME: if a previous call returns what happens to the context? */ + _nss_ldap_enter(); + _nss_ldap_ent_context_release(rpc_context); + _nss_ldap_leave(); + /* we're done */ + return 0; } @@ -193,6 +193,20 @@ static void printnetgroup(struct __netgrent *netgroup) "}\n"); } +static void printrpc(struct rpcent *rpc) +{ + int i; + printf("struct rpcent {\n" + " r_name=\"%s\",\n", + rpc->r_name); + for (i=0;rpc->r_aliases[i]!=NULL;i++) + printf(" r_aliases[%d]=\"%s\",\n", + i,rpc->r_aliases[i]); + printf(" r_aliases[%d]=NULL,\n" + " r_number=%d\n" + "}\n",i,(int)(rpc->r_number)); +} + /* the main program... */ int main(int argc,char *argv[]) { @@ -204,6 +218,7 @@ int main(int argc,char *argv[]) struct spwd shadowresult; struct __netgrent netgroupresult; struct protoent protoresult; + struct rpcent rpcresult; char buffer[1024]; enum nss_status res; int errnocp,h_errnocp; @@ -231,7 +246,7 @@ int main(int argc,char *argv[]) /* test getpwuid() */ printf("\nTEST getpwuid()\n"); - res=_nss_ldap_getpwuid_r(180,&passwdresult,buffer,1024,&errnocp); + res=_nss_ldap_getpwuid_r(1004,&passwdresult,buffer,1024,&errnocp); printf("status=%s\n",nssstatus(res)); if (res==NSS_STATUS_SUCCESS) printpasswd(&passwdresult); @@ -254,7 +269,7 @@ int main(int argc,char *argv[]) /* test getaliasbyname() */ printf("\nTEST getaliasbyname()\n"); - res=_nss_ldap_getaliasbyname_r("techstaff",&aliasresult,buffer,1024,&errnocp); + res=_nss_ldap_getaliasbyname_r("wij@arthurenhella.demon.nl",&aliasresult,buffer,1024,&errnocp); printf("status=%s\n",nssstatus(res)); if (res==NSS_STATUS_SUCCESS) printalias(&aliasresult); @@ -394,7 +409,7 @@ int main(int argc,char *argv[]) /* test ether_hostton() */ printf("\nTEST ether_hostton()\n"); - res=_nss_ldap_gethostton_r("appelscha",ðerresult,buffer,1024,&errnocp); + res=_nss_ldap_gethostton_r("spiritus",ðerresult,buffer,1024,&errnocp); printf("status=%s\n",nssstatus(res)); if (res==NSS_STATUS_SUCCESS) printether(ðerresult); @@ -403,7 +418,7 @@ int main(int argc,char *argv[]) /* test ether_ntohost() */ printf("\nTEST ether_ntohost()\n"); - res=_nss_ldap_getntohost_r(ether_aton("0:13:72:a4:39:c7"), + res=_nss_ldap_getntohost_r(ether_aton("00:E0:4C:39:D3:6A"), ðerresult,buffer,1024,&errnocp); printf("status=%s\n",nssstatus(res)); if (res==NSS_STATUS_SUCCESS) @@ -494,5 +509,37 @@ int main(int argc,char *argv[]) res=_nss_ldap_endprotoent(); printf("status=%s\n",nssstatus(res)); + /* test getrpcbyname() */ + printf("\nTEST getrpcbyname()\n"); + res=_nss_ldap_getrpcbyname_r("rpcfoo",&rpcresult,buffer,1024,&errnocp); + printf("status=%s\n",nssstatus(res)); + if (res==NSS_STATUS_SUCCESS) + printrpc(&rpcresult); + else + printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp)); + + /* test getrpcbynumber() */ + printf("\nTEST getrpcbynumber()\n"); + res=_nss_ldap_getrpcbynumber_r(7899,&rpcresult,buffer,1024,&errnocp); + printf("status=%s\n",nssstatus(res)); + if (res==NSS_STATUS_SUCCESS) + printrpc(&rpcresult); + else + printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp)); + + /* test {set,get,end}rpcent() */ + printf("\nTEST {set,get,end}rpcent()\n"); + res=_nss_ldap_setrpcent(1); + printf("status=%s\n",nssstatus(res)); + while ((res=_nss_ldap_getrpcent_r(&rpcresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS) + { + printf("status=%s\n",nssstatus(res)); + printrpc(&rpcresult); + } + printf("status=%s\n",nssstatus(res)); + printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp)); + res=_nss_ldap_endrpcent(); + printf("status=%s\n",nssstatus(res)); + return 0; } |