diff -urN clussed-19990103/CHANGELOG clussed-19990106/CHANGELOG --- clussed-19990103/CHANGELOG Sun Jan 3 15:15:48 1999 +++ clussed-19990106/CHANGELOG Wed Jan 6 01:43:53 1999 @@ -112,4 +112,17 @@ Fixed a bug in pc_19, it stuck looping with a bad callsign or a duplicate node. Made loop detection report the reason for the holding. + +Wed Jan 6 01:42:56 EET 1999 + + Added cs_errno handling in sock_connect and linker's connection part. + Now, if we add gateway functions, we should be able to get the + error messages back to the user. Error logging can be prettier too. + Made pc_16 and pc_19 not call net_useradd or net_nodeadd if all of + the entries were discarded as duplicates or bad callsigns (net_* + would SEGV). Made the net_ functions handle a passed NULL too, just + to be sure. 8-) + Made it compile on linux-2.2.0-pre4/glibc2 (not that it would have + worked, but...). + diff -urN clussed-19990103/INSTALL clussed-19990106/INSTALL --- clussed-19990103/INSTALL Thu Dec 24 18:00:18 1998 +++ clussed-19990106/INSTALL Mon Jan 4 02:36:07 1999 @@ -3,3 +3,12 @@ clussed to be able to network and/or handle user connections, you also need kernel AX.25, NET/ROM or TCP sockets support. + If you don't know how to install this software without more instructions +than this, you probably don't want to try it just yet, since the software +does not have any useful features ready yet. It is only half written, +and really buggy. + + More documentation will follow when the software actually works. +Please do not mail us asking how to install this. + + diff -urN clussed-19990103/af_ax25.c clussed-19990106/af_ax25.c --- clussed-19990103/af_ax25.c Wed Dec 30 03:38:26 1998 +++ clussed-19990106/af_ax25.c Mon Jan 4 02:03:05 1999 @@ -143,6 +143,7 @@ portcall = ax25_config_get_addr(argv[0]); if (!portcall) { + cs_errno = CS_E_INVPORT; log(L_ERR, "ax25_prepare_outgoing(): Invalid port: %s", argv[0]); return -1; } @@ -153,12 +154,14 @@ s->addrlen = sizeof(struct full_sockaddr_ax25); if (bind(s->fd, (struct sockaddr *)&s->sockaddr, s->addrlen) == -1) { - log(L_ERR, "ax25_prepare_outgoing(): AF_AX25: bind(): %s", strerror(errno)); + cs_errno = errno; + log(L_ERR, "ax25_prepare_outgoing(): AF_AX25: bind(): %s", strerror(cs_errno)); return -1; } if (convert_call_arglist(&argv[1], &s->sockaddr.ax25) == -1) { - log(L_ERR, "convert_call_arglist failed: %s", strerror(errno)); + cs_errno = CS_E_INVCALL; + log(L_ERR, "ax25_prepare_outgoing(): convert_call_arglist failed"); return -1; } diff -urN clussed-19990103/af_netrom.c clussed-19990106/af_netrom.c --- clussed-19990103/af_netrom.c Thu Dec 24 17:55:27 1998 +++ clussed-19990106/af_netrom.c Mon Jan 4 02:19:22 1999 @@ -145,6 +145,7 @@ portcall = nr_config_get_addr(argv[0]); if (!portcall) { + cs_errno = CS_E_INVPORT; log(L_ERR, "netrom_prepare_outgoing(): Invalid port: %s", argv[0]); return -1; } @@ -156,17 +157,20 @@ s->addrlen = sizeof(struct full_sockaddr_ax25); if (bind(s->fd, (struct sockaddr *)&s->sockaddr, s->addrlen) == -1) { - log(L_ERR, "netrom_prepare_outgoing(): AF_NETROM: bind(): %s", strerror(errno)); + cs_errno = errno; + log(L_ERR, "netrom_prepare_outgoing(): AF_NETROM: bind(): %s", strerror(cs_errno)); return -1; } if ((np = find_node(argv[1], NULL)) == NULL) { + cs_errno = CS_E_INVNODE; log(L_ERR, "netrom_prepare_outgoing(): No such node: %s", argv[1]); return -1; } if (convert_call(np->call, &s->sockaddr.ax25) == -1) { - log(L_ERR, "convert_call failed: %s", strerror(errno)); + cs_errno = CS_E_INVCALL; + log(L_ERR, "convert_call failed"); return -1; } s->sockaddr.ax25.fsa_ax25.sax25_family = AF_NETROM; Binary files clussed-19990103/base/data/luser.db and clussed-19990106/base/data/luser.db differ diff -urN clussed-19990103/base/etc/links.conf clussed-19990106/base/etc/links.conf --- clussed-19990103/base/etc/links.conf Wed Dec 30 03:42:24 1998 +++ clussed-19990106/base/etc/links.conf Mon Jan 4 02:41:27 1999 @@ -7,7 +7,7 @@ protocol pc script scripts/oh1lzb-1.con -#link pi5ehv-8 -#protocol pc -#script scripts/pi5ehv.con +link pi5ehv-8 +protocol pc +script scripts/pi5ehv.con diff -urN clussed-19990103/base/scripts/oh1lzb-1.con clussed-19990106/base/scripts/oh1lzb-1.con --- clussed-19990103/base/scripts/oh1lzb-1.con Wed Dec 30 03:42:55 1998 +++ clussed-19990106/base/scripts/oh1lzb-1.con Wed Jan 6 01:35:19 1999 @@ -3,5 +3,5 @@ # Connection script for Clusse 0.40 # -ax25 lo0 oh1lzb-1 +netrom nrcl oh1lzb-1 diff -urN clussed-19990103/base/scripts/pi5ehv.con clussed-19990106/base/scripts/pi5ehv.con --- clussed-19990103/base/scripts/pi5ehv.con Tue Dec 29 03:01:39 1998 +++ clussed-19990106/base/scripts/pi5ehv.con Wed Jan 6 01:37:27 1999 @@ -3,10 +3,11 @@ # Connection script for Clusse 0.40 # -ax25 lo0 oh7lzb-2 +#ax25 lo0 oh7lzb-2 +telnet soul.pspt.fi -r "Welcome" -s "telnet soul.pspt.fi" +#r "Welcome" +#s "telnet soul.pspt.fi" r "login:" "Unknown" "refused" "out" s "oh7lzb-1" r "Password:" diff -urN clussed-19990103/cfg_iface.c clussed-19990106/cfg_iface.c --- clussed-19990103/cfg_iface.c Sun Jan 3 15:00:47 1999 +++ clussed-19990106/cfg_iface.c Wed Jan 6 00:09:25 1999 @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff -urN clussed-19990103/cmd_net.c clussed-19990106/cmd_net.c --- clussed-19990103/cmd_net.c Tue Dec 29 02:23:12 1998 +++ clussed-19990106/cmd_net.c Wed Jan 6 00:16:14 1999 @@ -175,18 +175,38 @@ * User listing */ +int show_user(struct csock_t *s, struct nuser_t *nu) +{ + return 0; +} + int cmd_users(struct csock_t *s, int argc, char **argv) { - struct node_t *n; + struct node_t *n, *nonly = NULL; struct nuser_t *u; char st[80]; int i; + if (argc > 1) { + strncpy(st, argv[1], sizeof(st)); + hstrupr(st); + if ((u = guess_nuser((call_t *)st))) { + /* show only this user */ + return show_user(s, u); + } if ((nonly = guess_node((call_t *)st))) { + /* show only users on this node */ + } else { + /* check if in network / local user file */ + } + } + csprintf(s, "Users: %d (max %d) on %d nodes, %d links\n", nuser_count, nuser_max, node_count, link_count); csputs(s, "Node Users\n"); for (n = nodes; (n); n = n->next) { + if ((nonly) && n != nonly) + continue; sprintf(st, "%-9.9s", n->call); i = 0; diff -urN clussed-19990103/csock.c clussed-19990106/csock.c --- clussed-19990103/csock.c Sun Jan 3 15:06:11 1999 +++ clussed-19990106/csock.c Mon Jan 4 02:20:05 1999 @@ -46,8 +46,13 @@ int cs_errno = 0; char *cs_errorstrs[] = { - "No error?", - "NULL" + "Success or unknown error", + "Invalid port", + "Invalid call", + "No such node", + "No such host", + "No such service", + NULL }; /* @@ -79,6 +84,23 @@ return NULL; } +/* + * Convert an csock errno to a string + */ + +char *csstrerror(int errnum) +{ + if (errnum >= 0) + return strerror(errnum); + + errnum = errnum * -1 + CS_E_BASE; + if (errnum > CS_E_MAX || errnum < 0) + errnum = 0; + + return cs_errorstrs[errnum]; +} + + /************************************************************************ **** Socket list management ****************************************** ************************************************************************/ @@ -187,18 +209,25 @@ struct cscomp_t *c = s->comp; int i; - log(L_SINFO, "Socket: Disconnected %s: %s%s%s:%s (%d) (%s)", - afstr(s->af_type), (s->call) ? s->call : "", ((s->node) && (s->call)) ? ":" : "", - (s->node) ? s->node : "", s->port, s->fd, strerror(s->cs_errno)); FD_CLR(s->fd, &readfds); FD_CLR(s->fd, &writefds); close(s->fd); - if (s->disc_handler) { - (*s->disc_handler)(s); - s->disc_handler = NULL; - } else - log(L_ERR, "fd %d: sock_close(): Ouch, no disc_handler defined!"); + if (s->state != css_unknown) { + log(L_SINFO, "Socket: Disconnected %s: %s%s%s%s%s (%d) (%s)", + afstr(s->af_type), + (s->call) ? s->call : "", + ((s->node) && (s->call)) ? ":" : "", + (s->node) ? s->node : "", + (s->port) ? ":" : "", (s->port) ? s->port : "", + s->fd, strerror(s->cs_errno)); + + if (s->disc_handler && s->state != css_unknown) { + (*s->disc_handler)(s); + s->disc_handler = NULL; + } else + log(L_ERR, "fd %d: sock_close(): Ouch, no disc_handler defined!", s->fd); + } *s->prevp = s->next; if (c) { @@ -254,6 +283,7 @@ int i = 0; int fd = -1; + cs_errno = 0; switch (af_type) { @@ -266,11 +296,13 @@ hp = gethostbyname(argv[0]); if (hp == NULL) { log(L_ERR, "sock_connect(): Unknown host %s", argv[0]); + cs_errno = CS_E_NOHOST; goto trouble; } if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - log(L_ERR, "sock_connect(): socket(): Could not get an AF_INET socket: %s", strerror(errno)); + cs_errno = errno; + log(L_ERR, "sock_connect(): socket(): Could not get an AF_INET socket: %s", strerror(cs_errno)); goto trouble; } @@ -294,7 +326,8 @@ s->sockaddr.inet.sin_port = sp->s_port; } if (s->sockaddr.inet.sin_port == 0) { - log(L_ERR, "Unknown service %s", argv[1]); + log(L_ERR, "sock_connect(): Unknown service %s", argv[1]); + cs_errno = CS_E_NOSERV; goto trouble; } s->node = hstrdup(hp->h_name); @@ -312,7 +345,8 @@ #ifdef HAVE_AX25 case AF_AX25: if ((fd = socket(AF_AX25, SOCK_SEQPACKET, 0)) < 0) { - log(L_ERR, "sock_connect(): socket(): Could not get an AF_AX25 socket: %s", strerror(errno)); + cs_errno = errno; + log(L_ERR, "sock_connect(): socket(): Could not get an AF_AX25 socket: %s", strerror(cs_errno)); goto trouble; } @@ -331,7 +365,8 @@ #ifdef HAVE_NETROM case AF_NETROM: if ((fd = socket(AF_NETROM, SOCK_SEQPACKET, 0)) < 0) { - log(L_ERR, "sock_connect(): socket(): Could not get an AF_NETROM socket: %s", strerror(errno)); + cs_errno = errno; + log(L_ERR, "sock_connect(): socket(): Could not get an AF_NETROM socket: %s", strerror(cs_errno)); goto trouble; } @@ -349,6 +384,7 @@ default: log(L_ERR, "Socket: sock_connect() called for unknown af_type"); + cs_errno = EPROTONOSUPPORT; goto trouble; } @@ -361,12 +397,14 @@ */ if (fcntl(s->fd, F_SETFL, O_NONBLOCK) == -1) { - log(L_ERR, "sock_connect(): fcntl O_NONBLOCK failed: %s", strerror(errno)); + cs_errno = errno; + log(L_ERR, "sock_connect(): fcntl O_NONBLOCK failed: %s", strerror(cs_errno)); goto trouble; } if (connect(s->fd, (struct sockaddr *)&s->sockaddr, sizeof(s->sockaddr)) == -1 && errno != EINPROGRESS) { - log(L_ERR, "sock_connect(): connect: %s", strerror(errno)); + cs_errno = errno; + log(L_ERR, "sock_connect(): connect: %s", strerror(cs_errno)); goto trouble; } diff -urN clussed-19990103/csock.h clussed-19990106/csock.h --- clussed-19990103/csock.h Sun Jan 3 14:59:09 1999 +++ clussed-19990106/csock.h Mon Jan 4 02:20:11 1999 @@ -19,6 +19,17 @@ #include "luser.h" #include "login.h" +#define CS_E_BASE -100 +#define CS_E_TO * -1 + CS_E_BASE + +#define CS_E_SUCC 0 CS_E_TO +#define CS_E_INVPORT 1 CS_E_TO +#define CS_E_INVCALL 2 CS_E_TO +#define CS_E_INVNODE 3 CS_E_TO +#define CS_E_NOHOST 4 CS_E_TO +#define CS_E_NOSERV 5 CS_E_TO +#define CS_E_MAX 5 + #define DEF_BUFLEN_IN 10 #define DEF_BUFLEN_AX 256 #define DEF_BUFLEN_NR 1500 @@ -210,6 +221,7 @@ /* Misc */ extern int strtoaf(char *s); +extern char *csstrerror(int errnum); /* For main() */ void csock_init(void); diff -urN clussed-19990103/linker.c clussed-19990106/linker.c --- clussed-19990103/linker.c Sat Dec 26 02:28:52 1998 +++ clussed-19990106/linker.c Mon Jan 4 02:46:29 1999 @@ -254,14 +254,14 @@ lj->ptr = ptr; if (!(lj->f = fopen(lj->script, "r"))) { - log(L_ERR, "Linker: Could not open script %s for reading: %s", + log(L_ERR, "Linker: Failed: Could not open script %s for reading: %s", lj->script, strerror(errno)); lj_free(lj); return 0; } if (read_scriptline(lj)) { - log(L_ERR, "Linker: Empty script file %s, no connection command found.", + log(L_ERR, "Linker: Failed: Empty script file %s, no connection command found.", lj->script); lj_free(lj); return 0; @@ -270,15 +270,14 @@ if (!strcasecmp(lj->argv[0], "compressed")) { compressed = 1; if (read_scriptline(lj)) { - log(L_ERR, "Linker: No connection command after \"compressed\" in %s", - lj->script); + log(L_ERR, "Linker: Script %s failed: No connection command after \"compressed\"", lj->script); lj_free(lj); return 0; } } if ((af_type = strtoaf(lj->argv[0])) == -1) { - log(L_ERR, "Linker: Unknown AF type %s, confusing.", lj->argv[0]); + log(L_ERR, "Linker: Script %s failed: Unknown AF type %s, confusing.", lj->script, lj->argv[0]); lj_free(lj); return 0; } @@ -286,7 +285,7 @@ lj->s = sock_connect(af_type, compressed, lj->argc-1, &lj->argv[1]); if (!lj->s) { - log(L_ERR, "Linker: sock_connect() failed"); + log(L_ERR, "Linker: Script %s failed: Connect failed (%s)", lj->script, csstrerror(cs_errno)); lj_free(lj); return 0; } diff -urN clussed-19990103/net_pc.c clussed-19990106/net_pc.c --- clussed-19990103/net_pc.c Sun Jan 3 15:23:08 1999 +++ clussed-19990106/net_pc.c Mon Jan 4 19:25:54 1999 @@ -575,7 +575,7 @@ int pc_16(struct link_t *l, int argc, char **argv) { struct node_t *n; - struct nuser_t *nu, *nul, **prevp; + struct nuser_t *nu, *nul = NULL, **prevp; char *cm, *hr; int i; int hops; @@ -616,7 +616,8 @@ nu->priviledged = 0; } - net_useradd(nul); + if (nul) + net_useradd(nul); return 0; } @@ -699,7 +700,8 @@ i += 4; } - net_nodeadd(nl); + if (nl) + net_nodeadd(nl); return 0; } diff -urN clussed-19990103/net_user.c clussed-19990106/net_user.c --- clussed-19990103/net_user.c Wed Dec 30 03:52:15 1998 +++ clussed-19990106/net_user.c Mon Jan 4 19:28:34 1999 @@ -141,7 +141,7 @@ p = p->next; } } - if (m != 1) /* Exactly one match */ + if (m != 1) /* Exactly one match? */ return NULL; user = u; strcpy((char *)call, u->call); @@ -226,6 +226,9 @@ void net_useradd(struct nuser_t *nu) { struct nuser_t *ul, *p, *next; + + if (!nu) + return; ul = p = nu; p->prevp = &ul; diff -urN clussed-19990103/net_user.h clussed-19990106/net_user.h --- clussed-19990103/net_user.h Wed Dec 30 03:52:10 1998 +++ clussed-19990106/net_user.h Sun Jan 3 16:44:23 1999 @@ -25,6 +25,7 @@ extern struct nuser_t *get_nuser(call_t *call); /* Find user */ extern struct nuser_t *get_nuserh(call_t *call, struct node_t *node); /* Find user on node */ +extern struct nuser_t *guess_nuser(call_t *call); /* guess user */ extern void net_here(struct link_t *forml, call_t *call); /* User here */ extern void net_away(struct link_t *froml, call_t *call, char *reason); /* User away */ diff -urN clussed-19990103/network.c clussed-19990106/network.c --- clussed-19990103/network.c Sun Jan 3 15:14:25 1999 +++ clussed-19990106/network.c Mon Jan 4 19:28:17 1999 @@ -127,6 +127,38 @@ } /* + * Guess a node record + */ + +struct node_t *guess_node(call_t *call) +{ + struct node_t *node, *n, *p; + int l, m; + + p = nodes; + m = 0; + l = strlen((char *)call); + if (l != 0) { + while ((p)) { + /* Match substring: */ + if (strstr(p->call, (char *)call)) { + if (!strcmp((char *)call, p->call)) + /* Whoa, exact match! Accept this, even if there are others */ + return p; + m++; + n = p; + } + p = p->next; + } + } + if (m != 1) /* Exactly one match? */ + return NULL; + node = n; + strcpy((char *)call, n->call); + return node; +} + +/* * Get a link for the destination call */ @@ -766,6 +798,9 @@ void net_nodeadd(struct node_t *n) { struct node_t *nl, *p, *next; + + if (!n) + return; nl = p = n; p->prevp = &nl; diff -urN clussed-19990103/network.h clussed-19990106/network.h --- clussed-19990103/network.h Sun Jan 3 15:08:55 1999 +++ clussed-19990106/network.h Sun Jan 3 16:49:59 1999 @@ -205,6 +205,7 @@ extern void free_nodel(struct node_t *n); /* Free a list of nodes */ extern struct node_t *get_node(call_t *call); /* Find node */ +extern struct node_t *guess_node(call_t *call); /* Guess node */ extern struct link_t *get_link(call_t *nodec); /* Find link */ extern int count_links(void); /* Count links */