[PATCH] smbtree_showsharetype.patch

Seb James seb at esfnet.co.uk
Tue Feb 10 04:49:34 MST 2009


Hi List,

I have a patch for smbtree.c made against samba 3.3.0 which adds an
option for the user to include the share type in the list of shares
which smbtree prints.

I'd very much welcome feedback from the smbtree maintainer about this
patch and whether it might make it into the samba source. If it's not
thought a suitable change, I'd like to know if any code changes would
alter that.

I use this in our network printing appliance to obtain a list of file
shares; the extra info in the listing enables me to omit Print/IPC share
from a menu showing the available shares on the network.

smbtree -? shows the new option:

[seb at circle 11:42:54 utils]$ /opt/samba-3.3.0/bin/smbtree -?   
Usage: [OPTION...]
  -b, --broadcast                    Use broadcast instead of using the master
                                     browser
  -D, --domains                      List only domains (workgroups) of tree
  -S, --servers                      List domains(workgroups) and servers of
                                     tree
  -H, --sharetype                    Include the share type (Disk, print, IPC)
                                     in the output

Help options:
  -?, --help                         Show this help message
  --usage                            Display brief usage message

Common samba options:
  -d, --debuglevel=DEBUGLEVEL        Set debug level
  -s, --configfile=CONFIGFILE        Use alternate configuration file
  -l, --log-basename=LOGFILEBASE     Base name for log files
  -V, --version                      Print version

Authentication options:
  -U, --user=USERNAME                Set the network username
  -N, --no-pass                      Don't ask for a password
  -k, --kerberos                     Use kerberos (active directory)
                                     authentication
  -A, --authentication-file=FILE     Get the credentials from a file
  -S, --signing=on|off|required      Set the client signing state
  -P, --machine-pass                 Use stored machine account password
  -e, --encrypt                      Encrypt SMB transport (UNIX extended
                                     servers only)


Here is an example of the output, where I have used the -H tag to show
share type. Without the -H tag, the operation of smbtree is unchanged
from what people will be familiar with:

[seb at circle 11:36:37 source]$ /opt/samba-3.3.0/bin/smbtree -H -N
ESFNET  
        \\CIRCLE                        circle server (Samba, Debian)
                \\CIRCLE\blackhole              Print           A print queue which disappears any print jobs into /dev/null
                \\CIRCLE\hp1320                 Print           hp1320
                \\CIRCLE\kyo1300                Print           Kyocera FS-1300D mono laserjet
                \\CIRCLE\IPC$                   IPC             IPC Service (circle server (Samba, Debian))
                \\CIRCLE\allusers               Disk            All Users
                \\CIRCLE\TamArchive             Disk            Tams Test share for archive files


Patch follows inline (I call the file smbtree_showsharetype.patch):

--- smbtree.3.3.0.orig.c	2009-02-02 14:17:07.000000000 +0000
+++ smbtree.c	2009-02-02 14:17:16.000000000 +0000
@@ -22,6 +22,7 @@
 #include "includes.h"
 
 static int use_bcast;
+static int show_type;
 
 /* How low can we go? */
 
@@ -223,6 +224,7 @@
 static bool print_tree(struct user_auth_info *user_info)
 {
         struct smb_name_list *wg, *sv, *sh;
+        char share_type[16];
 
         /* List workgroups */
 
@@ -256,11 +258,46 @@
                             !get_shares(sv->name, user_info))
                                 continue;
 
-                        for (sh = shares; sh; sh = sh->next) {
-                                printf("\t\t\\\\%s\\%-15s\t%s\n", 
-				       sv->name, sh->name, sh->comment);
-                        }
-                }
+			/*
+			 * From libsmbclient.c:
+			 *
+			 * We need to process the type a little ...
+			 *
+			 * Disk share     = 0x00000000
+			 * Print share    = 0x00000001
+			 * Comms share    = 0x00000002 (obsolete?)
+			 * IPC$ share     = 0x00000003
+			 *
+			 * administrative shares:
+			 * ADMIN$, IPC$, C$, D$, E$ ...  are type |= 0x80000000
+			 */
+			for (sh = shares; sh; sh = sh->next) {
+				if (show_type) {
+					if ((sh->server_type & 0xffff) == 0) {
+						snprintf (share_type, 5, "Disk");
+					} else if ((sh->server_type & 0xffff) == 0x1) {
+						snprintf (share_type, 6, "Print");
+					} else if ((sh->server_type & 0xffff) == 0x2) {
+						snprintf (share_type, 6, "Comms");
+					} else if ((sh->server_type & 0xffff) == 0x3) {
+						snprintf (share_type, 4, "IPC");
+					} else {
+						snprintf (share_type, 8, "Unknown");
+					}
+
+					if (sh->server_type & 0x80000000) {
+						strncat (share_type, " (admin)", 8);
+					}
+
+					printf("\t\t\\\\%s\\%-15s\t%-15s\t%s\n",
+					       sv->name, sh->name, share_type, sh->comment);
+
+				} else {
+					printf("\t\t\\\\%s\\%-15s\t%s\n",
+					       sv->name, sh->name, sh->comment);
+				}
+			}
+		}
         }
 
         return True;
@@ -278,6 +315,7 @@
 		{ "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" },
 		{ "domains", 'D', POPT_ARG_VAL, &level, LEV_WORKGROUP, "List only domains (workgroups) of tree" },
 		{ "servers", 'S', POPT_ARG_VAL, &level, LEV_SERVER, "List domains(workgroups) and servers of tree" },
+		{ "sharetype", 'H', POPT_ARG_VAL, &show_type, True, "Include the share type (Disk, print, IPC) in the output" },
 		POPT_COMMON_SAMBA
 		POPT_COMMON_CREDENTIALS
 		POPT_TABLEEND



Very best regards,

Seb James






More information about the samba-technical mailing list