Get Samba version or capability information from Windows
Corinna Vinschen
corinna at vinschen.de
Mon Jan 28 10:44:45 GMT 2008
Ping?
Corinna
On Jan 24 12:47, Corinna Vinschen wrote:
> On Jan 24 10:04, Volker Lendecke wrote:
> > On Wed, Jan 23, 2008 at 05:46:00PM +0100, Corinna Vinschen wrote:
> > > Would a similar patch also be ok for the 3.0 branch?
> >
> > I'd be fine with it.
>
> Cool.
>
> While testing I found that the commited patch has a flaw. In the
> original version I relied on the fact that the local static variable
> "extended_info" in samba_extended_info_version() is initialized to 0.
> That's an obviously incorrect assumption if the extended_info struct is
> given as an argument pointer. So, the first patch attached fixes the
> chance that samba_subversion and samba_gitcommitdate might be
> uninitialized in the 3-2-test branch and removes a left over comment.
>
> The second patch backports the ExtendedInfo reply to a
> SMB_FS_OBJECTID_INFORMATION query from the 3-2-test branch to the
> 3-0-test branch, including the fix from the first patch.
>
> The object id itself gets not set and the 3.0 branch will
> consequentially not set the FILE_SUPPORTS_OBJECT_IDS flag in a
> SMB_FS_ATTRIBUTE_INFORMATION reply. I tested to add that stuff
> to 3.0 and it's no problem. If you prefer that, I'll create a new
> patch which also adds the object id.
>
>
> Thanks,
> Corinna
> diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c
> index 7896e71..d0acd95 100644
> --- a/source/smbd/trans2.c
> +++ b/source/smbd/trans2.c
> @@ -2484,6 +2484,7 @@ static void samba_extended_info_version(struct smb_extended_info *extended_info)
> #ifdef SAMBA_VERSION_REVISION
> extended_info->samba_version |= (tolower(*SAMBA_VERSION_REVISION) - 'a' + 1) & 0xff;
> #endif
> + extended_info->samba_subversion = 0;
> #ifdef SAMBA_VERSION_RC_RELEASE
> extended_info->samba_subversion |= (SAMBA_VERSION_RC_RELEASE & 0xff) << 24;
> #else
> @@ -2494,7 +2495,7 @@ static void samba_extended_info_version(struct smb_extended_info *extended_info)
> #ifdef SAMBA_VERSION_VENDOR_PATCH
> extended_info->samba_subversion |= (SAMBA_VERSION_VENDOR_PATCH & 0xffff);
> #endif
> - /* FIXME: samba_gitcommitdate should contain the git commit date. */
> + extended_info->samba_gitcommitdate = 0;
> #ifdef SAMBA_VERSION_GIT_COMMIT_TIME
> unix_to_nt_time(&extended_info->samba_gitcommitdate, SAMBA_VERSION_GIT_COMMIT_TIME);
> #endif
> diff --git a/source/include/smb.h b/source/include/smb.h
> index 5ce8406..46afcde 100644
> --- a/source/include/smb.h
> +++ b/source/include/smb.h
> @@ -1934,4 +1934,15 @@ enum usershare_err {
> /* Different reasons for closing a file. */
> enum file_close_type {NORMAL_CLOSE=0,SHUTDOWN_CLOSE,ERROR_CLOSE};
>
> +/* Used in SMB_FS_OBJECTID_INFORMATION requests. Must be exactly 48 bytes. */
> +#define SAMBA_EXTENDED_INFO_MAGIC 0x536d4261 /* "SmBa" */
> +#define SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH 28
> +struct smb_extended_info {
> + uint32 samba_magic; /* Always SAMBA_EXTRA_INFO_MAGIC */
> + uint32 samba_version; /* Major/Minor/Release/Revision */
> + uint32 samba_subversion; /* Prerelease/RC/Vendor patch */
> + NTTIME samba_gitcommitdate;
> + char samba_version_string[SAMBA_EXTENDED_INFO_VERSION_STRING_LENGTH];
> +};
> +
> #endif /* _SMB_H */
> diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c
> index 3e1ba8a..623117b 100644
> --- a/source/smbd/trans2.c
> +++ b/source/smbd/trans2.c
> @@ -2223,6 +2223,41 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
> return(-1);
> }
>
> +static void samba_extended_info_version(struct smb_extended_info *extended_info)
> +{
> + SMB_ASSERT(extended_info != NULL);
> +
> + extended_info->samba_magic = SAMBA_EXTENDED_INFO_MAGIC;
> + extended_info->samba_version = ((SAMBA_VERSION_MAJOR & 0xff) << 24)
> + | ((SAMBA_VERSION_MINOR & 0xff) << 16)
> + | ((SAMBA_VERSION_RELEASE & 0xff) << 8);
> +#ifdef SAMBA_VERSION_REVISION
> + extended_info->samba_version |= (tolower(*SAMBA_VERSION_REVISION) - 'a' + 1) & 0xff;
> +#endif
> + extended_info->samba_subversion = 0;
> +#ifdef SAMBA_VERSION_RC_RELEASE
> + extended_info->samba_subversion |= (SAMBA_VERSION_RC_RELEASE & 0xff) << 24;
> +#else
> +#ifdef SAMBA_VERSION_PRE_RELEASE
> + extended_info->samba_subversion |= (SAMBA_VERSION_PRE_RELEASE & 0xff) << 16;
> +#endif
> +#endif
> +#ifdef SAMBA_VERSION_VENDOR_PATCH
> + extended_info->samba_subversion |= (SAMBA_VERSION_VENDOR_PATCH & 0xffff);
> +#endif
> + extended_info->samba_subversion = 0;
> +#ifdef SAMBA_VERSION_GIT_COMMIT_TIME
> + unix_to_nt_time(&extended_info->samba_gitcommitdate, SAMBA_VERSION_GIT_COMMIT_TIME);
> +#endif
> +
> + memset(extended_info->samba_version_string, 0,
> + sizeof(extended_info->samba_version_string));
> +
> + snprintf (extended_info->samba_version_string,
> + sizeof(extended_info->samba_version_string),
> + "%s", samba_version_string());
> +}
> +
> /****************************************************************************
> Reply to a TRANS2_QFSINFO (query filesystem info).
> ****************************************************************************/
> @@ -2511,8 +2546,20 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, (unsigned
> }
> #endif /* HAVE_SYS_QUOTAS */
> case SMB_FS_OBJECTID_INFORMATION:
> + {
> + /*
> + * No object id, but we transmit version information.
> + */
> + struct smb_extended_info extended_info;
> + samba_extended_info_version (&extended_info);
> + SIVAL(pdata,16,extended_info.samba_magic);
> + SIVAL(pdata,20,extended_info.samba_version);
> + SIVAL(pdata,24,extended_info.samba_subversion);
> + SBIG_UINT(pdata,28,extended_info.samba_gitcommitdate);
> + memcpy(pdata+36,extended_info.samba_version_string,28);
> data_len = 64;
> break;
> + }
>
> /*
> * Query the version and capabilities of the CIFS UNIX extensions
More information about the samba-technical
mailing list