All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] Add an example on how to fetch FSCTL data
@ 2019-03-15  6:22 Ronnie Sahlberg
  2019-03-15  6:22 ` [PATCH] smbinfo: add fsctl-getobjid support Ronnie Sahlberg
  0 siblings, 1 reply; 3+ messages in thread
From: Ronnie Sahlberg @ 2019-03-15  6:22 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French, Pavel Shilovsky

Pavel,

Here is a small patch to smbinfo to fetch a FSCTL blob from the server.
There are very very many types of data that might be useful to
surface to the user and this is the first example on using the passthrough
API to fetch an FSCTL blob.

This requires the patch to cifs.ko to add fsctl support that are not in
upstream yet.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] smbinfo: add fsctl-getobjid support
  2019-03-15  6:22 [PATCH 0/1] Add an example on how to fetch FSCTL data Ronnie Sahlberg
@ 2019-03-15  6:22 ` Ronnie Sahlberg
  2019-03-16 19:46   ` Pavel Shilovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Ronnie Sahlberg @ 2019-03-15  6:22 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French, Pavel Shilovsky, Ronnie Sahlberg

This will print the ObjectID buffer for the object.
This is an example on how to fetch FSCTL data for an object using
the passthrough API.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 smbinfo.c   | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 smbinfo.rst |  2 ++
 2 files changed, 75 insertions(+)

diff --git a/smbinfo.c b/smbinfo.c
index 6b63f9d..215842c 100644
--- a/smbinfo.c
+++ b/smbinfo.c
@@ -39,6 +39,11 @@
 #include <inttypes.h>
 
 #define CIFS_IOCTL_MAGIC 0xCF
+
+/* query_info flags */
+#define PASSTHRU_QUERY_INFO     0x00000000
+#define PASSTHRU_FSCTL          0x00000001
+
 struct smb_query_info {
         uint32_t   info_type;
         uint32_t   file_info_class;
@@ -170,6 +175,72 @@ print_bits(uint32_t mask, struct bit_string *bs)
 }
 
 static void
+print_guid(uint8_t *sd)
+{
+	uint32_t u32;
+	uint16_t u16;
+	int i;
+
+	memcpy(&u32, &sd[0], 4);
+	printf("%08x-", le32toh(u32));
+
+	memcpy(&u16, &sd[4], 2);
+	printf("%04x-", le16toh(u16));
+
+	memcpy(&u16, &sd[6], 2);
+	printf("%04x-", le16toh(u16));
+
+	printf("%02x%02x-", sd[8], sd[9]);
+	for (i = 0; i < 6; i++)
+		printf("%02x", sd[10 + i]);
+}
+
+static void
+print_objidbuf(uint8_t *sd)
+{
+	printf("Object-ID: ");
+	print_guid(&sd[0]);
+	printf("\n");
+
+	printf("Birth-Volume-ID: ");
+	print_guid(&sd[16]);
+	printf("\n");
+
+	printf("Birth-Object-ID: ");
+	print_guid(&sd[32]);
+	printf("\n");
+
+	printf("Domain-ID: ");
+	print_guid(&sd[48]);
+	printf("\n");
+}
+
+static void
+fsctlgetobjid(int f)
+{
+	struct smb_query_info *qi;
+	struct stat st;
+
+	fstat(f, &st);
+
+	qi = malloc(sizeof(struct smb_query_info) + 64);
+	memset(qi, 0, sizeof(qi) + 64);
+	qi->info_type = 0x9009c;
+	qi->file_info_class = 0;
+	qi->additional_information = 0;
+	qi->input_buffer_length = 64;
+	qi->flags = PASSTHRU_FSCTL;
+
+	if (ioctl(f, CIFS_QUERY_INFO, qi) < 0) {
+		fprintf(stderr, "ioctl failed with %s\n", strerror(errno));
+		exit(1);
+	}
+	print_objidbuf((uint8_t *)(&qi[1]));
+
+	free(qi);
+}
+
+static void
 print_fileaccessinfo(uint8_t *sd, int type)
 {
         uint32_t access_flags;
@@ -951,6 +1022,8 @@ int main(int argc, char *argv[])
                 secdesc(f);
         else if (!strcmp(argv[optind], "quota"))
                 quota(f);
+        else if (!strcmp(argv[1], "fsctl-getobjid"))
+                fsctlgetobjid(f);
         else {
                 fprintf(stderr, "Unknown command %s\n", argv[optind]);
                 exit(1);
diff --git a/smbinfo.rst b/smbinfo.rst
index 9bfd313..fd7f0ff 100644
--- a/smbinfo.rst
+++ b/smbinfo.rst
@@ -62,6 +62,8 @@ COMMAND
 
 `filestandardinfo`: Prints the FileStandardInformation class
 
+`fsctl-getobjid`: Prints the ObjectID
+
 `quota`: Print the quota for the volume in the form
 - SID Length
 - Change Time
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] smbinfo: add fsctl-getobjid support
  2019-03-15  6:22 ` [PATCH] smbinfo: add fsctl-getobjid support Ronnie Sahlberg
@ 2019-03-16 19:46   ` Pavel Shilovsky
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Shilovsky @ 2019-03-16 19:46 UTC (permalink / raw)
  To: Ronnie Sahlberg; +Cc: linux-cifs, Steve French, Pavel Shilovsky

чт, 14 мар. 2019 г. в 23:22, Ronnie Sahlberg <lsahlber@redhat.com>:
>
> This will print the ObjectID buffer for the object.
> This is an example on how to fetch FSCTL data for an object using
> the passthrough API.
>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  smbinfo.c   | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  smbinfo.rst |  2 ++
>  2 files changed, 75 insertions(+)
>
> diff --git a/smbinfo.c b/smbinfo.c
> index 6b63f9d..215842c 100644
> --- a/smbinfo.c
> +++ b/smbinfo.c
> @@ -39,6 +39,11 @@
>  #include <inttypes.h>
>
>  #define CIFS_IOCTL_MAGIC 0xCF
> +
> +/* query_info flags */
> +#define PASSTHRU_QUERY_INFO     0x00000000
> +#define PASSTHRU_FSCTL          0x00000001
> +
>  struct smb_query_info {
>          uint32_t   info_type;
>          uint32_t   file_info_class;
> @@ -170,6 +175,72 @@ print_bits(uint32_t mask, struct bit_string *bs)
>  }
>
>  static void
> +print_guid(uint8_t *sd)
> +{
> +       uint32_t u32;
> +       uint16_t u16;
> +       int i;
> +
> +       memcpy(&u32, &sd[0], 4);
> +       printf("%08x-", le32toh(u32));
> +
> +       memcpy(&u16, &sd[4], 2);
> +       printf("%04x-", le16toh(u16));
> +
> +       memcpy(&u16, &sd[6], 2);
> +       printf("%04x-", le16toh(u16));
> +
> +       printf("%02x%02x-", sd[8], sd[9]);
> +       for (i = 0; i < 6; i++)
> +               printf("%02x", sd[10 + i]);
> +}
> +
> +static void
> +print_objidbuf(uint8_t *sd)
> +{
> +       printf("Object-ID: ");
> +       print_guid(&sd[0]);
> +       printf("\n");
> +
> +       printf("Birth-Volume-ID: ");
> +       print_guid(&sd[16]);
> +       printf("\n");
> +
> +       printf("Birth-Object-ID: ");
> +       print_guid(&sd[32]);
> +       printf("\n");
> +
> +       printf("Domain-ID: ");
> +       print_guid(&sd[48]);
> +       printf("\n");
> +}
> +
> +static void
> +fsctlgetobjid(int f)
> +{
> +       struct smb_query_info *qi;
> +       struct stat st;
> +
> +       fstat(f, &st);
> +
> +       qi = malloc(sizeof(struct smb_query_info) + 64);
> +       memset(qi, 0, sizeof(qi) + 64);
> +       qi->info_type = 0x9009c;
> +       qi->file_info_class = 0;
> +       qi->additional_information = 0;
> +       qi->input_buffer_length = 64;
> +       qi->flags = PASSTHRU_FSCTL;
> +
> +       if (ioctl(f, CIFS_QUERY_INFO, qi) < 0) {
> +               fprintf(stderr, "ioctl failed with %s\n", strerror(errno));
> +               exit(1);
> +       }
> +       print_objidbuf((uint8_t *)(&qi[1]));
> +
> +       free(qi);
> +}
> +
> +static void
>  print_fileaccessinfo(uint8_t *sd, int type)
>  {
>          uint32_t access_flags;
> @@ -951,6 +1022,8 @@ int main(int argc, char *argv[])
>                  secdesc(f);
>          else if (!strcmp(argv[optind], "quota"))
>                  quota(f);
> +        else if (!strcmp(argv[1], "fsctl-getobjid"))
> +                fsctlgetobjid(f);
>          else {
>                  fprintf(stderr, "Unknown command %s\n", argv[optind]);
>                  exit(1);
> diff --git a/smbinfo.rst b/smbinfo.rst
> index 9bfd313..fd7f0ff 100644
> --- a/smbinfo.rst
> +++ b/smbinfo.rst
> @@ -62,6 +62,8 @@ COMMAND
>
>  `filestandardinfo`: Prints the FileStandardInformation class
>
> +`fsctl-getobjid`: Prints the ObjectID
> +
>  `quota`: Print the quota for the volume in the form
>  - SID Length
>  - Change Time
> --
> 2.13.6
>

Fixed spaces to tabs and applied. Thanks.

--
Best regards,
Pavel Shilovsky

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-16 19:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-15  6:22 [PATCH 0/1] Add an example on how to fetch FSCTL data Ronnie Sahlberg
2019-03-15  6:22 ` [PATCH] smbinfo: add fsctl-getobjid support Ronnie Sahlberg
2019-03-16 19:46   ` Pavel Shilovsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.