A few changes:
authorAndrew Bartlett <abartlet@samba.org>
Wed, 22 Aug 2001 19:11:55 +0000 (19:11 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 22 Aug 2001 19:11:55 +0000 (19:11 +0000)
drop paramaters:
 status
 utmp hostname

change session code to always record each vuid current on the server.  The sessionid struct is no longer packed, as I couldn't get that to work ;-)

change smbstatus to show this info and less of the connections.tdb info (its not actualy that accurate).

I'll get swat doing some of this shortly.
(This used to be commit b068ad300527c44673bbee0aede7849199c89de7)

source3/include/includes.h
source3/include/session.h [new file with mode: 0644]
source3/param/loadparm.c
source3/smbd/reply.c
source3/smbd/server.c
source3/smbd/session.c
source3/utils/status.c
source3/web/statuspage.c

index 63bcb1192e55cb3e3797b7ca77ac704da459454a..8b138030ef9c9987d0e5f982d35b660b7fd17c6e 100644 (file)
@@ -668,6 +668,8 @@ extern int errno;
 
 #include "auth.h"
 
+#include "session.h"
+
 #ifndef MAXCODEPAGELINES
 #define MAXCODEPAGELINES 256
 #endif
diff --git a/source3/include/session.h b/source3/include/session.h
new file mode 100644 (file)
index 0000000..9091223
--- /dev/null
@@ -0,0 +1,41 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 2.0
+   session handling for recording currently vailid vuids
+   Copyright (C) tridge@samba.org 2001
+   Copyright (C) Andew Bartlett <abartlet@samba.org> 2001
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/* a "session" is claimed when we do a SessionSetupX operation
+   and is yielded when the corresponding vuid is destroyed.
+
+   sessions are used to populate utmp and PAM session structures
+*/
+
+struct sessionid {
+       uid_t uid;
+       gid_t gid;
+       fstring username;
+       fstring hostname;
+       fstring netbios_name;
+       fstring remote_machine;
+       fstring id_str;
+       uint32  id_num;
+       uint32  pid;
+       fstring ip_addr;
+};
+
index 543e9bab9f5e82e8d6d01eb8769a57dcd47259b0..85bcd52ff182e4011c4ccacf4612c27eea83462f 100644 (file)
@@ -149,7 +149,6 @@ typedef struct
 #ifdef WITH_UTMP
        char *szUtmpDir;
        char *szWtmpDir;
-       char *szUtmpHostname;
        BOOL bUtmp;
 #endif
        char *szSourceEnv;
@@ -342,7 +341,6 @@ typedef struct
        BOOL bCasePreserve;
        BOOL bShortCasePreserve;
        BOOL bCaseMangle;
-       BOOL status;
        BOOL bHideDotFiles;
        BOOL bHideUnReadable;
        BOOL bBrowseable;
@@ -457,7 +455,6 @@ static service sDefault = {
        True,                   /* case preserve */
        True,                   /* short case preserve */
        False,                  /* case mangle */
-       True,                   /* status */
        True,                   /* bHideDotFiles */
        False,                  /* bHideUnReadable */
        True,                   /* bBrowseable */
@@ -762,8 +759,6 @@ static struct parm_struct parm_table[] = {
        {"debug pid", P_BOOL, P_GLOBAL, &Globals.bDebugPid, NULL, NULL, 0},
        {"debug uid", P_BOOL, P_GLOBAL, &Globals.bDebugUid, NULL, NULL, 0},
        
-       {"status", P_BOOL, P_LOCAL, &sDefault.status, NULL, NULL, FLAG_GLOBAL | FLAG_SHARE | FLAG_PRINT},
-
        {"Protocol Options", P_SEP, P_SEPARATOR},
        
        {"protocol", P_ENUM, P_GLOBAL, &Globals.maxprotocol, NULL, enum_protocol, 0},
@@ -960,7 +955,6 @@ static struct parm_struct parm_table[] = {
 #ifdef WITH_UTMP
        {"utmp directory", P_STRING, P_GLOBAL, &Globals.szUtmpDir, NULL, NULL, 0},
        {"wtmp directory", P_STRING, P_GLOBAL, &Globals.szWtmpDir, NULL, NULL, 0},
-       {"utmp hostname", P_STRING, P_GLOBAL, &Globals.szUtmpHostname, NULL, NULL, 0},
        {"utmp",          P_BOOL, P_GLOBAL, &Globals.bUtmp, NULL, NULL, 0},
 #endif
        
@@ -1193,7 +1187,6 @@ static void init_globals(void)
 #ifdef WITH_UTMP
        string_set(&Globals.szUtmpDir, "");
        string_set(&Globals.szWtmpDir, "");
-       string_set(&Globals.szUtmpHostname, "%m");
        Globals.bUtmp = False;
 #endif
        string_set(&Globals.szSocketAddress, "0.0.0.0");
@@ -1436,7 +1429,6 @@ FN_GLOBAL_STRING(lp_lockdir, &Globals.szLockDir)
 #ifdef WITH_UTMP
 FN_GLOBAL_STRING(lp_utmpdir, &Globals.szUtmpDir)
 FN_GLOBAL_STRING(lp_wtmpdir, &Globals.szWtmpDir)
-FN_GLOBAL_STRING(lp_utmp_hostname, &Globals.szUtmpHostname)
 FN_GLOBAL_BOOL(lp_utmp, &Globals.bUtmp)
 #endif
 FN_GLOBAL_STRING(lp_rootdir, &Globals.szRootdir)
@@ -1643,7 +1635,6 @@ FN_LOCAL_BOOL(lp_casesensitive, bCaseSensitive)
 FN_LOCAL_BOOL(lp_preservecase, bCasePreserve)
 FN_LOCAL_BOOL(lp_shortpreservecase, bShortCasePreserve)
 FN_LOCAL_BOOL(lp_casemangle, bCaseMangle)
-FN_LOCAL_BOOL(lp_status, status)
 FN_LOCAL_BOOL(lp_hide_dot_files, bHideDotFiles)
 FN_LOCAL_BOOL(lp_hideunreadable, bHideUnReadable)
 FN_LOCAL_BOOL(lp_browseable, bBrowseable)
@@ -1883,7 +1874,6 @@ static BOOL lp_add_ipc(char *ipc_name, BOOL guest_ok)
        string_set(&ServicePtrs[i]->szUsername, "");
        string_set(&ServicePtrs[i]->comment, comment);
        string_set(&ServicePtrs[i]->fstype, "IPC");
-       ServicePtrs[i]->status = False;
        ServicePtrs[i]->iMaxConnections = 0;
        ServicePtrs[i]->bAvailable = True;
        ServicePtrs[i]->bRead_only = True;
index bef1b1508474cdea7bad90e57cd3a6d54720afe6..b4fb6693e62598e0b1ac71a0fc15210ebcf2a672 100644 (file)
@@ -127,9 +127,7 @@ int reply_special(char *inbuf,char *outbuf)
                reload_services(True);
                reopen_logs();
 
-               if (lp_status(-1)) {
-                       claim_connection(NULL,"",MAXSTATUS,True);
-               }
+               claim_connection(NULL,"",MAXSTATUS,True);
 
                break;
                
index 13071a5b65b88ce660d59c294af6281785e018ee..5bcb47393a63a1cc4f3ec7d240f648ab2128ceb2 100644 (file)
@@ -459,9 +459,7 @@ void exit_server(char *reason)
        invalidate_all_vuids();
 
        /* delete our entry in the connections database. */
-       if (lp_status(-1)) {
-               yield_connection(NULL,"",MAXSTATUS);
-       }
+       yield_connection(NULL,"",MAXSTATUS);
 
        respond_to_all_remaining_local_messages();
        decrement_smbd_process_count();
@@ -751,9 +749,7 @@ static void usage(char *pname)
        }
 
        /* Setup the main smbd so that we can get messages. */
-       if (lp_status(-1)) {
-               claim_connection(NULL,"",MAXSTATUS,True);
-       }
+       claim_connection(NULL,"",MAXSTATUS,True);
 
        /* Attempt to migrate from an old 2.0.x machine account file. */
        if (!migrate_from_old_password_file(global_myworkgroup)) {
index 7616689fe0c360a563abeb61ef5f8afa3fc21570..78c635d7cf0e0b09fec23e9bb79185fe61115b66 100644 (file)
 
 #include "includes.h"
 
-#if defined(WITH_PAM) || defined(WITH_UTMP)
+extern fstring remote_machine;
 
 static TDB_CONTEXT *tdb;
-struct sessionid {
-       fstring username;
-       fstring hostname;
-       fstring id_str;
-       uint32  id_num;
-       uint32  pid;
-};
-
 /* called when a session is created */
 BOOL session_claim(uint16 vuid)
 {
@@ -98,6 +90,10 @@ BOOL session_claim(uint16 vuid)
        slprintf(sessionid.id_str, sizeof(sessionid.id_str)-1, SESSION_TEMPLATE, i);
        sessionid.id_num = i;
        sessionid.pid = pid;
+       sessionid.uid = vuser->uid;
+       sessionid.gid = vuser->gid;
+       fstrcpy(sessionid.remote_machine, remote_machine);
+       fstrcpy(sessionid.ip_addr, client_addr());
 
        if (!smb_pam_claim_session(sessionid.username, sessionid.id_str, sessionid.hostname)) {
                DEBUG(1,("pam_session rejected the session for %s [%s]\n",
@@ -106,12 +102,8 @@ BOOL session_claim(uint16 vuid)
                return False;
        }
 
-       dlen = tdb_pack(dbuf, sizeof(dbuf), "fffdd",
-                       sessionid.username, sessionid.hostname, sessionid.id_str,
-                       sessionid.id_num, sessionid.pid);
-
-       data.dptr = dbuf;
-       data.dsize = dlen;
+       data.dptr = (char *)&sessionid;
+       data.dsize = sizeof(sessionid);
        if (tdb_store(tdb, key, data, TDB_MODIFY) != 0) {
                DEBUG(1,("session_claim: unable to create session id record\n"));
                return False;
@@ -132,7 +124,7 @@ BOOL session_claim(uint16 vuid)
 void session_yield(uint16 vuid)
 {
        user_struct *vuser = get_valid_user_struct(vuid);
-       TDB_DATA data;
+       TDB_DATA dbuf;
        struct sessionid sessionid;
        TDB_DATA key;           
        fstring keystr;
@@ -148,17 +140,15 @@ void session_yield(uint16 vuid)
        key.dptr = keystr;
        key.dsize = strlen(keystr)+1;
 
-       data = tdb_fetch(tdb, key);
-       if (data.dptr == NULL) {
+       dbuf = tdb_fetch(tdb, key);
+
+       if (dbuf.dsize != sizeof(sessionid))
                return;
-       }
 
-       tdb_unpack(data.dptr, data.dsize, "fffdd",
-                  &sessionid.username, &sessionid.hostname, &sessionid.id_str,
-                  &sessionid.id_num, &sessionid.pid);
+       memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
 
-       safe_free(data.dptr);
-       data.dptr = NULL;
+       safe_free(dbuf.dptr);
+       dbuf.dptr = NULL;
 
 #if WITH_UTMP  
        if (lp_utmp()) {
@@ -172,8 +162,3 @@ void session_yield(uint16 vuid)
        tdb_delete(tdb, key);
 }
 
-#else
- /* null functions - no session support needed */
- BOOL session_claim(uint16 vuid) { return True; }
- void session_yield(uint16 vuid) {} 
-#endif
index e5beb6403c8ca5296cb8c3795973d7fa93c5d259..36de6858f103ea249cbcbead4890afa5f756b1c5 100644 (file)
@@ -198,41 +198,33 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st
                return 0;
        }
 
-       if (brief) {
-               ptr=srecs;
-               while (ptr!=NULL) {
-                       if ((ptr->pid==crec.pid)&&(strncmp(ptr->machine,crec.machine,30)==0)) {
-                               if (ptr->start > crec.start)
-                                       ptr->start=crec.start;
-                               break;
-                       }
-                       ptr=ptr->next;
-               }
-               if (ptr==NULL) {
-                       ptr=(struct session_record *) malloc(sizeof(struct session_record));
-                       ptr->uid=crec.uid;
-                       ptr->pid=crec.pid;
-                       ptr->start=crec.start;
-                       strncpy(ptr->machine,crec.machine,30);
-                       ptr->machine[30]='\0';
-                       ptr->next=srecs;
-                       srecs=ptr;
-               }
-       } else {
-               Ucrit_addPid(crec.pid);  
-               if (processes_only) {
-                       if (last_pid != crec.pid)
-                               printf("%d\n",(int)crec.pid);
-                       last_pid = crec.pid; /* XXXX we can still get repeats, have to
-                                               add a sort at some time */
-               } else {
-                       printf("%-10.10s   %-8s %-8s %5d   %-8s (%s) %s",
-                              crec.name,uidtoname(crec.uid),gidtoname(crec.gid),(int)crec.pid,
-                              crec.machine,crec.addr,
-                              asctime(LocalTime(&crec.start)));
-               }
+       printf("%-10.10s   %5d   %-12s  %s",
+              crec.name,(int)crec.pid,
+              crec.machine,
+              asctime(LocalTime(&crec.start)));
+
+       return 0;
+}
+
+static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
+{
+       static pid_t last_pid;
+       struct session_record *ptr;
+       struct sessionid sessionid;
+
+       if (dbuf.dsize != sizeof(sessionid))
+               return 0;
+
+       memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
+
+       if (!process_exists(sessionid.pid) || !Ucrit_checkUsername(uidtoname(sessionid.uid))) {
+               return 0;
        }
 
+       printf("%5d   %-12s  %-12s  %-12s (%s)\n",
+              (int)sessionid.pid, uidtoname(sessionid.uid), gidtoname(sessionid.gid), 
+              sessionid.remote_machine, sessionid.hostname);
+       
        return 0;
 }
 
@@ -316,46 +308,38 @@ static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st
                return profile_dump();
        }
        
+       tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0);
+       if (!tdb) {
+               printf("sessionid.tdb not initialised\n");
+       }
+
+       if (locks_only) goto locks;
+
+       printf("\nSamba version %s\n",VERSION);
+       printf("PID     Username      Group         Machine                        \n");
+       printf("-------------------------------------------------------------------\n");
+
+       tdb_traverse(tdb, traverse_sessionid, NULL);
+       tdb_close(tdb);
+  
        tdb = tdb_open_log(lock_path("connections.tdb"), 0, USE_TDB_MMAP_FLAG, O_RDONLY, 0);
        if (!tdb) {
                printf("connections.tdb not initialised\n");
-               if (!lp_status(-1))
-                       printf("You need to have status=yes in your smb config file\n");
-               return(0);
        }  else if (verbose) {
                printf("Opened status file %s\n", fname);
        }
 
-       if (locks_only) goto locks;
+       if (brief) 
+               exit(0);
+       
+       printf("\nService      pid     machine       Connected at\n");
+       printf("-------------------------------------------------------\n");
 
-       printf("\nSamba version %s\n",VERSION);
-       if (brief) {
-               printf("PID     Username  Machine                       Time logged in\n");
-               printf("-------------------------------------------------------------------\n");
-       } else {
-               printf("Service      uid      gid      pid     machine\n");
-               printf("----------------------------------------------\n");
-       }
        tdb_traverse(tdb, traverse_fn1, NULL);
        tdb_close(tdb);
 
  locks:
        if (processes_only) exit(0);
-  
-       if (brief)  {
-               ptr=srecs;
-               while (ptr!=NULL) {
-                       printf("%-8d%-10.10s%-30.30s%s",
-                              (int)ptr->pid,uidtoname(ptr->uid),
-                              ptr->machine,
-                              asctime(LocalTime(&(ptr->start))));
-                       ptr=ptr->next;
-               }
-               printf("\n");
-               exit(0);
-       }
-
-       printf("\n");
 
        if (!shares_only) {
                int ret;
index dc26e86ef88c2b1e0f269de4fd37935522a3bcc5..c112deb224a5aa214f3dd6c6eb0d970d7e347add 100644 (file)
@@ -209,9 +209,7 @@ void status_page(void)
 
        if (!tdb) {
                /* open failure either means no connections have been
-                   made or status=no */
-               if (!lp_status(-1))
-                       printf("You need to have status=yes in your smb config file\n");
+                   made */
        }