Network byte order

Note to self:

Όταν διαβάζεις πακέτα από το καλώδιο να θυμάσαι πως οι τιμές στα headers είναι σε network byte order. Γι’αυτό και εκεί που περιμένεις 53 διαβάζεις 13568 (256 * 53). Τα παλικάρια που φτιάξανε το ntohs(3) κάτι ξέρανε.

Read the source Luke – part 1

A fellow (and very competent) postmaster of an extremely high traffic ISP (by Greek standards) dropped me a note asking me whether I had seen the following error message:

Jan 25 11:07:43 XXXXXXXXXXX sm-mta[21622]: l0M7JEYx016921: SYSERR(root): Error in ldap_search using user@YYYYYYYYYYYY.gr in map ldapmra: Unknown error 325

Being the LDAP hater that I am, I had never encountered it. Googling arround did not result in anything meaningful. So the next step was to read the source code:

First I downloaded and uncpaked the latest sendmail (8.13.8) and openldap (2.3.32) sources. Now where do I start? The error message points where:

Inside the sendmail-8.13.8 directory:

$ grep -r "Error in ldap_search" .
./sendmail/map.c: syserr("Error in ldap_search using %s in map %s",
./sendmail/map.c: syserr("451 4.3.5 Error in ldap_search using %s in map %s",

syserr() is called when sm_ldap_search() fails and errno is set by calling sm_ldap_geterrno():

errno = sm_ldap_geterrno(lmap->ldap_ld) + E_LDAPBASE;

What is E_LDAPBASE? We find it defined in include/sm/errstring.h:

#define E_LDAPBASE (E_PSEUDOBASE + 70)

OK, now what is E_PSEUDOBASE? We find it defined again in include/sm/errstring.h:

#ifndef E_PSEUDOBASE
# define E_PSEUDOBASE 256
#endif /* ! E_PSEUDOBASE */

Hmm… the valuse of E_LDAPBASE is 256 + 70 = 326? Now does this not look familiar? So what makes sm_ldap_geterrno() return -1?

$ grep -r ^sm_ldap_geterrno .
./libsm/ldap.c:sm_ldap_geterrno(ld)

sm_ldap_geterrno() basically calls:

(void) ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &err);

and returns the value of err.

Now we switch to the openldap-2.3.32 source directory:

$ grep -r ^ldap_get_option .
:
./libraries/libldap/options.c:ldap_get_option(

from which we find out that in our case it returns the following value:

* (int *) outvalue = ld->ld_errno;

So who sets the value of ld->ld_errno to -1? Back in the sendmail sources we see that we followed this branch of the code because of a call to sm_ldap_search():

$ grep -r ^sm_ldap_search() .
./libsm/ldap.c:sm_ldap_search(lmap, key)

sm_ldap_search returns the value of a call to ldap_search(). Switching back to openldap’s sources:

$ grep -r ^ldap_search .
:
./libraries/libldap/search.c:ldap_search(
:

ldap_search() returns the result of ldap_send_initial_request():

$ grep -r ^ldap_send_initial_request
./libraries/libldap/request.c:ldap_send_initial_request(

which in turns returns the result of ldap_server_request():

$ grep -r ^ldap_send_server_request .
./libraries/libldap/request.c:ldap_send_server_request(

It sets ld_errno to -1 in two cases. The first is when it sets it to LDAP_SERVER_DOWN (which is #defined as (-1) in ldap.h) and when ldap_int_flush_request() fails returning -1:

$ grep -r ^ldap_int_flush_request .
./libraries/libldap/request.c:ldap_int_flush_request(

ldap_int_flush_request() returns -1 when ber_flush() fails and sets ld_errno to LDAP_SERVER_DOWN.

So there:

Unknown error 325 means that your sendmail cannot talk to your LDAP server because sendmail thinks that slapd is down.

Or not?

(part2)

ConceptBase 7.0 released!

ConceptBase 7.0 is capable to manage large models with literally hundreds of thousands of concepts. Earlier versions already greatly supported the meta modeling of conceptual modeling languages. With the new release, you can also start to define semantics of dynamic modeling languages and use the configurable graph editor to visualize models and their use.

[via]

haskell and parallel programming

Ο Simon Peyton Jones γράφει ένα κεφάλαιο [PostScript document] για το βιβλίο Beautiful Code που γράφει ο Greg Wilson. Μια και δεν είμαι καλός γνώστης της Haskell, διάβασα το κείμενο διαγώνια. Εντυπωσιακή όμως ήταν η πρώτη παράγραφος:

“Intel tells us that the free lunch is over [7]. We can no longer expect our programs to go faster when we buy a next-generation processor. While that next-generation chip will have more CPUs, each individual CPU will be no faster than the previous year’s model. If we want our program to run faster, we must learn to write parallel programs [8].”

[7] – Your free lunch will soon be over
[8] – Software and the Concurrency Revolution

Έχω δύο βιβλία για τη Haskell στο σπίτι (τα οποία μαζεύουν σκόνη καιρό τώρα). Ελπίζω να (ξανα)ξεκινήσω αυτό του Hudak τον επόμενο μήνα. Επί τη ευκαιρία και ένα blog post που εξηγεί γιατί η Haskell είναι cool.

[via LtU]

semiskilled programmers

Από το blog της Νατάσας μπορεί να βρει κανείς το δρόμο για δύο συνεντεύξεις του Stroustrup. H Νατάσα επισημαίνει το ακόλουθο απόσπασμα:

“The idea of programming as a semiskilled task, practiced by people with a few months’ training, is dangerous. We wouldn’t tolerate plumbers or accountants that poorly educated. We don’t have as an aim that architecture (of buildings) and engineering (of bridges and trains) should become more accessible to people with progressively less training. Indeed, one serious problem is that currently, too many software developers are undereducated and undertrained.”

Είπεν όμως ο Κύριος ακόμα:

  • Most people don’t actually read code; they just see Internet Explorer “freeze.”
  • People reward developers who deliver software that is cheap, buggy, and first.

Συνδιάστε τα παραπάνω με το “war story” που άκουσα την Πέμπτη:

Εστιατόριο που κάνει και delivery από τότε που εγκατέστησε software διαχείρισης παραγγελιών, “χάνει” τις παραγγελίες ή τις καταχωρεί λάθος. Τέλος πάντων αντί να έχει καλύτερο service η επιχείρηση, καταφέρνει να έχει πολύ χειρότερο. Στον φίλο μου που διαμαρτυρήθηκε για το γεγονός, η μαγείρισσα είπε:

– Οι προγραμματιστές μας είπαν πως το πρόγραμμα χάνει τις παραγγελίες γιατί έχουμε πολλά αντικείμενα!

Έτσι χαλάει η πιάτσα: Wizard Engineering και ότι βγει.

*Now listening: Trading War Stories by Tupak Shakur*

SQO-OSS

SQO-OSS aims to assist European software developers in improving the quality of their code, and to remove one of the key barriers to entry for Open Source software by providing scientific proof of its quality.”

[via]