diff mbox series

smbinfo: add fsctl-getobjid support

Message ID 20190315062215.29499-2-lsahlber@redhat.com (mailing list archive)
State New, archived
Headers show
Series smbinfo: add fsctl-getobjid support | expand

Commit Message

Ronnie Sahlberg March 15, 2019, 6:22 a.m. UTC
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(+)

Comments

Pavel Shilovsky March 16, 2019, 7:46 p.m. UTC | #1
чт, 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
diff mbox series

Patch

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