Author: jra
Date: 2007-04-16 19:10:16 +0000 (Mon, 16 Apr 2007)
New Revision: 22266

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=22266

Log:
Fix bug #4512 - we were returning a volume label greater than
32 unicode chars. Windows XP doesn't like that :-).
Jeremy

Modified:
   branches/SAMBA_3_0/source/include/smb.h
   branches/SAMBA_3_0/source/param/loadparm.c
   branches/SAMBA_3_0/source/smbd/connection.c
   branches/SAMBA_3_0/source/smbd/trans2.c
   branches/SAMBA_3_0_25/source/include/smb.h
   branches/SAMBA_3_0_25/source/param/loadparm.c
   branches/SAMBA_3_0_25/source/smbd/connection.c
   branches/SAMBA_3_0_25/source/smbd/trans2.c


Changeset:
Modified: branches/SAMBA_3_0/source/include/smb.h
===================================================================
--- branches/SAMBA_3_0/source/include/smb.h     2007-04-16 12:44:13 UTC (rev 
22265)
+++ branches/SAMBA_3_0/source/include/smb.h     2007-04-16 19:10:16 UTC (rev 
22266)
@@ -878,7 +878,7 @@
        int cnum;
        uid_t uid;
        gid_t gid;
-       char name[24];
+       char servicename[FSTRING_LEN];
        char addr[24];
        char machine[FSTRING_LEN];
        time_t start;

Modified: branches/SAMBA_3_0/source/param/loadparm.c
===================================================================
--- branches/SAMBA_3_0/source/param/loadparm.c  2007-04-16 12:44:13 UTC (rev 
22265)
+++ branches/SAMBA_3_0/source/param/loadparm.c  2007-04-16 19:10:16 UTC (rev 
22266)
@@ -5299,15 +5299,22 @@
  A useful volume label function. 
 ********************************************************************/
 
-char *volume_label(int snum)
+const char *volume_label(int snum)
 {
-       char *ret = lp_volume(snum);
-       if (!*ret)
-               return lp_servicename(snum);
-       return (ret);
+       char *ret;
+       const char *label = lp_volume(snum);
+       if (!*label) {
+               label = lp_servicename(snum);
+       }
+               
+       /* This returns a 33 byte guarenteed null terminated string. */
+       ret = talloc_strndup(main_loop_talloc_get(), label, 32);
+       if (!ret) {
+               return "";
+       }               
+       return ret;
 }
 
-
 /*******************************************************************
  Set the server type we will announce as via nmbd.
 ********************************************************************/

Modified: branches/SAMBA_3_0/source/smbd/connection.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/connection.c 2007-04-16 12:44:13 UTC (rev 
22265)
+++ branches/SAMBA_3_0/source/smbd/connection.c 2007-04-16 19:10:16 UTC (rev 
22266)
@@ -108,13 +108,13 @@
 
        if (cs->Clear && !process_exists(crec.pid) && (errno == ESRCH)) {
                DEBUG(2,("pid %s doesn't exist - deleting connections %d 
[%s]\n",
-                       procid_str_static(&crec.pid), crec.cnum, crec.name));
+                       procid_str_static(&crec.pid), crec.cnum, 
crec.servicename));
                if (tdb_delete(the_tdb, kbuf) != 0)
                        DEBUG(0,("count_fn: tdb_delete failed with error %s\n", 
tdb_errorstr(tdb) ));
                return 0;
        }
 
-       if (strequal(crec.name, cs->name))
+       if (strequal(crec.servicename, cs->name))
                cs->curr_connections++;
 
        return 0;
@@ -191,8 +191,8 @@
        if (conn) {
                crec.uid = conn->uid;
                crec.gid = conn->gid;
-               safe_strcpy(crec.name,
-                           lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
+               safe_strcpy(crec.servicename,
+                           
lp_servicename(SNUM(conn)),sizeof(crec.servicename)-1);
        }
        crec.start = time(NULL);
        crec.bcast_msg_flags = msg_flags;

Modified: branches/SAMBA_3_0/source/smbd/trans2.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/trans2.c     2007-04-16 12:44:13 UTC (rev 
22265)
+++ branches/SAMBA_3_0/source/smbd/trans2.c     2007-04-16 19:10:16 UTC (rev 
22266)
@@ -2247,7 +2247,7 @@
        uint16 info_level;
        int data_len, len;
        SMB_STRUCT_STAT st;
-       char *vname = volume_label(SNUM(conn));
+       const char *vname = volume_label(SNUM(conn));
        int snum = SNUM(conn);
        char *fstype = lp_fstype(SNUM(conn));
        int quota_flag = 0;
@@ -2368,9 +2368,11 @@
                        SIVAL(pdata,8,str_checksum(lp_servicename(snum)) ^ 
                                (str_checksum(get_local_machine_name())<<16));
 
+                       /* Max label len is 32 characters. */
                        len = srvstr_push(outbuf, pdata+18, vname, -1, 
STR_UNICODE);
                        SIVAL(pdata,12,len);
                        data_len = 18+len;
+
                        DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_VOLUME_INFO 
namelen = %d, vol=%s serv=%s\n", 
                                (int)strlen(vname),vname, 
lp_servicename(snum)));
                        break;

Modified: branches/SAMBA_3_0_25/source/include/smb.h
===================================================================
--- branches/SAMBA_3_0_25/source/include/smb.h  2007-04-16 12:44:13 UTC (rev 
22265)
+++ branches/SAMBA_3_0_25/source/include/smb.h  2007-04-16 19:10:16 UTC (rev 
22266)
@@ -885,7 +885,7 @@
        int cnum;
        uid_t uid;
        gid_t gid;
-       char name[24];
+       char servicename[FSTRING_LEN];
        char addr[24];
        char machine[FSTRING_LEN];
        time_t start;

Modified: branches/SAMBA_3_0_25/source/param/loadparm.c
===================================================================
--- branches/SAMBA_3_0_25/source/param/loadparm.c       2007-04-16 12:44:13 UTC 
(rev 22265)
+++ branches/SAMBA_3_0_25/source/param/loadparm.c       2007-04-16 19:10:16 UTC 
(rev 22266)
@@ -5293,15 +5293,22 @@
  A useful volume label function. 
 ********************************************************************/
 
-char *volume_label(int snum)
+const char *volume_label(int snum)
 {
-       char *ret = lp_volume(snum);
-       if (!*ret)
-               return lp_servicename(snum);
-       return (ret);
+       char *ret;
+       const char *label = lp_volume(snum);
+       if (!*label) {
+               label = lp_servicename(snum);
+       }
+               
+       /* This returns a 33 byte guarenteed null terminated string. */
+       ret = talloc_strndup(main_loop_talloc_get(), label, 32);
+       if (!ret) {
+               return "";
+       }               
+       return ret;
 }
 
-
 /*******************************************************************
  Set the server type we will announce as via nmbd.
 ********************************************************************/

Modified: branches/SAMBA_3_0_25/source/smbd/connection.c
===================================================================
--- branches/SAMBA_3_0_25/source/smbd/connection.c      2007-04-16 12:44:13 UTC 
(rev 22265)
+++ branches/SAMBA_3_0_25/source/smbd/connection.c      2007-04-16 19:10:16 UTC 
(rev 22266)
@@ -108,13 +108,13 @@
 
        if (cs->Clear && !process_exists(crec.pid) && (errno == ESRCH)) {
                DEBUG(2,("pid %s doesn't exist - deleting connections %d 
[%s]\n",
-                       procid_str_static(&crec.pid), crec.cnum, crec.name));
+                       procid_str_static(&crec.pid), crec.cnum, 
crec.servicename));
                if (tdb_delete(the_tdb, kbuf) != 0)
                        DEBUG(0,("count_fn: tdb_delete failed with error %s\n", 
tdb_errorstr(tdb) ));
                return 0;
        }
 
-       if (strequal(crec.name, cs->name))
+       if (strequal(crec.servicename, cs->name))
                cs->curr_connections++;
 
        return 0;
@@ -191,8 +191,8 @@
        if (conn) {
                crec.uid = conn->uid;
                crec.gid = conn->gid;
-               safe_strcpy(crec.name,
-                           lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
+               safe_strcpy(crec.servicename,
+                           
lp_servicename(SNUM(conn)),sizeof(crec.servicename)-1);
        }
        crec.start = time(NULL);
        crec.bcast_msg_flags = msg_flags;

Modified: branches/SAMBA_3_0_25/source/smbd/trans2.c
===================================================================
--- branches/SAMBA_3_0_25/source/smbd/trans2.c  2007-04-16 12:44:13 UTC (rev 
22265)
+++ branches/SAMBA_3_0_25/source/smbd/trans2.c  2007-04-16 19:10:16 UTC (rev 
22266)
@@ -2232,7 +2232,7 @@
        uint16 info_level;
        int data_len, len;
        SMB_STRUCT_STAT st;
-       char *vname = volume_label(SNUM(conn));
+       const char *vname = volume_label(SNUM(conn));
        int snum = SNUM(conn);
        char *fstype = lp_fstype(SNUM(conn));
        int quota_flag = 0;
@@ -2353,9 +2353,11 @@
                        SIVAL(pdata,8,str_checksum(lp_servicename(snum)) ^ 
                                (str_checksum(get_local_machine_name())<<16));
 
+                       /* Max label len is 32 characters. */
                        len = srvstr_push(outbuf, pdata+18, vname, -1, 
STR_UNICODE);
                        SIVAL(pdata,12,len);
                        data_len = 18+len;
+
                        DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_VOLUME_INFO 
namelen = %d, vol=%s serv=%s\n", 
                                (int)strlen(vname),vname, 
lp_servicename(snum)));
                        break;

Reply via email to