]> code.citadel.org Git - citadel.git/blobdiff - citadel/citadel.c
* The size constant "256" which shows up everywhere as a buffer size has now
[citadel.git] / citadel / citadel.c
index c13d9d9a8da450275c1af06e7a967167a3980d94..eb965e427ff36cfe7c6c7fbab12391c24bae9fbd 100644 (file)
 #include "client_passwords.h"
 #include "citadel_decls.h"
 #include "tools.h"
+#include "acconfig.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
 
+#include "md5.h"
+
 struct march {
        struct march *next;
        char march_name[ROOMNAMELEN];
        char march_floor;
        char march_order;
-};
+       };
 
 #define IFEXPERT if (userflags&US_EXPERT)
 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
@@ -57,8 +60,8 @@ struct march *march = NULL;
 char temp[PATH_MAX];           /* Name of general temp file */
 char temp2[PATH_MAX];          /* Name of general temp file */
 char tempdir[PATH_MAX];                /* Name of general temp dir */
-char editor_path[256];         /* path to external editor */
-char printcmd[256];            /* print command */
+char editor_path[SIZ];         /* path to external editor */
+char printcmd[SIZ];            /* print command */
 int editor_pid = (-1);
 char fullname[32];
 jmp_buf nextbuf;
@@ -83,13 +86,16 @@ 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 hostbuf[SIZ];
+char portbuf[SIZ];
 char rc_floor_mode;
 char floor_mode;
 char curr_floor = 0;           /* number of current floor */
-char floorlist[128][256];      /* names of floors */
+char floorlist[128][SIZ];      /* names of floors */
 char express_msgs = 0;         /* express messages waiting! */
+int termn8 = 0;                        /* Set to nonzero to cause a logoff */
+
+extern int rc_ansi_color;      /* ansi color value from citadel.rc */
 
 /*
  * here is our 'clean up gracefully and exit' routine
@@ -153,7 +159,7 @@ void catch_sigcont(int signum)
 
 void formout(char *name)
 {                              /* display a file */
-       char cmd[256];
+       char cmd[SIZ];
        snprintf(cmd, sizeof cmd, "MESG %s", name);
        serv_puts(cmd);
        serv_gets(cmd);
@@ -169,8 +175,8 @@ void formout(char *name)
 
 void userlist(char *patn)
 {
-       char buf[256];
-       char fl[256];
+       char buf[SIZ];
+       char fl[SIZ];
        struct tm *tmbuf;
        time_t lc;
 
@@ -297,7 +303,7 @@ char *pop_march(int desired_floor)
  */
 void dotgoto(char *towhere, int display_name)
 {
-       char aaa[256], bbb[256], psearch[256];
+       char aaa[SIZ], bbb[SIZ], psearch[SIZ];
        static long ls = 0L;
        int newmailcount;
        static int oldmailcount = (-1);
@@ -424,7 +430,7 @@ void dotgoto(char *towhere, int display_name)
  */
 void gotonext(void)
 {
-       char buf[256];
+       char buf[SIZ];
        struct march *mptr, *mptr2;
        char next_room[ROOMNAMELEN];
 
@@ -484,7 +490,7 @@ void gotonext(void)
  */
 void forget_all_rooms_on(int ffloor)
 {
-       char buf[256];
+       char buf[SIZ];
        struct march *flist, *fptr;
 
        printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
@@ -551,7 +557,7 @@ void gotofloor(char *towhere, int mode)
 {
        int a, tofloor;
        struct march *mptr;
-       char buf[256], targ[256];
+       char buf[SIZ], targ[SIZ];
 
        if (floorlist[0][0] == 0)
                load_floorlist();
@@ -674,7 +680,7 @@ int set_password(void)
 {
        char pass1[20];
        char pass2[20];
-       char buf[256];
+       char buf[SIZ];
 
        if (strlen(rc_password) > 0) {
                strcpy(pass1, rc_password);
@@ -704,7 +710,7 @@ int set_password(void)
 /*
  * get info about the server we've connected to
  */
-void get_serv_info(void)
+void get_serv_info(char *supplied_hostname)
 {
        char buf[512];
 
@@ -714,7 +720,15 @@ void get_serv_info(void)
        snprintf(buf, sizeof buf, "IDEN %d|%d|%d|%s|",
                 SERVER_TYPE, 0, REV_LEVEL,
                 (server_is_local ? "local" : CITADEL));
-       locate_host(&buf[strlen(buf)]);         /* append to the end */
+
+       /* Append a hostname */
+       if (supplied_hostname != NULL) {
+               strcat(buf, supplied_hostname);
+       }
+       else {
+               locate_host(&buf[strlen(buf)]); /* append to the end */
+       }
+
        serv_puts(buf);
        serv_gets(buf);         /* we don't care about the result code */
 }
@@ -728,10 +742,10 @@ void get_serv_info(void)
  */
 void who_is_online(int longlist)
 {
-       char buf[256], username[256], roomname[256], fromhost[256];
-       char flags[256];
-       char actual_user[256], actual_room[256], actual_host[256];
-       char tbuf[256], clientsoft[256];
+       char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
+       char flags[SIZ];
+       char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
+       char tbuf[SIZ], clientsoft[SIZ];
        time_t timenow = 0;
        time_t idletime, idlehours, idlemins, idlesecs;
        int last_session = (-1);
@@ -824,34 +838,17 @@ void enternew(char *desc, char *buf, int maxlen)
 }
 
 
-void proto_sync_check(void) {          /* FIXME ... remove this */
-       char buf[256];
-       char token[256];
-       FILE *fp;
 
-       safestrncpy(token, tmpnam(NULL), sizeof token);
-       sprintf(buf, "ECHO %s", token);
-       serv_puts(buf);
-       serv_gets(buf);
-       if (!strcmp(&buf[4], token)) return;
+int shift(int argc, char **argv, int start, int count) {
+       int i;
 
-       fp = fopen(token, "w");
-       fprintf(fp, "%s\n", buf);
-       while (serv_gets(buf), strcmp(&buf[4], token)) {
-               fprintf(fp, "%s\n", buf);
+       for (i=start; i<(argc-count); ++i) {
+               argv[i] = argv[i+count];
        }
-       fclose(fp);
-
-       sprintf(buf, "gedit %s &", token);
-       system(buf);
-       sleep(3);
-       unlink(token);
+       argc = argc - count;
+       return argc;
 }
 
-
-
-
-
 /*
  * main
  */
@@ -860,9 +857,12 @@ int main(int argc, char **argv)
        int a, b, mcmd;
        char aaa[100], bbb[100];/* general purpose variables */
        char argbuf[32];        /* command line buf */
-       volatile int termn8 = 0;
+       char nonce[NONCE_SIZE];
+       char *telnet_client_host = NULL;
+       char *sptr, *sptr2;     /* USed to extract the nonce */
+       char hexstring[MD5_HEXSTRING_SIZE];
        int stored_password = 0;
-       char password[256];
+       char password[SIZ];
 
        sttybbs(SB_SAVE);       /* Store the old terminal parameters */
        load_command_set();     /* parse the citadel.rc file */
@@ -871,6 +871,20 @@ int main(int argc, char **argv)
        signal(SIGTERM, dropcarr);      /* Cleanup gracefully if terminated */
        signal(SIGCONT, catch_sigcont);         /* Catch SIGCONT so we can reset terminal */
 
+       /* 
+        * Handle command line options as if we were called like /bin/login
+        * (i.e. from in.telnetd)
+        */
+       for (a=0; a<argc; ++a) {
+               if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
+                       telnet_client_host = argv[a+1];
+                       argc = shift(argc, argv, a, 2);
+               }
+               if (!strcmp(argv[a], "-p")) {
+                       argc = shift(argc, argv, a, 1);
+               }
+       }
+
        printf("Attaching to server... \r");
        fflush(stdout);
        attach_to_server(argc, argv, hostbuf, portbuf);
@@ -882,7 +896,30 @@ int main(int argc, char **argv)
                printf("%s\n", &aaa[4]);
                logoff(atoi(aaa));
        }
-       get_serv_info();
+
+/* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
+ * is zeroized.
+ */
+       
+       if ((sptr = strchr(aaa, '<')) == NULL)
+       {
+          nonce[0] = '\0';
+       }
+       else
+       {
+          if ((sptr2 = strchr(sptr, '>')) == NULL)
+          {
+             nonce[0] = '\0';
+          }
+          else
+          {
+             sptr2++;
+             *sptr2 = '\0';
+             strncpy(nonce, sptr, NONCE_SIZE);
+          }
+       }
+       
+       get_serv_info(telnet_client_host);
 
        look_for_ansi();
        cls(0);
@@ -902,10 +939,18 @@ 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);
+                       snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
                        serv_puts(aaa);
                        serv_gets(aaa);
-                       sprintf(aaa, "PASS %s", password);
+                       if (nonce[0])
+                       {
+                               sprintf(aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring));
+                       }
+                       else    /* Else no APOP */
+                       {
+                               snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
+                       }
+                       
                        serv_puts(aaa);
                        serv_gets(aaa);
                        if (aaa[0] == '2') {
@@ -954,7 +999,16 @@ GSTA:      /* See if we have a username and password on disk */
                newprompt("\rPlease enter your password: ", password, -19);
        }
        strproc(password);
-       snprintf(aaa, sizeof aaa, "PASS %s", password);
+
+       if (nonce[0])
+       {
+               sprintf(aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring));
+       }
+       else    /* Else no APOP */
+       {
+                       snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
+       }
+       
        serv_puts(aaa);
        serv_gets(aaa);
        if (aaa[0] == '2') {
@@ -987,8 +1041,16 @@ NEWUSR:   if (strlen(rc_password) == 0) {
 
        enter_config(1);
 
+PWOK:
+       /* Switch color support on or off if we're in user mode */
+       if (rc_ansi_color == 3) {
+               if (userflags & US_COLOR)
+                       enable_color = 1;
+               else
+                       enable_color = 0;
+       }
 
-PWOK:  printf("%s\nAccess level: %d (%s)\nUser #%ld / Call #%d\n",
+       printf("%s\nAccess level: %d (%s)\nUser #%ld / Call #%d\n",
               fullname, axlevel, axdefs[(int) axlevel],
               usernum, timescalled);
 
@@ -1058,13 +1120,12 @@ PWOK:   printf("%s\nAccess level: %d (%s)\nUser #%ld / Call #%d\n",
        else
                readmsgs(1, 1, 0);
 
-       do {                    /* MAIN LOOP OF PROGRAM */
-
-               proto_sync_check();     /* FIXME ... remove this */
-               mcmd = getcmd(argbuf);
+       /* MAIN COMMAND LOOP */
+       do {
+               mcmd = getcmd(argbuf);          /* Get keyboard command */
 
 #ifdef TIOCGWINSZ
-               check_screen_dims();
+               check_screen_dims();            /* if xterm, get screen size */
 #endif
 
                if (termn8 == 0)
@@ -1442,11 +1503,13 @@ PWOK:   printf("%s\nAccess level: %d (%s)\nUser #%ld / Call #%d\n",
                        }       /* end switch */
        } while (termn8 == 0);
 
-      TERMN8:printf("%s logged out.\n", fullname);
-       while (march != NULL)
+TERMN8:        printf("%s logged out.\n", fullname);
+       while (march != NULL) {
                remove_march(march->march_name, 0);
-       if (mcmd == 30)
+       }
+       if (mcmd == 30) {
                printf("\n\nType 'off' to hang up, or next user...\n");
+       }
        snprintf(aaa, sizeof aaa, "LOUT");
        serv_puts(aaa);
        serv_gets(aaa);
@@ -1456,4 +1519,4 @@ PWOK:     printf("%s\nAccess level: %d (%s)\nUser #%ld / Call #%d\n",
        }
        goto GSTA;
 
-}                              /* end main() */
+}      /* end main() */