[PATCH] make srvmgr work again

Michael Glauche mg at plum.de
Wed May 3 23:55:11 GMT 2000


--- /usr/src/orig/samba-tng-alpha.2.5.3/source/Makefile.in      Tue May  2
13:09:17 2000
+++ Makefile.in Thu May  4 00:45:35 2000
@@ -370,8 +370,6 @@
 SRVSVCD_OBJ = $(MSRPCD_OBJ) $(SRVSVCD_OBJ1) \
            $(RPC_SRVUTIL_OBJ) \
            $(PROFILE_OBJ)  \
+           $(LOCKING_OBJ) \
+          $(UBIQXLIB) \
            $(SIDDB_OBJ) \
                $(LIBSTATUS_OBJ)

@@ -411,8 +409,6 @@

 NETLOGOND_OBJ = $(MSRPCD_OBJ) $(NETLOGOND_OBJ1) \
            $(RPC_SRVUTIL_OBJ) \
+           $(LOCKING_OBJ) \
+          $(UBIQXLIB) \
            $(SIDDB_OBJ) \
                $(UNIXPASSDB_OBJ) $(LIBSTATUS_OBJ) $(PROFILE_OBJ)

--- /usr/src/orig/samba-tng-alpha.2.5.3/source/lib/util_status.c        Thu Apr
13 05:29:2
1 2000
+++ lib/util_status.c   Thu May  4 01:37:26 2000
@@ -3,7 +3,7 @@
    Version 1.9.
    Samba connection status utility functions
    Copyright (C) Andrew Tridgell 1992-1999
-   Copyright (C) Michael Glauche 1999
+   Copyright (C) Michael Glauche 1999-2000

    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
@@ -18,11 +18,18 @@
    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.
+
+   Revision History:
+
+   2. may 2000: mg at glauche.de
+   added TDB status lookup
 */

 #include "includes.h"

 extern int DEBUGLEVEL;
+static int status_locks_count;
+static int status_locks_pid;

 /*******************************************************************
 parse the STATUS..LCK file.  caller is responsible for freeing *crec.
@@ -32,37 +39,44 @@
 {
   int fd;
   pstring fname;
+  TDB_CONTEXT *tdb;
+  TDB_DATA key,nextkey,d;
   int conn;
   int num_recs;
   struct connect_record *c;
+  struct connections_data cdata;
   int i;

   if (crec == NULL || connection_count == NULL)
   {
     return False;
   }
-
-  pstrcpy(fname,lp_lockdir());
-  standard_sub_basic(fname);
-  trim_string(fname,"","/");
-  pstrcat(fname,"/STATUS..LCK");
+  conn = 0;

-  fd = sys_open(fname,O_RDONLY, 0);
-
-  if (fd == -1)
-  {
-    DEBUG(0,("Couldn't open status file %s\n",fname));
+  tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0);
+  if (!tdb) {
+    DEBUG(0,("connections.tdb not initialised\n"));
+    if (!lp_status(-1))
+       DEBUG(0,("You need to have status=yes in your smb config file\n"));
+
     return False;
+  }  else {
+       DEBUG(5,("Opened TDB status file\n"));
   }
-
+
   (*crec) = NULL;
-
-   num_recs = get_file_size(fname) / sizeof(*c);
+  conn = 0;

-  DEBUG(5,("Opened status file %s, record count %d\n",fname, num_recs));
+  key = tdb_firstkey(tdb);
+  while (key.dptr) {
+    d = tdb_fetch(tdb, key);

-   for (i = 0, conn = 0; i < num_recs; i++)
-   {
+    memcpy(&cdata, d.dptr, sizeof(cdata));
+
+    DEBUG(5,("TDB status cnum = %d\n",cdata.cnum));
+    DEBUG(5,("TDB status pid = %u\n",cdata.pid));
+
+    if ((cdata.cnum != -1) && (process_exists(cdata.pid))) {
         (*crec) = Realloc((*crec), (conn+1) * sizeof((*crec)[conn]));
         if ((*crec) == NULL)
             {
@@ -71,25 +85,26 @@
             }

        c = &((*crec)[conn]);
-       if (sys_lseek(fd,i*sizeof(*c),SEEK_SET) != i*sizeof(*c) ||
-           read(fd,c,sizeof(*c)) != sizeof(*c))
-        {
-          DEBUG(0,("unable to read a crec in get_connection_status\n"));
-         break;
-        }
-       DEBUG(10,("cnum:%u.  pid: %d magic: %x\n",
-                  c->cnum, c->pid, c->magic));
-
-       /* valid connection, smbd process still going, connection still going */
-       if ( c->magic == 0x280267 && process_exists(c->pid) && c->cnum != -1 )
-         {
-              conn++;
-         }
-
-      }
-    close(fd);
-    (*connection_count)=conn;
-    return True;
+        c->uid = cdata.uid;
+       c->pid = cdata.pid;
+       c->cnum = cdata.cnum;
+       pstrcpy(c->name,cdata.name);
+       pstrcpy(c->addr,cdata.addr);
+       pstrcpy(c->machine,cdata.machine);
+       c->start = cdata.start;
+
+        DEBUG(5,("TDB status name = %s\n",c->name));
+        conn++;
+    }
+
+    nextkey = tdb_nextkey(tdb, key);
+    free(key.dptr);
+    free(d.dptr);
+    key = nextkey;
+  }
+
+  (*connection_count)=conn;
+  return True;
 }

 /*******************************************************************
@@ -114,17 +129,20 @@
      MaxPid = 0;
      for (conn = 0; conn < connection_count; conn++)
        {
-         DEBUG(10,("Connection nr : %u\n",conn));
+         DEBUG(3,("Connection nr : %u\n",conn));
          found=False;
          for (i = 0; i < MaxPid; i++)
         {
            if (crec[conn].pid == pid[i])
           {
+             DEBUG(3,("Session count - found PID : %u\n",pid[i]));
+
              found = True;
              i=MaxPid;
            }
          }
          if (!found) {
+            DEBUG(3,("Session count - did not found PID :
%u\n",crec[conn].pid));
            (*srec) = Realloc((*srec), (MaxPid+1) * sizeof((*srec)[MaxPid]));
            if ((*srec) == NULL)
             {
@@ -144,6 +162,7 @@
           c->uid = crec[conn].uid;
           c->pid = crec[conn].pid;
           c->cnum = crec[conn].cnum;
+          c->start = crec[conn].start;
           pstrcpy(c->name,crec[conn].name);

            MaxPid++;
@@ -158,3 +177,36 @@
    return True;
 }

+/*******************************************************************
+Get the number of open Locks. uses global variables *yuck* any
+other way to get the share modes without a traverse function ????
+ ********************************************************************/
+
+
+void status_traverse_share_mode(share_mode_entry *e, char *fname)
+{
+   if ((int)e->pid == status_locks_pid) {
+       status_locks_count ++;
+   }
+}
+
+BOOL get_locks_count(int pid, uint32 *locks_count)
+{
+  int ret;
+
+  if (pid < 1)
+  {
+    return False;
+  }
+  status_locks_count = 0;
+  status_locks_pid = pid;
+
+  if (!locking_init(1)) {
+       DEBUG(0,("Can't initialise shared memory - exiting\n"));
+       return False;
+  }
+  ret = share_mode_forall(status_traverse_share_mode);
+  locking_end();
+  DEBUG(3,("Locks found for PID %u : %u\n",pid,status_locks_count));
+  (*locks_count) = status_locks_count;
+}
\ No newline at end of file
--- /usr/src/orig/samba-tng-alpha.2.5.3/source/srvsvcd/srv_srvsvc_nt.c  Tue May
2 13:10:2
0 2000
+++ srvsvcd/srv_srvsvc_nt.c     Thu May  4 01:37:27 2000
@@ -710,7 +710,10 @@
        uint32 num_entries = 0;
        struct connect_record *crec;
        uint32 session_count;
-
+       uint32 lock_count;
+       time_t current_time;
+       time_t diff;
+
        if (!get_session_count(&crec, &session_count))
        {
                (*snum) = 0;
@@ -729,7 +732,8 @@
        }

        DEBUG(5, ("make_srv_sess_1_ss1\n"));
-
+       current_time = time(NULL);
+
        if (snum)
        {
                for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES;
@@ -738,12 +742,16 @@
                        DEBUG(0, ("sess1 machine: %s, uid : %u\n",
                                  crec[num_entries].machine,
                                  (uint32)crec[num_entries].uid));
+                       if (!get_locks_count(crec[num_entries].pid,
&lock_count)) {
+                               lock_count = 0;
+                       }
+                       diff = current_time - crec[num_entries].start;
                        make_srv_sess_1_info(&(ss1->info_1[num_entries]),
                                             &(ss1->info_1_str[num_entries]),
                                             crec[num_entries].machine,
                                             uidtoname(crec[num_entries].uid),
-                                            1, 10, 5, 0);
-/*     What are these on the End ??? */
+                                            lock_count, diff, diff, 0);
+/*     what is "user flags" ?? */

                        /* move on to creating next session */
                        /* move on to creating next sess */
@@ -969,7 +977,8 @@

        struct connect_record *crec;
        uint32 connection_count;
-
+        uint32 lock_count;
+
        if (!get_connection_status(&crec, &connection_count))
        {
                (*snum) = 0;
@@ -995,9 +1004,12 @@
                     (*snum)++)
                {
                        diff = current_time - crec[num_entries].start;
+                       if (!get_locks_count(crec[num_entries].pid,
&lock_count)) {
+                               lock_count = 0;
+                       }
                        make_srv_conn_1_info(&(ss1->info_1[num_entries]),
                                             &(ss1->info_1_str[num_entries]),
-                                            (*snum), 0, 0, 1, diff,
+                                            (*snum), 0, lock_count, 1, diff,
                                             uidtoname(crec[num_entries].uid),
                                             crec[num_entries].name);



This should make srvmgr work, it even seems to display the number of locked
files per session
correctly ;)

regards,
    Michael



More information about the samba-technical mailing list