From 44cd7009fb10f192e798b6e5485756ede042d096 Mon Sep 17 00:00:00 2001 From: midipix Date: Jun 26 2020 20:48:26 +0000 Subject: helper api: added toks_uuid_from_path(). --- diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index 1621214..a3d0806 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -189,6 +189,7 @@ toks_api int toks_output_error_record (const struct toks_driver_ctx *, const s toks_api int toks_output_error_vector (const struct toks_driver_ctx *); /* helper api */ +toks_api int toks_uuid_from_path (const char *, struct _nt_guid *); toks_api int toks_string_to_guid (const char (*)[40], struct _nt_guid *); toks_api void toks_guid_to_string (const struct _nt_guid *, char (*)[40]); diff --git a/project/common.mk b/project/common.mk index 5f8b868..3b96261 100644 --- a/project/common.mk +++ b/project/common.mk @@ -19,6 +19,7 @@ INTERNAL_SRCS = \ src/driver/toks_amain.c \ src/driver/toks_driver_ctx.c \ src/helper/toks_guid_string.c \ + src/helper/toks_uuid_from_path.c \ src/internal/nolibc/toksvc_compiler.c \ src/internal/toksvc_dprintf_impl.c \ src/internal/toksvc_log_impl.c \ diff --git a/src/helper/toks_uuid_from_path.c b/src/helper/toks_uuid_from_path.c new file mode 100644 index 0000000..34fc83a --- /dev/null +++ b/src/helper/toks_uuid_from_path.c @@ -0,0 +1,89 @@ +/*********************************************************/ +/* toksvc: a framework-native token broker service */ +/* Copyright (C) 2020 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.TOKSVC. */ +/*********************************************************/ + +#include +#include +#include +#include +#include + +#include +#include "toksvc_init_impl.h" +#include "toksvc_driver_impl.h" +#include "toksvc_nolibc_impl.h" + +static int32_t toks_uuid_path_open(void ** hfile, const char * path) +{ + return toks_open_dir(hfile,0,path,true) + ? toks_open_file(hfile,0,path,true) + : NT_STATUS_SUCCESS; +} + +int toks_uuid_from_path(const char * path, struct _nt_guid * uuid) +{ + int32_t status; + void * hfile; + void * hevent; + nt_iosb iosb; + nt_file_object_id_buffer objid; + + toks_init(); + + if ((status = toks_uuid_path_open(&hfile,path))) + return status; + + status = ntapi->tt_create_private_event( + &hevent, + NT_NOTIFICATION_EVENT, + NT_EVENT_NOT_SIGNALED); + + if (status) { + ntapi->zw_close(hfile); + return status; + } + + iosb.status = NT_STATUS_PENDING; + + status = ntapi->zw_fs_control_file( + hfile, + hevent,0,0, + &iosb, + NT_FSCTL_CREATE_OR_GET_OBJECT_ID, + 0,0,&objid,sizeof(objid)); + + if (status == NT_STATUS_PENDING) + ntapi->zw_wait_for_single_object( + hevent, + NT_SYNC_NON_ALERTABLE, + 0); + + ntapi->zw_close(hfile); + ntapi->zw_close(hevent); + + if (iosb.status == NT_STATUS_SUCCESS) { + uuid->data1 = (objid.obj_id[0]); + uuid->data1 |= (objid.obj_id[1] << 8); + uuid->data1 |= (objid.obj_id[2] << 16); + uuid->data1 |= (objid.obj_id[3] << 24); + + uuid->data2 = (objid.obj_id[4]); + uuid->data2 |= (objid.obj_id[5] << 8); + + uuid->data3 = (objid.obj_id[6]); + uuid->data3 |= (objid.obj_id[7] << 8); + + uuid->data4[0] = (objid.obj_id[8]); + uuid->data4[1] = (objid.obj_id[9]); + uuid->data4[2] = (objid.obj_id[10]); + uuid->data4[3] = (objid.obj_id[11]); + uuid->data4[4] = (objid.obj_id[12]); + uuid->data4[5] = (objid.obj_id[13]); + uuid->data4[6] = (objid.obj_id[14]); + uuid->data4[7] = (objid.obj_id[15]); + } + + return iosb.status; +}