diff -urN clussed-19981229/CHANGELOG clussed-19981231/CHANGELOG --- clussed-19981229/CHANGELOG Tue Dec 29 23:12:00 1998 +++ clussed-19981231/CHANGELOG Thu Dec 31 13:05:56 1998 @@ -86,3 +86,20 @@ commands dumping a list of keys in a database, in sorted order. Expanded frequency field in user_dx() to 10 characters, >9GHz spots. +Thu Dec 31 13:04:20 EET 1998 + + Some work on loop detection/crash prevention and valid_call checks. + + --- patch from Petteri, OH1MMA : + Made the prompt customizable. Users can now individually select the + items they want displayed. (Some Clusse users still ask for more + prompt styles, this could help keeping them happy?) + "help prompt" works, because I wanted to document the new "prompt + management concept". This is definitely not a proper implementation. + Fixed a compiler warning in login.c :-) + + (yes, i don't want a single more of those "help commands", someone + write that help system ASAP! and that warning was there to remind + me that the given password should be checked against something 8-) + -hessu) + diff -urN clussed-19981229/CREDITS clussed-19981231/CREDITS --- clussed-19981229/CREDITS Thu Jan 1 02:00:00 1970 +++ clussed-19981231/CREDITS Thu Dec 31 13:07:40 1998 @@ -0,0 +1,6 @@ + + In no particular order, thanks go to: + +Petteri, OH1MMA + Prompt management concept and implementation + diff -urN clussed-19981229/Makefile clussed-19981231/Makefile --- clussed-19981229/Makefile Tue Dec 29 21:55:41 1998 +++ clussed-19981231/Makefile Thu Dec 31 12:50:05 1998 @@ -17,7 +17,7 @@ snap: distclean @echo "Making snapshot ..." @Snapshot.sh - + clean: @echo "Making clean ..." rm -f *.o */*.o *~ */*~ */*/*~ core compile.h @@ -101,7 +101,7 @@ net_user.h f_luser.h timer.h ctime.h cluster.o: cluster.h cluster.c command.h help.h cmd_sys.h cmd_cluster.h \ cmd_net.h cmd_usercfg.h network.h net_ping.h luser.h ctime.h \ - config.h f_nuser.h f_luser.h + config.h f_nuser.h f_luser.h net_user.h timer.h command.o: command.h command.c csock.h cfgfile.h cmd_sys.o: cmd_sys.h cmd_sys.c csock.h version.h hmalloc.h ctime.h cmd_cluster.o: cmd_cluster.h cmd_cluster.c csock.h hmalloc.h network.h \ diff -urN clussed-19981229/TODO clussed-19981231/TODO --- clussed-19981229/TODO Thu Jan 1 02:00:00 1970 +++ clussed-19981231/TODO Thu Dec 31 13:10:24 1998 @@ -0,0 +1,22 @@ + + Things to do prior version 1.0.0: + + - Language system. Ideas: + Could be built on top of the db interface. Define an + ASCII file format for the language definition, an external + "language compiler" to dump that in a db. mv -f new.db old.db, + kill -HUP clussed to install a new language on the fly. + language.conf to define what languages are used, and default + languages per user callsign regexps (a la FBB). + - Help system (probably comes to life with the language system without + any extra thinking) + - List commands, files to store DX spots, announcements, wwv data + - expiration for the data files (including the db's) + - Handle SIGHUP: try to reread configuration, close and open databases + and other files. Configuration reading should happen from files to a + structure, so that it could be tried at run-time (read to another + copy, if config is valid, take it into use "conf = new_conf;", and if + there are typing mistakes, "hfree(new_conf);". + - Authentication (password check against luser db in login.c) and + permissions (who can do what). Something in between node and DOS clusse. + Binary files clussed-19981229/base/data/luser.db and clussed-19981231/base/data/luser.db differ diff -urN clussed-19981229/base/etc/links.conf clussed-19981231/base/etc/links.conf --- clussed-19981229/base/etc/links.conf Tue Dec 29 12:42:13 1998 +++ clussed-19981231/base/etc/links.conf Wed Dec 30 03:42:24 1998 @@ -1,11 +1,11 @@ -#link oh7lzb-1 -#protocol pc -#script scripts/oh7lzb-1.con - link oh2lzb-1 protocol pc mode incoming + +link oh1lzb-1 +protocol pc +script scripts/oh1lzb-1.con #link pi5ehv-8 #protocol pc diff -urN clussed-19981229/base/scripts/oh1lzb-1.con clussed-19981231/base/scripts/oh1lzb-1.con --- clussed-19981229/base/scripts/oh1lzb-1.con Thu Jan 1 02:00:00 1970 +++ clussed-19981231/base/scripts/oh1lzb-1.con Wed Dec 30 03:42:55 1998 @@ -0,0 +1,7 @@ + +# +# Connection script for Clusse 0.40 +# + +ax25 lo0 oh1lzb-1 + Binary files clussed-19981229/base2/data/nuser.db and clussed-19981231/base2/data/nuser.db differ Binary files clussed-19981229/base3/data/luser.db and clussed-19981231/base3/data/luser.db differ Binary files clussed-19981229/base3/data/mid.db and clussed-19981231/base3/data/mid.db differ Binary files clussed-19981229/base3/data/nuser.db and clussed-19981231/base3/data/nuser.db differ diff -urN clussed-19981229/base3/etc/links.conf clussed-19981231/base3/etc/links.conf --- clussed-19981229/base3/etc/links.conf Sun Dec 27 21:24:58 1998 +++ clussed-19981231/base3/etc/links.conf Wed Dec 30 03:41:42 1998 @@ -3,3 +3,7 @@ protocol pc script scripts/oh2lzb-1.con +link oh7lzb-1 +protocol pc +mode incoming + diff -urN clussed-19981229/cluster.c clussed-19981231/cluster.c --- clussed-19981229/cluster.c Tue Dec 29 21:54:55 1998 +++ clussed-19981231/cluster.c Thu Dec 31 13:03:57 1998 @@ -19,9 +19,11 @@ #include "net_ping.h" #include "luser.h" #include "ctime.h" +#include "timer.h" #include "config.h" #include "f_nuser.h" #include "f_luser.h" +#include "net_user.h" /* * Cluster commands @@ -49,6 +51,7 @@ { "unetwork", cmd_unetwork }, { "uptime", cmd_uptime }, { "ping", cmd_ping }, + { "prompt", cmd_prompt }, { "pstatus", cmd_pstatus }, { "version", cmd_version }, { "?", cmd_commands }, @@ -62,7 +65,27 @@ void prompt(struct csock_t *s) { - csprintf(s, "c>\n"); + int p = s->lu->f->prompt; + + if (!((p & P_NONE) || p == P_TRAD)) { + if (p & P_UCALL) csputs(s, (char *) s->lu->f->call); + if (p & P_CCALL) csprintf(s, "%s%s", + (p & P_UCALL) ? "@" : "", + (char *) clucall); + /* I'd like to see these globals file scoped and + accessed with something like get_clucall() /PVi */ + /* yeah, i'd like them to be in a structure like conf->clucall, + for the sake of configuration re-read at SIGHUP attempts */ + if (p & P_UPTIME) csprintf(s, " Up:%s", secs2str_l(uptime())); + if (p & P_NUSERS) csprintf(s, " (%i/%i)", luser_count, + nuser_count); + if (p & P_DATE) csprintf(s, " %s.", datestr_s(now)); + if (p & P_TIME) csprintf(s, " %sZ", timestr_p(now)); + } + if (p == P_TRAD) + csputc(s, 'c'); + if (!(p & P_NONE)) + csputs(s, ">\n"); } /* diff -urN clussed-19981229/cmd_usercfg.c clussed-19981231/cmd_usercfg.c --- clussed-19981229/cmd_usercfg.c Sun Dec 27 04:21:41 1998 +++ clussed-19981231/cmd_usercfg.c Thu Dec 31 12:53:24 1998 @@ -86,6 +86,9 @@ if (setto) *m |= M_NODE; else *m &= ~M_NODE; break; + default: + csprintf(s, "Unknown argument: %c\n", *p); + break; } } } @@ -107,3 +110,70 @@ return 0; } +/* + * View or change the prompt + */ + +int cmd_prompt(struct csock_t *s, int argc, char **argv) +{ + int setto = 1; + int i; + char *c; + int *p = &s->lu->f->prompt; + + for (i = 1; i < argc; i++) { + for (c = argv[i]; (*c); c++) { + switch (*c) { + case '+': + setto = 1; + break; + case '-': + setto = 0; + break; + case '0': + *p = P_TRAD; + break; + case '1': + if (setto) *p |= P_UCALL; + else *p &= ~P_UCALL; + break; + case '2': + if (setto) *p |= P_CCALL; + else *p &= ~P_CCALL; + break; + case '3': + if (setto) *p |= P_TIME; + else *p &= ~P_TIME; + break; + case '4': + if (setto) *p |= P_DATE; + else *p &= ~P_DATE; + break; + case '5': + if (setto) *p |= P_UPTIME; + else *p &= ~P_UPTIME; + break; + case '6': + if (setto) *p |= P_NUSERS; + else *p &= ~P_NUSERS; + break; + case '7': + if (setto) *p |= P_NONE; + else *p &= ~P_NONE; + break; + default: + csprintf(s, "Unknown argument: %c\n", *c); + break; + } + } + } + + if (argc > 1) + write_luserf(s->lu->f); + + csputs(s, "Your prompt: "); + if (!*p || (*p & P_NONE)) + csputc(s, '\n'); + + return 0; +} diff -urN clussed-19981229/cmd_usercfg.h clussed-19981231/cmd_usercfg.h --- clussed-19981229/cmd_usercfg.h Sun Dec 27 04:00:24 1998 +++ clussed-19981231/cmd_usercfg.h Thu Dec 31 12:34:11 1998 @@ -6,5 +6,6 @@ extern int cmd_name(struct csock_t *s, int argc, char **argv); extern int cmd_messages(struct csock_t *s, int argc, char **argv); +extern int cmd_prompt(struct csock_t *s, int argc, char **argv); #endif diff -urN clussed-19981229/csock.c clussed-19981231/csock.c --- clussed-19981229/csock.c Sat Dec 26 02:22:13 1998 +++ clussed-19981231/csock.c Wed Dec 30 21:46:15 1998 @@ -916,7 +916,7 @@ * Dispatch an incoming connection to a higher layer */ -void sock_login(struct csock_t *s) +int sock_login(struct csock_t *s) { s->type = cst_incoming; s->state = css_connected; @@ -926,19 +926,20 @@ (s->node) ? s->node : "", s->port, s->fd); if (s->af_type == AF_INET) - auth_login(s); + return auth_login(s); else - luser_login(s); + return luser_login(s); } /* * Disconnect a socket */ -void sock_disconnect(struct csock_t *s) +int sock_disconnect(struct csock_t *s) { s->state = css_disconnecting; sock_close(s); + return -2; } /************************************************************************ diff -urN clussed-19981229/csock.h clussed-19981231/csock.h --- clussed-19981229/csock.h Sat Dec 26 02:16:50 1998 +++ clussed-19981231/csock.h Wed Dec 30 03:38:54 1998 @@ -183,8 +183,8 @@ /* For af_* */ extern struct csock_t *sock_alloc(int fd, int af_type, int def_buflen, int obuf_tresh, int compressed); -extern void sock_login(struct csock_t *s); -extern void sock_disconnect(struct csock_t *s); +extern int sock_login(struct csock_t *s); +extern int sock_disconnect(struct csock_t *s); extern struct csock_t *sock_connect(int af_type, int compressed, int argc, char **argv); /* Socket output */ diff -urN clussed-19981229/help.c clussed-19981231/help.c --- clussed-19981229/help.c Sat Dec 26 18:18:03 1998 +++ clussed-19981231/help.c Thu Dec 31 12:34:11 1998 @@ -3,6 +3,15 @@ #include "cluster.h" #include "help.h" +/* + * Help commands + */ + +struct cmd help_cmds[] = { + { "prompt", help_prompt }, + { NULL, NULL, } +}; + int cmd_commands(struct csock_t *s, int argc, char **argv) { struct cmd *c; @@ -17,7 +26,28 @@ int cmd_help(struct csock_t *s, int argc, char **argv) { - csprintf(s, "Help is for wimps. Use the source, luke!\n"); - + if (argc > 1) + command(s, help_cmds, argv[1]); + else + csprintf(s, "Help is for wimps. Use the source, luke!\n"); + + return 0; +} + +int help_prompt(struct csock_t *s, int argc, char **argv) +{ + csputs(s, "\nPRompt [<+|->] ... - change the prompt\n\n"); + csputs(s, "You can customize the prompt by selecting one or more\n"); + csputs(s, "of the following items to be displayed:\n\n"); + csputs(s, "0. The basic \"c>\" prompt. Resets other settings.\n"); + csputs(s, "1. Your callsign\n"); + csputs(s, "2. Cluster's callsign\n"); + csputs(s, "3. Current time\n"); + csputs(s, "4. Current date\n"); + csputs(s, "5. Cluster's uptime\n"); + csputs(s, "6. Number of users (local/all)\n"); + csputs(s, "7. None (hides the prompt, preserves other selections.)\n"); + csputs(s, "\nExample: prompt +25-3\n\n"); + return 0; } diff -urN clussed-19981229/help.h clussed-19981231/help.h --- clussed-19981229/help.h Sat Dec 26 18:18:20 1998 +++ clussed-19981231/help.h Thu Dec 31 12:34:11 1998 @@ -4,7 +4,11 @@ #include "csock.h" +extern struct cmd help_cmds[]; + extern int cmd_commands(struct csock_t *s, int argc, char **argv); extern int cmd_help(struct csock_t *s, int argc, char **argv); + +extern int help_prompt(struct csock_t *s, int argc, char **argv); #endif diff -urN clussed-19981229/login.c clussed-19981231/login.c --- clussed-19981229/login.c Sun Dec 27 18:52:04 1998 +++ clussed-19981231/login.c Thu Dec 31 12:34:11 1998 @@ -80,16 +80,14 @@ int password_handler(struct csock_t *s, void *data, int len) { - char *p = (char *)data; + /* char *p = (char *)data; */ if (s->af_type == AF_INET) tn_wont_echo(s); csprintf(s, "\n\n"); s->call = hstrdup(s->login->call); login_free(s->login); - luser_login(s); - - return 0; + return luser_login(s); } int login_handler(struct csock_t *s, void *data, int len) @@ -117,13 +115,15 @@ * Login: */ -void auth_login(struct csock_t *s) +int auth_login(struct csock_t *s) { if (s->af_type == AF_INET) tn_do_linemode(s); csprintf(s, "\n%s (%s)\n\nlogin: ", SOFT_SHORTSTRING, hostname); csflush(s); login_alloc(s); + + return 0; } void login_logout(struct csock_t *s) diff -urN clussed-19981229/login.h clussed-19981231/login.h --- clussed-19981229/login.h Sun Dec 20 18:08:27 1998 +++ clussed-19981231/login.h Wed Dec 30 03:36:54 1998 @@ -13,7 +13,7 @@ struct login_t **prevp; }; -extern void auth_login(struct csock_t *s); +extern int auth_login(struct csock_t *s); extern void login_logout(struct csock_t *s); extern int login_handler(struct csock_t *s, void *data, int len); diff -urN clussed-19981229/luser.c clussed-19981231/luser.c --- clussed-19981229/luser.c Sun Dec 27 03:58:06 1998 +++ clussed-19981231/luser.c Wed Dec 30 03:34:56 1998 @@ -235,7 +235,7 @@ * Accept a user connection (or not) */ -void luser_login(struct csock_t *s) +int luser_login(struct csock_t *s) { struct luser_t *lu; int newuser = 0; @@ -246,8 +246,7 @@ truncssid((call_t *)s->call); if ((li = get_link((call_t *)s->call)) && li->mode == lm_incoming) { - link_login(s, li); - return; + return link_login(s, li); } lu = luser_alloc(s); @@ -274,6 +273,8 @@ csprintf(s, "Welcome, new user.\n"); prompt(s); + + return 0; } /* diff -urN clussed-19981229/luser.h clussed-19981231/luser.h --- clussed-19981229/luser.h Sun Dec 27 03:24:07 1998 +++ clussed-19981231/luser.h Thu Dec 31 12:49:06 1998 @@ -10,12 +10,14 @@ #include "cfile.h" #include "csock.h" +/* Flags mask */ #define F_BEEPS 1 #define F_TIMESTAMP 2 #define F_TIMER 4 #define F_PCCOMPAT 8 #define F_FILTER 16 +/* Messages and beeps mask */ #define M_DX 1 #define M_ANN 2 #define M_WWV 4 @@ -27,8 +29,17 @@ #define M_NULL 0 +/* Prompt style mask */ +#define P_TRAD 0x0 +#define P_UCALL 0x1 +#define P_CCALL 0x2 +#define P_TIME 0x4 +#define P_DATE 0x8 +#define P_UPTIME 0x10 +#define P_NUSERS 0x20 +#define P_NONE 0x40 + #define MAX_GROUP 20 -#define MAX_PROMPT 8 #define M2_NONE 0 #define M3_NONE 0 @@ -90,7 +101,7 @@ extern int send_us(int mtype, char *fmt, ...); -extern void luser_login(struct csock_t *s); +extern int luser_login(struct csock_t *s); extern void luser_logout(struct csock_t *s); extern int luser_handler(struct csock_t *s, void *data, int len); diff -urN clussed-19981229/net_pc.c clussed-19981231/net_pc.c --- clussed-19981229/net_pc.c Mon Dec 28 03:12:04 1998 +++ clussed-19981231/net_pc.c Thu Dec 31 13:12:00 1998 @@ -583,6 +583,8 @@ prevp = &nul; if (!(n = get_node((call_t *)argv[1]))) return 0; + if (n->via != l) + return caught_loop(l); hops = pchops2int(argv[argc-1]); for (i = 2; i < argc-1; i++) { @@ -594,6 +596,8 @@ continue; *hr = '\0'; hr++; + if (!valid_call((call_t *)argv[i])) + continue; nu = hmalloc(sizeof(struct nuser_t)); *prevp = nu; nu->prevp = prevp; @@ -651,7 +655,7 @@ /* Add node */ int pc_19(struct link_t *l, int argc, char **argv) { - struct node_t *n, *nl, **prevp; + struct node_t *n, *nl = NULL, **prevp; int i = 1; int hops; @@ -661,6 +665,15 @@ while (i < argc-2) { if (i > argc - 5) break; + if (!valid_call((call_t *)argv[i+1])) + continue; + if ((n = get_node((call_t *)argv[i+1]))) + if (n->via != l) { + caught_loop(l); + free_nodel(nl); + return -2; + } else + continue; n = hmalloc(sizeof(struct node_t)); *prevp = n; n->prevp = prevp; @@ -711,7 +724,7 @@ if (argc != 4) return invalid_argc(l, 4, argc, argv); - if ((n = get_node((call_t *)argv[1]))) + if ((n = get_node((call_t *)argv[1])) && n->via == l) net_nodedel(n, argv[2]); return 0; @@ -772,9 +785,8 @@ p2++; } - if (get_node((call_t *)p)) { - /* LOOP */ - } + if (get_node((call_t *)p)) + return caught_loop(l); p = p2; } diff -urN clussed-19981229/net_user.c clussed-19981231/net_user.c --- clussed-19981229/net_user.c Mon Dec 28 23:47:55 1998 +++ clussed-19981231/net_user.c Wed Dec 30 03:52:15 1998 @@ -234,7 +234,7 @@ while (p) { next = p->next; - if (get_nuserh(&p->call, p->node) || (!valid_call(&p->call))) { + if ((get_nuserh(&p->call, p->node)) || (!valid_call(&p->call))) { if (p->next) p->next->prevp = p->prevp; *p->prevp = p->next; diff -urN clussed-19981229/network.c clussed-19981231/network.c --- clussed-19981229/network.c Mon Dec 28 23:48:17 1998 +++ clussed-19981231/network.c Wed Dec 30 11:25:49 1998 @@ -97,6 +97,21 @@ } /* + * Free a list of nodes + */ + +void free_nodel(struct node_t *n) +{ + struct node_t *next; + + while (n) { + next = n->next; + free(n); + n = next; + } +} + +/* * Find a record from the node list */ @@ -237,7 +252,7 @@ * Link connection */ -void link_login(struct csock_t *sock, struct link_t *l) +int link_login(struct csock_t *sock, struct link_t *l) { if (l->state == ls_disc || l->state == ls_held) { sock->charset = l->charset; @@ -250,8 +265,7 @@ if (l->state == ls_held) { /* Held */ l->dreason = dr_held; - sock_disconnect(sock); - return; + return sock_disconnect(sock); } l->state = ls_init; @@ -261,11 +275,11 @@ pc_conn_handler(l); - return; + return 0; } /* Whoa, duplikaatti! Katkaistaan molemmat... */ sock_disconnect(sock); - sock_disconnect(l->sock); + return sock_disconnect(l->sock); } /* @@ -371,6 +385,22 @@ } /* + * Drop this link immediately, due to a caught loop + */ + +int caught_loop(struct link_t *l) +{ + if (l->state == ls_held) + return -2; /* might be several reasons to hold a link + in a single received message */ + log(L_ERR, "Link: %s: Loop detected - link held!", l->name); + + l->state = ls_held; + l->dreason = dr_loop; + return sock_disconnect(l->sock); +} + +/* * Link has been disconnected */ @@ -402,7 +432,8 @@ } l->retry_timer = 0; if (l->backup) { - l->state = ls_backup; + if (l->state != ls_held) + l->state = ls_backup; l->backup->state = ls_disc; } } diff -urN clussed-19981229/network.h clussed-19981231/network.h --- clussed-19981229/network.h Sun Dec 27 19:14:43 1998 +++ clussed-19981231/network.h Wed Dec 30 04:03:51 1998 @@ -202,6 +202,7 @@ extern struct link_t *links; /* Links */ extern struct index_t indexes; /* Index */ +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 link_t *get_link(call_t *nodec); /* Find link */ @@ -215,8 +216,10 @@ extern void link_finished(struct link_t *l); /* Linking finished */ extern int cut_links(enum cutlink_t method, char *reason); /* Cut all links */ -extern void link_login(struct csock_t *sock, struct link_t *l); +extern int link_login(struct csock_t *sock, struct link_t *l); extern void link_logout(struct csock_t *sock); + +extern int caught_loop(struct link_t *l); /* Cluster events */ extern int net_dx(struct dx_t *dx); /* DX */