]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_rwho.c
mk_module_init.sh now tests to see if echo supports -e and -E
[citadel.git] / citadel / serv_rwho.c
index 5f39d9be70ae30d0730c9c7803c224e1841891a7..553049c9b3bf61da5140f91605f5851066f0f548 100644 (file)
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include <time.h>
-#include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
 #include "control.h"
-#include "dynloader.h"
 #include "room_ops.h"
 #include "user_ops.h"
 #include "policy.h"
@@ -36,6 +44,8 @@
 #include "tools.h"
 
 
+#include "ctdl_module.h"
+
 
 /*
  * display who's online
@@ -49,9 +59,9 @@ void cmd_rwho(char *argbuf) {
        int aide;
        char un[40];
        char real_room[ROOMNAMELEN], room[ROOMNAMELEN];
-       char host[40], flags[5];
+       char host[64], flags[5];
        
-       aide = CC->usersupp.axlevel >= 6;
+       aide = CC->user.axlevel >= 6;
        cprintf("%d%c \n", LISTING_FOLLOWS, CtdlCheckExpress() );
        
        for (cptr = ContextList; cptr != NULL; cptr = cptr->next) 
@@ -96,11 +106,13 @@ void cmd_rwho(char *argbuf) {
                        strcpy(room, real_room);
                }
                
-                if ((aide) && (spoofed))
-                   strcat(flags, "+");
+                if ((aide) && (spoofed)) {
+                       strcat(flags, "+");
+               }
                
-               if ((cptr->cs_flags & CS_STEALTH) && (aide))
-                  strcat(flags, "-");
+               if ((cptr->cs_flags & CS_STEALTH) && (aide)) {
+                       strcat(flags, "-");
+               }
                
                if (((cptr->cs_flags&CS_STEALTH)==0) || (aide))
                {
@@ -108,32 +120,32 @@ void cmd_rwho(char *argbuf) {
                                cptr->cs_pid, un, room,
                                host, cptr->cs_clientname,
                                (long)(cptr->lastidle),
-                               cptr->lastcmdname, flags);
-               }
-
-               if ((user_spoofed) && (aide)) {
-                       cprintf("%s|", cptr->curr_user);
-               }
-               else {
-                       cprintf("|");
-               }
-
-               if ((room_spoofed) && (aide)) {
-                       cprintf("%s|", real_room);
-               }
-               else {
-                       cprintf("|");
-               }
-
-               if ((host_spoofed) && (aide)) {
-                       cprintf("%s|", cptr->cs_host);
-               }
-               else {
-                       cprintf("|");
+                               cptr->lastcmdname, flags
+                       );
+
+                       if ((user_spoofed) && (aide)) {
+                               cprintf("%s|", cptr->curr_user);
+                       }
+                       else {
+                               cprintf("|");
+                       }
+       
+                       if ((room_spoofed) && (aide)) {
+                               cprintf("%s|", real_room);
+                       }
+                       else {
+                               cprintf("|");
+                       }
+       
+                       if ((host_spoofed) && (aide)) {
+                               cprintf("%s|", cptr->cs_host);
+                       }
+                       else {
+                               cprintf("|");
+                       }
+       
+                       cprintf("%d\n", cptr->logged_in);
                }
-
-               cprintf("\n");
-
        }
 
        /* Now it's magic time.  Before we finish, call any EVT_RWHO hooks
@@ -150,18 +162,18 @@ void cmd_rwho(char *argbuf) {
  */
 void cmd_rchg(char *argbuf)
 {
-       char newroomname[256];
+       char newroomname[ROOMNAMELEN];
 
-       extract(newroomname, argbuf, 0);
+       extract_token(newroomname, argbuf, 0, '|', sizeof newroomname);
        newroomname[ROOMNAMELEN-1] = 0;
        if (strlen(newroomname) > 0) {
                safestrncpy(CC->fake_roomname, newroomname,
                        sizeof(CC->fake_roomname) );
-               }
+       }
        else {
-               strcpy(CC->fake_roomname, "");
-               }
-       cprintf("%d OK\n", OK);
+               safestrncpy(CC->fake_roomname, "", sizeof CC->fake_roomname);
+       }
+       cprintf("%d OK\n", CIT_OK);
 }
 
 /*
@@ -169,17 +181,17 @@ void cmd_rchg(char *argbuf)
  */
 void cmd_hchg(char *argbuf)
 {
-       char newhostname[256];
+       char newhostname[64];
 
-       extract(newhostname, argbuf, 0);
+       extract_token(newhostname, argbuf, 0, '|', sizeof newhostname);
        if (strlen(newhostname) > 0) {
                safestrncpy(CC->fake_hostname, newhostname,
                        sizeof(CC->fake_hostname) );
-               }
+       }
        else {
-               strcpy(CC->fake_hostname, "");
-               }
-       cprintf("%d OK\n", OK);
+               safestrncpy(CC->fake_hostname, "", sizeof CC->fake_hostname);
+       }
+       cprintf("%d OK\n", CIT_OK);
 }
 
 
@@ -189,9 +201,9 @@ void cmd_hchg(char *argbuf)
 void cmd_uchg(char *argbuf)
 {
 
-       char newusername[256];
+       char newusername[USERNAME_SIZE];
 
-       extract(newusername, argbuf, 0);
+       extract_token(newusername, argbuf, 0, '|', sizeof newusername);
 
        if (CtdlAccessCheck(ac_aide)) return;
 
@@ -207,7 +219,7 @@ void cmd_uchg(char *argbuf)
                CC->fake_username[0] = '\0';
                CC->cs_flags |= CS_STEALTH;
        }
-       cprintf("%d\n",OK);
+       cprintf("%d\n",CIT_OK);
 }
 
 
@@ -221,21 +233,19 @@ void cmd_stel(char *cmdbuf)
        int requested_mode;
 
        requested_mode = extract_int(cmdbuf,0);
-       if (requested_mode !=0) requested_mode = 1;
 
-       if (CtdlAccessCheck(ac_aide)) return;
-
-       if (CC->cs_flags & CS_STEALTH) {
-               if (requested_mode == 0)
-                       CC->cs_flags = CC->cs_flags-CS_STEALTH;
-               }
-       else {
-               if (requested_mode == 1)
-                       CC->cs_flags = CC->cs_flags|CS_STEALTH;
-               }
+       if (CtdlAccessCheck(ac_logged_in)) return;
 
-       cprintf("%d Ok\n",OK);
+       if (requested_mode == 1) {
+               CC->cs_flags = CC->cs_flags | CS_STEALTH;
        }
+       if (requested_mode == 0) {
+               CC->cs_flags = CC->cs_flags & ~CS_STEALTH;
+       }
+
+       cprintf("%d %d\n", CIT_OK,
+               ((CC->cs_flags & CS_STEALTH) ? 1 : 0) );
+}
 
 
 
@@ -243,12 +253,14 @@ void cmd_stel(char *cmdbuf)
 
 
 
-char *Dynamic_Module_Init(void)
+CTDL_MODULE_INIT(rwho)
 {
         CtdlRegisterProtoHook(cmd_rwho, "RWHO", "Display who is online");
         CtdlRegisterProtoHook(cmd_hchg, "HCHG", "Masquerade hostname");
         CtdlRegisterProtoHook(cmd_rchg, "RCHG", "Masquerade roomname");
         CtdlRegisterProtoHook(cmd_uchg, "UCHG", "Masquerade username");
         CtdlRegisterProtoHook(cmd_stel, "STEL", "Enter/exit stealth mode");
+
+       /* return our Subversion id for the Log */
         return "$Id$";
 }