X-Git-Url: https://git.distorted.org.uk/~mdw/become/blobdiff_plain/ffdb9474d2cc2a32d0d9bcbbdb4463252142162e..9e5602f0603b771fdda16731ab5bf6e460fe8795:/src/daemon.c diff --git a/src/daemon.c b/src/daemon.c index 5b5df85..61638df 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: daemon.c,v 1.5 1997/08/20 16:17:10 mdw Exp $ + * $Id: daemon.c,v 1.8 1997/09/26 09:14:58 mdw Exp $ * * Running a `become' daemon * @@ -29,7 +29,21 @@ /*----- Revision history --------------------------------------------------* * * $Log: daemon.c,v $ - * Revision 1.5 1997/08/20 16:17:10 mdw + * Revision 1.8 1997/09/26 09:14:58 mdw + * Merged blowfish branch into trunk. + * + * Revision 1.7.2.1 1997/09/26 09:08:05 mdw + * Use the Blowfish encryption algorithm instead of IDEA. This is partly + * because I prefer Blowfish (without any particularly strong evidence) but + * mainly because IDEA is patented and Blowfish isn't. + * + * Revision 1.7 1997/09/17 10:23:23 mdw + * Fix a typo. Port numbers are in network order now, so don't change them. + * + * Revision 1.6 1997/09/09 18:17:06 mdw + * Allow default port to be given as a service name or port number. + * + * Revision 1.5 1997/08/20 16:17:10 mdw * More sensible restart routine: `_reinit' functions replaced by `_end' and * `_init' functions. * @@ -73,10 +87,10 @@ /* --- Local headers --- */ #include "become.h" +#include "blowfish.h" #include "config.h" #include "crypt.h" #include "daemon.h" -#include "idea.h" #include "lexer.h" #include "name.h" #include "netg.h" @@ -97,7 +111,7 @@ static int daemon__port = -1; /* No particular port yet */ static volatile sig_atomic_t daemon__rescan = 0; /* Rescan as soon as poss */ #define daemon__signum daemon__rescan /* Alias for readbility */ static int daemon__readKey = 0; /* Have I read a key? */ -static unsigned char daemon__key[IDEA_KEYSIZE]; /* encryption key */ +static unsigned char daemon__key[BLOWFISH_KEYSIZE]; /* Encryption key */ static jmp_buf daemon__dieBuf; /* Jump here to kill the daemon */ /*----- Main code ---------------------------------------------------------*/ @@ -213,7 +227,7 @@ void daemon__read(int fd) unsigned char rpl[crp_size]; /* Buffer for outgoing replies */ struct sockaddr_in sin; /* Address of packet sender */ char sender[64]; /* Sender's hostname (resolved) */ - unsigned char sk[IDEA_KEYSIZE]; /* Session key for reply */ + unsigned char sk[BLOWFISH_KEYSIZE]; /* Session key for reply */ request rq; /* Request buffer for verification */ /* --- Read the message --- */ @@ -319,11 +333,11 @@ void daemon_init(const char *cf, int port) * look it up in /etc/services under whatever name I was started as. */ - if (daemon__port <= 0) { + if (daemon__port == 0) { struct servent *se = getservbyname(quis(), "udp"); if (!se) - die("no idea which port to use"); - daemon__port = ntohs(se->s_port); + die("no idea which port to listen to"); + daemon__port = se->s_port; } /* --- Now set up a socket --- */ @@ -334,10 +348,12 @@ void daemon_init(const char *cf, int port) if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1) die("couldn't create socket: %s", strerror(errno)); sin.sin_family = AF_INET; - sin.sin_port = htons(daemon__port); + sin.sin_port = daemon__port; sin.sin_addr.s_addr = htonl(INADDR_ANY); - if (bind(s, (struct sockaddr *)&sin, sizeof(sin))) - die("couldn't bind socket to port: %s", strerror(errno)); + if (bind(s, (struct sockaddr *)&sin, sizeof(sin))) { + die("couldn't bind socket to port %i: %s", + ntohs(daemon__port), strerror(errno)); + } } /* --- Fork off into the sunset --- */