split fmt_ldapadl into fmt_ldapadl and fmt_ldapavl (the former is a
SEQUENCE used in search requests, the latter is a SET used in search results)
This commit is contained in:
12
asn1.h
12
asn1.h
@@ -61,22 +61,22 @@ int fmt_asn1transparent(char* dest,enum asn1_tagclass tc,enum asn1_tagtype tt,en
|
||||
int fmt_asn1string(char* dest,enum asn1_tagclass tc,enum asn1_tagtype tt,enum asn1_tag tag,const char* c,unsigned long l);
|
||||
|
||||
/* write ASN.1 OCTET STRING */
|
||||
#define fmt_asn1OCTETSTRING(dest,c,l) fmt_asn1string(dest,UNIVERSAL,PRIMITIVE,OCTET_STRING,c,l);
|
||||
#define fmt_asn1OCTETSTRING(dest,c,l) fmt_asn1string(dest,UNIVERSAL,PRIMITIVE,OCTET_STRING,c,l)
|
||||
|
||||
/* write ASN.1 INTEGER */
|
||||
#define fmt_asn1INTEGER(dest,l) fmt_asn1int(dest,UNIVERSAL,PRIMITIVE,INTEGER,l);
|
||||
#define fmt_asn1INTEGER(dest,l) fmt_asn1int(dest,UNIVERSAL,PRIMITIVE,INTEGER,l)
|
||||
|
||||
/* write ASN.1 BOOLEAN */
|
||||
#define fmt_asn1BOOLEAN(dest,l) fmt_asn1int(dest,UNIVERSAL,PRIMITIVE,BOOLEAN,l);
|
||||
#define fmt_asn1BOOLEAN(dest,l) fmt_asn1int(dest,UNIVERSAL,PRIMITIVE,BOOLEAN,l)
|
||||
|
||||
/* write ASN.1 ENUMERATED */
|
||||
#define fmt_asn1ENUMERATED(dest,l) fmt_asn1int(dest,UNIVERSAL,PRIMITIVE,ENUMERATED,l);
|
||||
#define fmt_asn1ENUMERATED(dest,l) fmt_asn1int(dest,UNIVERSAL,PRIMITIVE,ENUMERATED,l)
|
||||
|
||||
/* write ASN.1 SEQUENCE */
|
||||
#define fmt_asn1SEQUENCE(dest,l) fmt_asn1transparent(dest,UNIVERSAL,CONSTRUCTED,SEQUENCE_OF,l);
|
||||
#define fmt_asn1SEQUENCE(dest,l) fmt_asn1transparent(dest,UNIVERSAL,CONSTRUCTED,SEQUENCE_OF,l)
|
||||
|
||||
/* write ASN.1 SET */
|
||||
#define fmt_asn1SET(dest,l) fmt_asn1transparent(dest,UNIVERSAL,CONSTRUCTED,SET_OF,l);
|
||||
#define fmt_asn1SET(dest,l) fmt_asn1transparent(dest,UNIVERSAL,CONSTRUCTED,SET_OF,l)
|
||||
|
||||
|
||||
/* conventions for the parser routines:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "asn1.h"
|
||||
#include "ldap.h"
|
||||
|
||||
int fmt_ldapadl(char* dest,struct AttributeDescriptionList* adl) {
|
||||
static int doit(char* dest,struct AttributeDescriptionList* adl,int seq) {
|
||||
struct AttributeDescriptionList* x=adl;
|
||||
long sum=0;
|
||||
int tmp;
|
||||
@@ -9,7 +9,10 @@ int fmt_ldapadl(char* dest,struct AttributeDescriptionList* adl) {
|
||||
sum+=fmt_asn1OCTETSTRING(0,0,x->a.l);
|
||||
x=x->next;
|
||||
}
|
||||
tmp=fmt_asn1SEQUENCE(dest,sum);
|
||||
if (seq)
|
||||
tmp=fmt_asn1SEQUENCE(dest,sum);
|
||||
else
|
||||
tmp=fmt_asn1SET(dest,sum);
|
||||
sum+=tmp;
|
||||
if (dest) {
|
||||
dest+=tmp;
|
||||
@@ -22,3 +25,10 @@ int fmt_ldapadl(char* dest,struct AttributeDescriptionList* adl) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
int fmt_ldapadl(char* dest,struct AttributeDescriptionList* adl) {
|
||||
return doit(dest,adl,1);
|
||||
}
|
||||
|
||||
int fmt_ldapavl(char* dest,struct AttributeDescriptionList* adl) {
|
||||
return doit(dest,adl,0);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ int fmt_ldappal(char* dest,struct PartialAttributeList* pal) {
|
||||
if (!pal) return 0;
|
||||
sum=fmt_ldapstring(0,&pal->type);
|
||||
/* look how much space the adl needs */
|
||||
l=fmt_ldapadl(0,pal->values);
|
||||
l=fmt_ldapavl(0,pal->values);
|
||||
/* write sequence header */
|
||||
l2=fmt_asn1SEQUENCE(dest,l+sum);
|
||||
if (dest) {
|
||||
@@ -16,7 +16,7 @@ int fmt_ldappal(char* dest,struct PartialAttributeList* pal) {
|
||||
}
|
||||
sum+=l+l2;
|
||||
if (dest) {
|
||||
fmt_ldapadl(dest,pal->values);
|
||||
fmt_ldapavl(dest,pal->values);
|
||||
dest+=l;
|
||||
}
|
||||
return sum+fmt_ldappal(dest,pal->next);
|
||||
|
||||
1
ldap.h
1
ldap.h
@@ -102,6 +102,7 @@ int fmt_ldapresult(char* dest,long result,char* matcheddn,char* errormessage,cha
|
||||
int fmt_ldappal(char* dest,struct PartialAttributeList* pal);
|
||||
int fmt_ldapava(char* dest,struct AttributeValueAssertion* a);
|
||||
int fmt_ldapadl(char* dest,struct AttributeDescriptionList* adl);
|
||||
int fmt_ldapavl(char* dest,struct AttributeDescriptionList* adl);
|
||||
|
||||
#define fmt_ldapbindresponse(a,b,c,d,e) fmt_ldapresult(a,b,c,d,e)
|
||||
#define fmt_ldapsearchresultdone(a,b,c,d,e) fmt_ldapresult(a,b,c,d,e)
|
||||
|
||||
14
ldapclient.c
14
ldapclient.c
@@ -9,6 +9,8 @@
|
||||
#include "ip4.h"
|
||||
#include "str.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#define BUFSIZE 8192
|
||||
|
||||
static long messageid=1;
|
||||
@@ -68,12 +70,12 @@ usage:
|
||||
adl.a.s=argv[i];
|
||||
adl.a.l=strlen(argv[i]);
|
||||
next=&adl;
|
||||
++i;
|
||||
while (i<argc) {
|
||||
struct AttributeDescriptionList *n;
|
||||
n=malloc(sizeof(struct AttributeDescriptionList));
|
||||
n->a.s=argv[i]; n->a.l=strlen(argv[i]);
|
||||
n->next=0;
|
||||
next->next=n;
|
||||
n->next=next;
|
||||
next=n;
|
||||
i++;
|
||||
}
|
||||
@@ -113,6 +115,14 @@ usage:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
int fd=open("/tmp/searchresultentry",O_WRONLY|O_CREAT,0600);
|
||||
write(fd,buf+tmp2,max-buf+tmp2);
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
if ((tmp=scan_ldapsearchresultentry(buf+tmp2,max,&sre))) {
|
||||
struct PartialAttributeList* pal=sre.attributes;
|
||||
buffer_puts(buffer_1,"objectName \"");
|
||||
|
||||
57
tinyldap.c
57
tinyldap.c
@@ -11,6 +11,8 @@
|
||||
#include <wait.h>
|
||||
#endif
|
||||
|
||||
static int verbose=0;
|
||||
|
||||
#define BUFSIZE 8192
|
||||
|
||||
int handle(int in,int out) {
|
||||
@@ -21,18 +23,20 @@ int handle(int in,int out) {
|
||||
int res;
|
||||
long messageid,op,Len;
|
||||
if (tmp==0)
|
||||
if (!len) { write(2,"eof!\n",5); return 0; }
|
||||
if (!len) { return 0; }
|
||||
if (tmp<0) { write(2,"error!\n",7); return 1; }
|
||||
len+=tmp;
|
||||
res=scan_ldapmessage(buf,buf+len,&messageid,&op,&Len);
|
||||
if (res>0) {
|
||||
buffer_puts(buffer_2,"got message of length ");
|
||||
buffer_putulong(buffer_2,Len);
|
||||
buffer_puts(buffer_2," with id ");
|
||||
buffer_putulong(buffer_2,messageid);
|
||||
buffer_puts(buffer_2,": op ");
|
||||
buffer_putulong(buffer_2,op);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
if (verbose) {
|
||||
buffer_puts(buffer_2,"got message of length ");
|
||||
buffer_putulong(buffer_2,Len);
|
||||
buffer_puts(buffer_2," with id ");
|
||||
buffer_putulong(buffer_2,messageid);
|
||||
buffer_puts(buffer_2,": op ");
|
||||
buffer_putulong(buffer_2,op);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
}
|
||||
switch (op) {
|
||||
case BindRequest:
|
||||
{
|
||||
@@ -41,13 +45,15 @@ int handle(int in,int out) {
|
||||
int tmp;
|
||||
tmp=scan_ldapbindrequest(buf+res,buf+res+len,&version,&name,&method);
|
||||
if (tmp>=0) {
|
||||
buffer_puts(buffer_2,"bind request: version ");
|
||||
buffer_putulong(buffer_2,version);
|
||||
buffer_puts(buffer_2," for name \"");
|
||||
buffer_put(buffer_2,name.s,name.l);
|
||||
buffer_puts(buffer_2,"\" with method ");
|
||||
buffer_putulong(buffer_2,method);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
if (verbose) {
|
||||
buffer_puts(buffer_2,"bind request: version ");
|
||||
buffer_putulong(buffer_2,version);
|
||||
buffer_puts(buffer_2," for name \"");
|
||||
buffer_put(buffer_2,name.s,name.l);
|
||||
buffer_puts(buffer_2,"\" with method ");
|
||||
buffer_putulong(buffer_2,method);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
}
|
||||
{
|
||||
char outbuf[1024];
|
||||
int s=100;
|
||||
@@ -145,16 +151,20 @@ nomem:
|
||||
long l=fmt_ldapsearchresultentry(0,&sre);
|
||||
char *buf=alloca(l+300); /* you never know ;) */
|
||||
long tmp;
|
||||
buffer_puts(buffer_2,"sre len ");
|
||||
buffer_putulong(buffer_2,l);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
if (verbose) {
|
||||
buffer_puts(buffer_2,"sre len ");
|
||||
buffer_putulong(buffer_2,l);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
}
|
||||
tmp=fmt_ldapmessage(buf,messageid,SearchResultEntry,l);
|
||||
fmt_ldapsearchresultentry(buf+tmp,&sre);
|
||||
write(out,buf,l+tmp);
|
||||
}
|
||||
buffer_puts(buffer_2,"found: ");
|
||||
buffer_puts(buffer_2,r->dn);
|
||||
buffer_putsflush(buffer_2,"\n");
|
||||
if (verbose) {
|
||||
buffer_puts(buffer_2,"found: ");
|
||||
buffer_puts(buffer_2,r->dn);
|
||||
buffer_putsflush(buffer_2,"\n");
|
||||
}
|
||||
}
|
||||
r=r->next;
|
||||
}
|
||||
@@ -227,6 +237,11 @@ int main() {
|
||||
buffer_putsflush(buffer_2,"accept failed!\n");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
handle(asock,asock);
|
||||
exit(0);
|
||||
#else
|
||||
#endif
|
||||
switch (fork()) {
|
||||
case -1: buffer_putsflush(buffer_2,"fork failed!\n"); exit(1);
|
||||
case 0: /* child */
|
||||
|
||||
Reference in New Issue
Block a user