Skip to content

Commit

Permalink
Created typed sending operations like lillyput_BindRequest()
Browse files Browse the repository at this point in the history
These are now used in the test lillypass 3.  Test 4 remains unimplemented.
  • Loading branch information
vanrein committed Jan 30, 2017
1 parent 6ae4440 commit 4c11ac0
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 196 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ endif()
#TODO# Test that the output matches expectations
foreach (netpkg ${netpkgs})
get_filename_component (netpkgname ${netpkg} NAME)
foreach (level 0 1 2) #TODO# 3 4
foreach (level 0 1 2 3) #TODO# 4
add_test (
NAME lillypass-level${level}-netpkg-${netpkgname}
COMMAND lillypass.test ${level} ${netpkg}
Expand Down
9 changes: 4 additions & 5 deletions INSTALL.MD
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ override. Or, to automate this choice, you could use
We advise out-of-source builds, even though we have a few items on our
TODO list that require preparations inside the code tree for now.

cd lillydap
mkdir build
cd build
mkdir /tmp/build
cd /tmp/build

In this build directory, configure using defaults, or use a variant as
described under configuration. You need to reference the source tree
relative to the build directory, so `..` after the preparation above,

cmake ..
cmake /path/to/lillydap

Then proceed to building,

make
cmake --build .

You can now run the package's tests,

Expand Down
8 changes: 8 additions & 0 deletions UTILITIES.MD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Do not rely on this if efficiency or scalability are among your concerns.

## TLS Utilities

**TODO**

These utilities implement the StartTLS operation, in the service of
encryption and possibly authentication. One implementation works
by passing control over the
Expand All @@ -33,6 +35,8 @@ and harvest the remote identity as an authenticated identity.

## Authentication Utilities

**TODO**

These utilities help with the Bind and Unbind operations. Versions for the
client and server side exist. There is no support for Simple authantication,
but SASL is supported.
Expand All @@ -50,6 +54,8 @@ operation is also included in the utilities.

## Authorisation Utilities

**TODO**

There is an option in LDAP to authorise a user identity after authentication,
based on the control for
[Proxied Authorization](https://tools.ietf.org/html/rfc4370)
Expand All @@ -60,6 +66,8 @@ operation.

## Utility Support for InternetWide / ARPA2

**TODO**

The utilities described above integrate well with the ARPA2 projects,
making this fit in with the InternetWide Architecture, in the following
ways:
Expand Down
31 changes: 31 additions & 0 deletions include/lillydap/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,35 @@ typedef union LillyOpRegistry {
} by_name;
} LillyOpRegistry;

#define putop(opcd,opnm) static inline lillyput_##opnm (LDAP *lil, \
LillyPool qpool, const LillyMsgId mid, \
const LillyPack_##opnm *arg, const dercursor ctl) { \
return lillyput_operation (lil, qpool, mid, \
opcd, \
(const dercursor *) arg, \
ctl); \
}
putop (0, BindRequest)
putop (1, BindResponse)
putop (2, UnbindRequest)
putop (3, SearchRequest)
putop (4, SearchResultEntry)
putop (5, SearchResultDone)
putop (6, ModifyRequest)
putop (7, ModifyResponse)
putop (8, AddRequest)
putop (9, AddResponse)
putop (10, DelRequest)
putop (11, DelResponse)
putop (12, ModifyDNRequest)
putop (13, ModifyDNResponse)
putop (14, CompareRequest)
putop (15, CompareResponse)
putop (16, AbandonRequest)
putop (19, SearchResultReference)
putop (23, ExtendedRequest)
putop (24, ExtendedResponse)
putop (25, IntermediateResponse)


#endif /* LILLYDAP_H */
17 changes: 13 additions & 4 deletions lib/msgop.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ int lillyput_operation (LDAP *lil,
}
dermsg.derlen = totlen;
//
// Perform the actual packing in the now-prepared buffer
// Start counting totlen from 0 and hope to find the same again
totlen = 0;
//
// If controls were provided, add them
if (controls.derptr != NULL) {
memcpy (dermsg.derptr + dermsg.derlen - controls.derlen,
Expand All @@ -219,13 +223,18 @@ int lillyput_operation (LDAP *lil,
controls.derlen));
}
//
// Perform the actual packing in the now-prepared buffer
// Start counting totlen from 0 and hope to find the same again
totlen = 0;
// Precede with the packed data
totlen += der_pack (opcode_table [opcode].pck_message,
data,
dermsg.derptr + dermsg.derlen - totlen);
//
// Exceptional -- due to IMPLICIT TAGS
// If packaging started with DER_PACK_STORE, we may need to set
// the flag that this is a composite field (but not when empty)
if (dermsg.derptr [1 + dermsg.derlen - totlen] > 0) {
dermsg.derptr [0 + dermsg.derlen - totlen] |= 0x20;
}
//
// Prefix the MessageID
mid = msgid;
uint8_t midlen = 0;
Expand All @@ -242,7 +251,7 @@ int lillyput_operation (LDAP *lil,
totlen = qder2b_prefixhead (dermsg.derptr + dermsg.derlen - totlen,
DER_TAG_SEQUENCE | 0x20,
totlen);
#if 1
#if 0
if (totlen != dermsg.derlen) {
fprintf (stderr, "ERROR: Reproduced length %zd instead of %zd\n", totlen, dermsg.derlen);
}
Expand Down
199 changes: 13 additions & 186 deletions test/lillypass.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
* 0. Directly pass LDAPMessage chunks as a dercursor
* 1. Pass a LDAPMessage after splitting into request, opcode and controls
* 2. Pass LDAP operations with unpacked data, but use the same code for each
* 3. Pass LDAP operations through individual operations (big risk of ENOSYS)
* 3. Pass LDAP operations through individual operations (chance of ENOSYS)
* 4. The LDAP operations unpack the controls, and later pack them again
*
* TODO: level 3 still does what it did in lillydump.
* TODO: level 4 has not been implemented yet.
*
* Reading / writing is highly structured, so it can be used for testing.
Expand All @@ -39,177 +38,6 @@
#include <quick-der/api.h>


int lillypass_BindRequest (LDAP *lil,
LillyPool qpool,
const LillyMsgId msgid,
const LillyPack_BindRequest *br,
const dercursor controls) {
printf ("Got BindRequest\n");
printf (" - version in %d bytes %02x,...\n", br->version.derlen, br->version.derptr [0]);
printf (" - name \"%.*s\"\n", br->name.derlen, br->name.derptr);
if (br->authentication.simple.derptr != NULL) {
printf (" - simple authentication with \"%.*s\"\n", br->authentication.simple.derlen, br->authentication.simple.derptr);
}
if (br->authentication.sasl.mechanism.derptr != NULL) {
printf (" - SASL mechanism \"%.*s\"\n", br->authentication.sasl.mechanism.derlen, br->authentication.sasl.mechanism.derptr);
if (br->authentication.sasl.credentials.derptr != NULL) {
printf (" - SASL credentias \"%.*s\"\n", br->authentication.sasl.credentials.derlen, br->authentication.sasl.credentials.derptr);
}
}
return 0;
}

int lillypass_BindResponse (LDAP *lil,
LillyPool qpool,
const LillyMsgId msgid,
const LillyPack_BindResponse *br,
const dercursor controls) {
printf ("Got BindResponse\n");
printf (" - resultCode in %d bytes %02x,%02x,%02x,%02x,...\n", br->resultCode.derlen, br->resultCode.derptr [0], br->resultCode.derptr [1], br->resultCode.derptr [2], br->resultCode.derptr [3]);
printf (" - matchedDN \"%.*s\"\n", br->matchedDN.derlen, br->matchedDN.derptr);
printf (" - diagnosticMessage \"%.*s\"\n", br->diagnosticMessage.derlen, br->diagnosticMessage.derptr);
return 0;
}

int lillypass_UnbindRequest (LDAP *lil,
LillyPool qpool,
const LillyMsgId msgid,
const LillyPack_UnbindRequest *ur,
const dercursor controls) {
printf ("Got UnbindRequest\n");
printf (" - payload length is %s\n", (ur->derptr == NULL) ? "absent": (ur->derlen == 0) ? "empty" : "filled?!?");
return 0;
}

int lillypass_SearchRequest (LDAP *lil,
LillyPool qpool,
const LillyMsgId msgid,
const LillyPack_SearchRequest *sr,
const dercursor controls) {
printf ("Got SearchRequest\n");
printf (" - baseObject \"%.*s\"\n", sr->baseObject.derlen, sr->baseObject.derptr);
if (sr->scope.derlen != 1) {
printf (" ? scope has awkward size %zd instead of 1\n", sr->scope.derlen);
} else {
switch (*sr->scope.derptr) {
case 0:
printf (" - scope base\n");
break;
case 1:
printf (" - scope one\n");
break;
case 2:
printf (" - scope sub\n");
break;
default:
printf (" ? scope weird value %d instead of 0, 1 or 2\n", *sr->scope.derptr);
}
}
if (sr->derefAliases.derlen != 1) {
printf (" ? derefAliases has awkward size %zd instead of 1\n", sr->derefAliases.derlen);
} else {
switch (*sr->derefAliases.derptr) {
case 0:
printf (" - derefAliases neverDerefAlias\n");
break;
case 1:
printf (" - derefAliases derefInSearching\n");
break;
case 2:
printf (" - derefAliases derefFindingBaseObj\n");
break;
case 3:
printf (" - derefAliases derefAlways\n");
break;
default:
printf (" ? derefAliases weird value %d instead of 0, 1, 2 or 3\n", *sr->derefAliases.derptr);
}
}
// attributes SEQUENCE OF LDAPString
dercursor attrs = sr->attributes;
printf (" - attributes.derlen = %zd\n", attrs.derlen);
printf (" - attributes.enter.derlen = %zd\n", attrs.derlen);
while (attrs.derlen > 0) {
dercursor attr = attrs;
if (der_focus (&attr)) {
fprintf (stderr, "ERROR while focussing on attribute of SearchRequest: %s\n", strerror (errno));
} else {
printf (" - attr.derlen = %zd\n", attr.derlen);
printf (" - attributes \"%.*s\"\n", attr.derlen, attr.derptr);
}
der_skip (&attrs);
}
return 0;
}

int lillypass_SearchResultEntry (LDAP *lil,
LillyPool qpool,
const LillyMsgId msgid,
const LillyPack_SearchResultEntry *sre,
const dercursor controls) {
printf ("Got SearchResultEntry\n");
printf (" - objectName \"%.*s\"\n", sre->objectName.derlen, sre->objectName.derptr);
// partialAttribute SEQUENCE OF PartialAttribute
dercursor pa = sre->attributes;
der_enter (&pa);
while (pa.derlen > 0) {
dercursor type = pa;
// SEQUENCE { type AttributeDescription,
// vals SET OF AttributeValue }
der_enter (&type);
printf (" - partialAttribute.type \"%.*s\"\n", type.derlen, type.derptr);
der_skip (&pa);
dercursor vals = pa;
der_enter (&vals);
while (vals.derlen > 0) {
dercursor val = vals;
der_enter (&val);
printf (" - value \"%.*s\"\n", val.derlen, val.derptr);
der_skip (&vals);
}
der_skip (&pa);
}
return 0;
}

int lillypass_SearchResultReference (LDAP *lil,
LillyPool qpool,
const LillyMsgId msgid,
const LillyPack_SearchResultReference *srr,
const dercursor controls) {
printf ("Got SearchResultReference\n");
dercursor uris = *srr;
do {
dercursor uri = uris;
der_enter (&uri);
printf (" - URI \"%.*s\"\n", uri.derlen, uri.derptr);
der_skip (&uris);
} while (uris.derlen > 0);
return 0;
}

int lillypass_SearchResultDone (LDAP *lil,
LillyPool qpool,
const LillyMsgId msgid,
const LillyPack_SearchResultDone *srd,
const dercursor controls) {
printf ("Got SearchResultDone\n");
printf (" - resultCode is %zd==1 byte valued %d\n", srd->resultCode.derlen, *srd->resultCode.derptr);
printf (" - matchedDN \"%.*s\"\n", srd->matchedDN.derlen, srd->matchedDN.derptr);
printf (" - diagnosticMessage \"%.*s\"\n", srd->diagnosticMessage.derlen, srd->diagnosticMessage.derptr);
if (srd->referral.derptr != NULL) {
dercursor uris = srd->referral;
do {
dercursor uri = uris;
der_enter (&uri);
printf (" - URI \"%.*s\"\n", uri.derlen, uri.derptr);
der_skip (&uris);
} while (uris.derlen > 0);
}
return 0;
}


void process (LDAP *lil, char *progname, char *derfilename) {
//
// Open the file
Expand Down Expand Up @@ -258,13 +86,13 @@ void setup (void) {

static const LillyOpRegistry opregistry = {
.by_name = {
.BindRequest = lillypass_BindRequest,
.BindResponse = lillypass_BindResponse,
.UnbindRequest = lillypass_UnbindRequest,
.SearchRequest = lillypass_SearchRequest,
.SearchResultEntry = lillypass_SearchResultEntry,
.SearchResultReference = lillypass_SearchResultReference,
.SearchResultDone = lillypass_SearchResultDone,
.BindRequest = lillyput_BindRequest,
.BindResponse = lillyput_BindResponse,
.UnbindRequest = lillyput_UnbindRequest,
.SearchRequest = lillyput_SearchRequest,
.SearchResultEntry = lillyput_SearchResultEntry,
.SearchResultReference = lillyput_SearchResultReference,
.SearchResultDone = lillyput_SearchResultDone,
}
};

Expand Down Expand Up @@ -300,8 +128,8 @@ int main (int argc, char *argv []) {
lil->lillyget_operation =
lil->lillyput_operation = lillyput_operation;
//
// ...and then we turn it back depending on the level
char level = '\0';
// ...and then we gradually turn it back depending on the level
char level = 'X';
if (strlen (argv [1]) == 1) {
level = argv [1] [0];
}
Expand All @@ -313,24 +141,23 @@ int main (int argc, char *argv []) {
case '4':
fprintf (stderr, "%s: Level 4 is not yet implemented\n",
argv [0]);
//TODO// Replace opregistry with control-unpackers-repackers
// and fallthrough...
case '3':
lil->lillyget_operation = lillyget_operation;
lil->opregistry = &opregistry;
// and fallthrough...
case '2':
lil->lillyget_ldapmessage = lillyget_ldapmessage;
// and fallthrough...
case '1':
lil->lillyget_dercursor = lillyget_dercursor;
lil->lillyget_dercursor = lillyget_dercursor;
// and fallthrough...
case '0':
// Keep everything as-is, passing as directly as possible
break;
}
//
// For level 4 we need the operation registry
lil->opregistry = &opregistry;
//
// Allocate a connection pool
lil->cnxpool = lillymem_newpool ();
if (lil->cnxpool == NULL) {
Expand Down

0 comments on commit 4c11ac0

Please sign in to comment.