From: Art Cancro Date: Mon, 24 Apr 2000 03:36:44 +0000 (+0000) Subject: * Removed references to strucmp() and struncmp(), replaced them with X-Git-Tag: v7.86~7205 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=d7241a11aa7ec9453cedd57d58d14c1061cf63d4;p=citadel.git * Removed references to strucmp() and struncmp(), replaced them with strcasecmp() and strncasecmp() as we did in the server a while ago, and set up the config script to figure out whether they need to be compiled in. Also moved them to tools.h * Wrote a password manager for the client --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 37517d150..501a373cd 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,11 @@ $Log$ + Revision 571.4 2000/04/24 03:36:43 ajc + * Removed references to strucmp() and struncmp(), replaced them with + strcasecmp() and strncasecmp() as we did in the server a while ago, and + set up the config script to figure out whether they need to be compiled + in. Also moved them to tools.h + * Wrote a password manager for the client + Revision 571.3 2000/04/19 03:17:10 ajc * Don't ever expire the Local System Configuration> room @@ -1861,4 +1868,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/Makefile.in b/citadel/Makefile.in index 558ba1cb1..22f59ade5 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -82,7 +82,8 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c commands.c \ whobbs.c sendcommand.c mime_parser.c base64.c qpdecode.c getutline.c \ auth.c chkpwd.c client_icq.c html.c vcard.c serv_upgrade.c \ serv_smtp.c serv_pop3.c internet_addressing.c parsedate.c genstamp.c \ - domain.c clientsocket.c serv_inetcfg.c serv_rwho.c serv_bio.c + domain.c clientsocket.c serv_inetcfg.c serv_rwho.c serv_bio.c \ + client_passwords.c DEP_FILES=$(SOURCES:.c=.d) @@ -99,10 +100,12 @@ serv_modules: $(SERV_MODULES) citadel$(EXEEXT): ipc_c_tcp$(CX) citadel$(CX) rooms$(CX) routines$(CX) \ routines2$(CX) messages$(CX) client_icq$(CX) \ + client_passwords$(CX) \ commands$(CX) client_chat$(CX) serv_info$(CX) tools$(CX) $(LIBOBJS) $(CC) ipc_c_tcp$(CX) citadel$(CX) rooms$(CX) routines$(CX) \ routines2$(CX) messages$(CX) client_icq$(CX) \ commands$(CX) client_chat$(CX) serv_info$(CX) tools$(CX) \ + client_passwords$(CX) \ $(LIBOBJS) $(LDFLAGS) -o citadel $(NETLIBS) $(CLIENT_PTLIBS) netpoll: netpoll.o config.o ipc_c_tcp.o tools.o $(LIBOBJS) diff --git a/citadel/citadel.c b/citadel/citadel.c index 1f2347eff..f9b0fc70d 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -33,6 +33,7 @@ #include "commands.h" #include "ipc.h" #include "client_chat.h" +#include "client_passwords.h" #include "client_icq.h" #include "citadel_decls.h" #include "tools.h" @@ -84,6 +85,8 @@ char sigcaught = 0; char have_xterm = 0; /* are we running on an xterm? */ char rc_username[32]; char rc_password[32]; +char hostbuf[256]; +char portbuf[256]; char rc_floor_mode; char floor_mode; char curr_floor = 0; /* number of current floor */ @@ -245,8 +248,8 @@ void remove_march(char *roomname, int floornum) if (march == NULL) return; - if ((!strucmp(march->march_name, roomname)) - || ((!strucmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) { + if ((!strcasecmp(march->march_name, roomname)) + || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) { mptr = march->next; free(march); march = mptr; @@ -255,8 +258,8 @@ void remove_march(char *roomname, int floornum) mptr2 = march; for (mptr = march; mptr != NULL; mptr = mptr->next) { - if ((!strucmp(mptr->march_name, roomname)) - || ((!strucmp(roomname, "_FLOOR_")) + if ((!strcasecmp(mptr->march_name, roomname)) + || ((!strcasecmp(roomname, "_FLOOR_")) && (mptr->march_floor == floornum))) { mptr2->next = mptr->next; @@ -359,7 +362,7 @@ void dotgoto(char *towhere, int display_name) if (pattern(psearch, towhere) >= 0) { partial_match = 1; } - if (!struncmp(towhere, psearch, strlen(towhere))) { + if (!strncasecmp(towhere, psearch, strlen(towhere))) { partial_match = 2; } if (partial_match > best_match) { @@ -387,7 +390,7 @@ void dotgoto(char *towhere, int display_name) curr_floor = extract_int(&aaa[4], 10); remove_march(room_name, 0); - if (!strucmp(towhere, "_BASEROOM_")) + if (!strcasecmp(towhere, "_BASEROOM_")) remove_march(towhere, 0); if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) { if (floorlist[(int) curr_floor][0] == 0) @@ -572,12 +575,12 @@ void gotofloor(char *towhere, int mode) load_floorlist(); tofloor = (-1); for (a = 0; a < 128; ++a) - if (!strucmp(&floorlist[a][0], towhere)) + if (!strcasecmp(&floorlist[a][0], towhere)) tofloor = a; if (tofloor < 0) { for (a = 0; a < 128; ++a) { - if (!struncmp(&floorlist[a][0], towhere, strlen(towhere))) { + if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) { tofloor = a; } } @@ -701,11 +704,12 @@ int set_password(void) } strproc(pass1); strproc(pass2); - if (!strucmp(pass1, pass2)) { + if (!strcasecmp(pass1, pass2)) { snprintf(buf, sizeof buf, "SETP %s", pass1); serv_puts(buf); serv_gets(buf); printf("%s\n", &buf[4]); + offer_to_remember_password(hostbuf, portbuf, fullname, pass1); return (0); } else { printf("*** They don't match... try again.\n"); @@ -820,10 +824,11 @@ void enternew(char *desc, char *buf, int maxlen) int main(int argc, char **argv) { int a, b, mcmd; - char aaa[100], bbb[100], eee[100]; /* general purpose variables */ + char aaa[100], bbb[100];/* general purpose variables */ char argbuf[32]; /* command line buf */ volatile int termn8 = 0; - + int stored_password = 0; + char password[256]; sttybbs(SB_SAVE); /* Store the old terminal parameters */ load_command_set(); /* parse the citadel.rc file */ @@ -836,9 +841,7 @@ int main(int argc, char **argv) printf("Attaching to server... \r"); fflush(stdout); - attach_to_server(argc, argv); - printf("Establishing session...\r"); - fflush(stdout); + attach_to_server(argc, argv, hostbuf, portbuf); send_ansi_detect(); @@ -863,7 +866,28 @@ int main(int argc, char **argv) formout("hello"); /* print the opening greeting */ printf("\n"); -GSTA: termn8 = 0; +GSTA: /* See if we have a username and password on disk */ + if (rc_remember_passwords) { + get_stored_password(hostbuf, portbuf, fullname, password); + if (strlen(fullname) > 0) { + sprintf(aaa, "USER %s", fullname); + serv_puts(aaa); + serv_gets(aaa); + sprintf(aaa, "PASS %s", password); + serv_puts(aaa); + serv_gets(aaa); + if (aaa[0] == '2') { + load_user_info(&aaa[4]); + stored_password = 1; + goto PWOK; + } + else { + set_stored_password(hostbuf, portbuf, "", ""); + } + } + } + + termn8 = 0; newnow = 0; do { if (strlen(rc_username) > 0) { @@ -872,15 +896,15 @@ GSTA: termn8 = 0; newprompt("Enter your name: ", fullname, 29); } strproc(fullname); - if (!strucmp(fullname, "new")) { /* just in case */ + if (!strcasecmp(fullname, "new")) { /* just in case */ printf("Please enter the name you wish to log in with.\n"); } } while ( - (!strucmp(fullname, "bbs")) - || (!strucmp(fullname, "new")) + (!strcasecmp(fullname, "bbs")) + || (!strcasecmp(fullname, "new")) || (strlen(fullname) == 0)); - if (!strucmp(fullname, "off")) { + if (!strcasecmp(fullname, "off")) { mcmd = 29; goto TERMN8; } @@ -893,16 +917,18 @@ GSTA: termn8 = 0; /* password authentication */ if (strlen(rc_password) > 0) { - strcpy(eee, rc_password); + strcpy(password, rc_password); } else { - newprompt("\rPlease enter your password: ", eee, -19); + newprompt("\rPlease enter your password: ", password, -19); } - strproc(eee); - snprintf(aaa, sizeof aaa, "PASS %s", eee); + strproc(password); + snprintf(aaa, sizeof aaa, "PASS %s", password); serv_puts(aaa); serv_gets(aaa); if (aaa[0] == '2') { load_user_info(&aaa[4]); + offer_to_remember_password(hostbuf, portbuf, + fullname, password); goto PWOK; } printf("<< wrong password >>\n"); @@ -910,7 +936,7 @@ GSTA: termn8 = 0; logoff(0); goto GSTA; - NEWUSR:if (strlen(rc_password) == 0) { +NEWUSR: if (strlen(rc_password) == 0) { printf("No record. Enter as new user? "); if (yesno() == 0) goto GSTA; @@ -930,7 +956,7 @@ GSTA: termn8 = 0; enter_config(1); - PWOK:printf("%s\nAccess level: %d (%s)\nUser #%ld / Call #%d\n", +PWOK: printf("%s\nAccess level: %d (%s)\nUser #%ld / Call #%d\n", fullname, axlevel, axdefs[(int) axlevel], usernum, timescalled); diff --git a/citadel/citadel.h b/citadel/citadel.h index 79148db0a..a3b723dcb 100644 --- a/citadel/citadel.h +++ b/citadel/citadel.h @@ -28,8 +28,6 @@ #define tolower(x) ( ((x>='A')&&(x<='Z')) ? (x+'a'-'A') : x ) #define NEW_CONFIG -#define strucmp(lstr,rstr) struncmp(lstr,rstr,32767) - /* * The only typedef we do is an 8-bit unsigned, for screen dimensions. * All other defs are done using standard C types. The code assumes that diff --git a/citadel/citadel.rc b/citadel/citadel.rc index 5172df644..a7f8febee 100644 --- a/citadel/citadel.rc +++ b/citadel/citadel.rc @@ -67,15 +67,18 @@ beep=1 # allow_attachments=0 -# If you set the USERNAME variable, the value you set here will automatically -# be passed to the "Enter your name:" prompt. + +# If you set REMEMBER_PASSWORDS to 1, the Citadel client will offer to +# remember your user name and password for every Citadel server you access, +# automatically logging in with them on subsequent visits. +# (DANGER: do NOT enable this for "safe" public clients!) # -#username=My User Name +remember_passwords=0 -# If you set the PASSWORD variable, the value you set here will automatically -# be passed to all prompts which request a password ... including the prompt -# which asks for a password when creating a new user. +# Optionally, you can force the same username and password everywhere. This +# obviously isn't as robust as the password manager. # +#username=My User Name #password=mypassword # If URLCMD is defined, users can hit 'U' after reading a message which diff --git a/citadel/client_chat.c b/citadel/client_chat.c index a5a2f4589..3aad45f43 100644 --- a/citadel/client_chat.c +++ b/citadel/client_chat.c @@ -173,7 +173,7 @@ RCL: if (send_complete_line) { printf("Got room %s\n", c_room); } - if (strucmp(c_text,"NOOP")) { + if (strcasecmp(c_text,"NOOP")) { if (!strcmp(c_user, fullname)) { color(BRIGHT_YELLOW); } diff --git a/citadel/client_passwords.c b/citadel/client_passwords.c new file mode 100644 index 000000000..3d78f9b3a --- /dev/null +++ b/citadel/client_passwords.c @@ -0,0 +1,134 @@ +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tools.h" +#include "commands.h" + +#define PWFILENAME "%s/.citadel.passwords" + +void determine_pwfilename(char *pwfile) { + struct passwd *p; + + p = getpwuid(getuid()); + if (p == NULL) strcpy(pwfile, ""); + sprintf(pwfile, PWFILENAME, p->pw_dir); +} + + +/* + * Check the password file for a host/port match; if found, stuff the user + * name and password into the user/pass buffers + */ +void get_stored_password( + char *host, + char *port, + char *username, + char *password) { + + char pwfile[PATH_MAX]; + FILE *fp; + char buf[256]; + char buf64[256]; + char hostbuf[256], portbuf[256], ubuf[256], pbuf[256]; + + strcpy(username, ""); + strcpy(password, ""); + + determine_pwfilename(pwfile); + if (strlen(pwfile)==0) return; + + fp = fopen(pwfile, "r"); + if (fp == NULL) return; + while (fgets(buf64, sizeof buf64, fp) != NULL) { + decode_base64(buf, buf64); + extract(hostbuf, buf, 0); + extract(portbuf, buf, 1); + extract(ubuf, buf, 2); + extract(pbuf, buf, 3); + + if (!strcasecmp(hostbuf, host)) { + if (!strcasecmp(portbuf, port)) { + strcpy(username, ubuf); + strcpy(password, pbuf); + } + } + } + fclose(fp); +} + + +/* + * Set (or clear) stored passwords. + */ +void set_stored_password( + char *host, + char *port, + char *username, + char *password) { + + char pwfile[PATH_MAX]; + FILE *fp, *oldfp; + char buf[256]; + char buf64[256]; + char hostbuf[256], portbuf[256], ubuf[256], pbuf[256]; + + determine_pwfilename(pwfile); + if (strlen(pwfile)==0) return; + + oldfp = fopen(pwfile, "r"); + if (oldfp == NULL) oldfp = fopen("/dev/null", "r"); + unlink(pwfile); + fp = fopen(pwfile, "w"); + if (fp == NULL) fp = fopen("/dev/null", "w"); + while (fgets(buf64, sizeof buf64, oldfp) != NULL) { + decode_base64(buf, buf64); + extract(hostbuf, buf, 0); + extract(portbuf, buf, 1); + extract(ubuf, buf, 2); + extract(pbuf, buf, 3); + + if ( (strcasecmp(hostbuf, host)) + || (strcasecmp(portbuf, port)) ) { + sprintf(buf, "%s|%s|%s|%s|", + hostbuf, portbuf, ubuf, pbuf); + encode_base64(buf64, buf); + fprintf(fp, "%s\n", buf64); + } + } + if (strlen(username) > 0) { + sprintf(buf, "%s|%s|%s|%s|", + host, port, username, password); + encode_base64(buf64, buf); + fprintf(fp, "%s\n", buf64); + } + fclose(oldfp); + fclose(fp); + chmod(pwfile, 0600); +} + + +/* + * Set the password if the user wants to, clear it otherwise + */ +void offer_to_remember_password( + char *host, + char *port, + char *username, + char *password) { + + if (rc_remember_passwords) { + if (boolprompt("Remember username/password for this site", 0)) { + set_stored_password(host, port, username, password); + } + else { + set_stored_password(host, port, "", ""); + } + } +} diff --git a/citadel/client_passwords.h b/citadel/client_passwords.h new file mode 100644 index 000000000..1945ff07c --- /dev/null +++ b/citadel/client_passwords.h @@ -0,0 +1,16 @@ +void determine_pwfilename(char *); +void get_stored_password( + char *host, + char *port, + char *username, + char *password); +void set_stored_password( + char *host, + char *port, + char *username, + char *password); +void offer_to_remember_password( + char *host, + char *port, + char *username, + char *password); diff --git a/citadel/commands.c b/citadel/commands.c index 844a2e9b2..da810085c 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -59,6 +59,7 @@ char rc_exp_cmd[256]; int rc_allow_attachments; int rc_display_message_numbers; int rc_force_mail_prompts; +int rc_remember_passwords; int rc_ansi_color; int num_urls = 0; char urls[MAXURLS][256]; @@ -539,6 +540,7 @@ void load_command_set(void) rc_floor_mode = 0; rc_exp_beep = 1; rc_allow_attachments = 0; + rc_remember_passwords = 0; strcpy(rc_exp_cmd, ""); rc_display_message_numbers = 0; rc_force_mail_prompts = 0; @@ -570,56 +572,59 @@ void load_command_set(void) while ((strlen(buf) > 0) ? (isspace(buf[strlen(buf) - 1])) : 0) buf[strlen(buf) - 1] = 0; - if (!struncmp(buf, "editor=", 7)) + if (!strncasecmp(buf, "editor=", 7)) strcpy(editor_path, &buf[7]); - if (!struncmp(buf, "printcmd=", 9)) + if (!strncasecmp(buf, "printcmd=", 9)) strcpy(printcmd, &buf[9]); - if (!struncmp(buf, "expcmd=", 7)) + if (!strncasecmp(buf, "expcmd=", 7)) strcpy(rc_exp_cmd, &buf[7]); - if (!struncmp(buf, "local_screen_dimensions=", 24)) + if (!strncasecmp(buf, "local_screen_dimensions=", 24)) have_xterm = (char) atoi(&buf[24]); - if (!struncmp(buf, "use_floors=", 11)) { - if (!strucmp(&buf[11], "yes")) + if (!strncasecmp(buf, "use_floors=", 11)) { + if (!strcasecmp(&buf[11], "yes")) rc_floor_mode = RC_YES; - if (!strucmp(&buf[11], "no")) + if (!strcasecmp(&buf[11], "no")) rc_floor_mode = RC_NO; - if (!strucmp(&buf[11], "default")) + if (!strcasecmp(&buf[11], "default")) rc_floor_mode = RC_DEFAULT; } - if (!struncmp(buf, "beep=", 5)) { + if (!strncasecmp(buf, "beep=", 5)) { rc_exp_beep = atoi(&buf[5]); } - if (!struncmp(buf, "allow_attachments=", 18)) { + if (!strncasecmp(buf, "allow_attachments=", 18)) { rc_allow_attachments = atoi(&buf[18]); } - if (!struncmp(buf, "display_message_numbers=", 24)) { + if (!strncasecmp(buf, "remember_passwords=", 19)) { + rc_remember_passwords = atoi(&buf[19]); + } + if (!strncasecmp(buf, "display_message_numbers=", 24)) { rc_display_message_numbers = atoi(&buf[24]); } - if (!struncmp(buf, "force_mail_prompts=", 19)) { + if (!strncasecmp(buf, "force_mail_prompts=", 19)) { rc_force_mail_prompts = atoi(&buf[19]); } - if (!struncmp(buf, "ansi_color=", 11)) { - if (!struncmp(&buf[11], "on", 2)) + if (!strncasecmp(buf, "ansi_color=", 11)) { + if (!strncasecmp(&buf[11], "on", 2)) rc_ansi_color = 1; - if (!struncmp(&buf[11], "auto", 4)) + if (!strncasecmp(&buf[11], "auto", 4)) rc_ansi_color = 2; /* autodetect */ - if (!struncmp(&buf[11], "user", 4)) + if (!strncasecmp(&buf[11], "user", 4)) rc_ansi_color = 3; /* user config */ } - if (!struncmp(buf, "username=", 9)) + if (!strncasecmp(buf, "username=", 9)) strcpy(rc_username, &buf[9]); - if (!struncmp(buf, "password=", 9)) + if (!strncasecmp(buf, "password=", 9)) strcpy(rc_password, &buf[9]); - if (!struncmp(buf, "urlcmd=", 7)) + if (!strncasecmp(buf, "urlcmd=", 7)) strcpy(rc_url_cmd, &buf[7]); - if (!struncmp(buf, "cmd=", 4)) { + if (!strncasecmp(buf, "cmd=", 4)) { strcpy(buf, &buf[4]); cptr = (struct citcmd *) malloc(sizeof(struct citcmd)); @@ -1059,8 +1064,8 @@ FMTA: while ((eof_flag == 0) && (strlen(buffer) < 126)) { } } - if ( (!struncmp(buffer, "http://", 7)) - || (!struncmp(buffer, "ftp://", 6)) ) { + if ( (!strncasecmp(buffer, "http://", 7)) + || (!strncasecmp(buffer, "ftp://", 6)) ) { safestrncpy(urls[num_urls], buffer, 255); for (a=0; a "); } - if ((!struncmp(buf,"hnod=",5)) - && (strucmp(&buf[5],serv_info.serv_humannode)) + if ((!strncasecmp(buf,"hnod=",5)) + && (strcasecmp(&buf[5],serv_info.serv_humannode)) && (strlen(rfca) == 0) ) { color(DIM_WHITE); printf("("); @@ -419,8 +418,8 @@ int read_message(long int num, char pagin) /* Read a message from the server */ color(DIM_WHITE); printf(") "); } - if ((!struncmp(buf,"room=",5)) - && (strucmp(&buf[5],room_name)) + if ((!strncasecmp(buf,"room=",5)) + && (strcasecmp(&buf[5],room_name)) && (strlen(rfca) == 0)) { color(DIM_WHITE); printf("in "); @@ -428,11 +427,11 @@ int read_message(long int num, char pagin) /* Read a message from the server */ printf("%s> ",&buf[5]); } - if (!struncmp(buf,"node=",5)) { + if (!strncasecmp(buf,"node=",5)) { safestrncpy(node, &buf[5], sizeof(buf) - 5); if ( (room_flags&QR_NETWORK) - || ((strucmp(&buf[5],serv_info.serv_nodename) - &&(strucmp(&buf[5],serv_info.serv_fqdn)))) ) + || ((strcasecmp(&buf[5],serv_info.serv_nodename) + &&(strcasecmp(&buf[5],serv_info.serv_fqdn)))) ) { if (strlen(rfca) == 0) { color(DIM_WHITE); @@ -443,13 +442,13 @@ int read_message(long int num, char pagin) /* Read a message from the server */ } } - if (!struncmp(buf,"rcpt=",5)) { + if (!strncasecmp(buf,"rcpt=",5)) { color(DIM_WHITE); printf("to "); color(BRIGHT_CYAN); printf("%s ",&buf[5]); } - if (!struncmp(buf,"time=",5)) { + if (!strncasecmp(buf,"time=",5)) { fmt_date(now, atol(&buf[5])); printf("%s ", now); } @@ -542,7 +541,7 @@ void replace_string(char *filename, long int startpos) buf[strlen(buf)] = a; if ( strlen(buf) >= strlen(srch_str) ) { ptr=&buf[strlen(buf)-strlen(srch_str)]; - if (!struncmp(ptr,srch_str,strlen(srch_str))) { + if (!strncasecmp(ptr,srch_str,strlen(srch_str))) { strcpy(ptr,rplc_str); ++substitutions; } diff --git a/citadel/rooms.c b/citadel/rooms.c index fcc65c3ef..68135fe49 100644 --- a/citadel/rooms.c +++ b/citadel/rooms.c @@ -31,7 +31,6 @@ void hit_any_key(void); int yesno(void); void strprompt(char *prompt, char *str, int len); void newprompt(char *prompt, char *str, int len); -int struncmp(char *lstr, char *rstr, int len); void dotgoto(char *towhere, int display_name); void serv_read(char *buf, int bytes); void formout(char *name); @@ -314,9 +313,9 @@ int select_floor(int rfloor) safestrncpy(floorstr,floorlist[rfloor],sizeof floorstr); strprompt("Which floor",floorstr,256); for (a=0; a<128; ++a) { - if (!strucmp(floorstr,&floorlist[a][0])) + if (!strcasecmp(floorstr,&floorlist[a][0])) newfloor = a; - if ((newfloor<0)&&(!struncmp(floorstr, + if ((newfloor<0)&&(!strncasecmp(floorstr, &floorlist[a][0],strlen(floorstr)))) newfloor = a; if ((newfloor<0)&&(pattern(&floorlist[a][0], @@ -441,7 +440,7 @@ void editthisroom(void) { /* Ask about the room aide */ do { strprompt("Room aide (or 'none')",raide,29); - if (!strucmp(raide,"none")) { + if (!strcasecmp(raide,"none")) { strcpy(raide,""); strcpy(buf,"200"); } @@ -453,7 +452,7 @@ void editthisroom(void) { } } while(buf[0]!='2'); - if (!strucmp(raide,"none")) strcpy(raide,""); + if (!strcasecmp(raide,"none")) strcpy(raide,""); /* Angels and demons dancing in my head... */ @@ -1109,7 +1108,7 @@ void kill_floor(void) { newprompt("Delete which floor? ",buf,255); if (strlen(buf)==0) return; for (a=0; a<128; ++a) - if (!strucmp(&floorlist[a][0],buf)) + if (!strcasecmp(&floorlist[a][0],buf)) floornum_to_delete = a; if (floornum_to_delete < 0) { printf("No such floor. Select one of:\n"); diff --git a/citadel/routines.c b/citadel/routines.c index e7c08a9a0..8d47314ae 100644 --- a/citadel/routines.c +++ b/citadel/routines.c @@ -54,26 +54,9 @@ extern struct CtdlServInfo serv_info; extern char rc_floor_mode; extern int rc_ansi_color; -int struncmp(char *lstr, char *rstr, int len) -{ - int pos = 0; - char lc,rc; - while (posrc) return(1); - pos=pos+1; - } - return(0); - } - - - void back(int spaces) /* Destructive backspace */ { -int a; + int a; for (a=1; a<=spaces; ++a) { putc(8,stdout); putc(32,stdout); putc(8,stdout); } @@ -279,7 +262,7 @@ int pattern(char *search, char *patn) /* Searches for patn in search string */ { int a,b; for (a=0; a #include #include @@ -19,17 +20,36 @@ static byte dtable[256]; /* base64 encode / decode table */ char *safestrncpy(char *dest, const char *src, size_t n) { - if (dest == NULL || src == NULL) - { - fprintf(stderr, "safestrncpy: NULL argument\n"); - abort(); - } - strncpy(dest, src, n); - dest[n - 1] = 0; - return dest; + if (dest == NULL || src == NULL) { + fprintf(stderr, "safestrncpy: NULL argument\n"); + abort(); + } + strncpy(dest, src, n); + dest[n - 1] = 0; + return dest; } + +#ifndef HAVE_STRNCASECMP +int strncasecmp(char *lstr, char *rstr, int len) +{ + int pos = 0; + char lc,rc; + while (posrc) return(1); + pos=pos+1; + } + return(0); +} +#endif + + + /* * num_tokens() - discover number of parameters/tokens in a string */ diff --git a/citadel/tools.h b/citadel/tools.h index 9def9852d..6b8ea4430 100644 --- a/citadel/tools.h +++ b/citadel/tools.h @@ -12,5 +12,12 @@ int collapsed_strcmp(char *s1, char *s2); void remove_token(char *source, int parmnum, char separator); void fmt_date(char *buf, time_t thetime); +#ifndef HAVE_STRNCASECMP +int strncasecmp(char *, char *, int) +#endif +#ifndef HAVE_STRCASECMP +#define strcasecmp(x,y) strncasecmp(x,y,INT_MAX); +#endif + #define extract(dest,source,parmnum) extract_token(dest,source,parmnum,'|') #define num_parms(source) num_tokens(source, '|') diff --git a/citadel/userlist.c b/citadel/userlist.c index 41d313b59..91d99f1dc 100644 --- a/citadel/userlist.c +++ b/citadel/userlist.c @@ -49,8 +49,9 @@ void userlist(void) { int main(int argc, char **argv) { char buf[256]; + char hostbuf[256], portbuf[256]; - attach_to_server(argc,argv); + attach_to_server(argc, argv, hostbuf, portbuf); serv_gets(buf); if ((buf[0]!='2')&&(strncmp(buf,"551",3))) { fprintf(stderr,"%s: %s\n",argv[0],&buf[4]); diff --git a/citadel/whobbs.c b/citadel/whobbs.c index 7c9f46238..a9106eba3 100644 --- a/citadel/whobbs.c +++ b/citadel/whobbs.c @@ -42,6 +42,8 @@ int main(int argc, char **argv) int www = 0; int s_pid = 0; int my_pid = 0; + char hostbuf[256]; + char portbuf[256]; char s_user[256]; char s_room[256]; char s_host[256]; @@ -53,7 +55,7 @@ int main(int argc, char **argv) */ if (getenv("REQUEST_METHOD") != NULL) www = 1; - attach_to_server(argc,argv); + attach_to_server(argc,argv, hostbuf, portbuf); serv_gets(buf); if ((buf[0]!='2')&&(strncmp(buf,"551",3))) { fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);