Blame src/helper/toks_uuid_from_path.c

44cd70
/*********************************************************/
44cd70
/*  toksvc: a framework-native token broker service      */
d91fa0
/*  Copyright (C) 2020  SysDeer Technologies, LLC        */
44cd70
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
44cd70
/*********************************************************/
44cd70
44cd70
#include <psxtypes/psxtypes.h>
44cd70
#include <ntapi/nt_object.h>
44cd70
#include <ntapi/nt_fsctl.h>
44cd70
#include <ntapi/nt_guid.h>
44cd70
#include <ntapi/ntapi.h>
44cd70
44cd70
#include <toksvc/toksvc.h>
44cd70
#include "toksvc_init_impl.h"
44cd70
#include "toksvc_driver_impl.h"
44cd70
#include "toksvc_nolibc_impl.h"
44cd70
44cd70
static int32_t toks_uuid_path_open(void ** hfile, const char * path)
44cd70
{
44cd70
	return toks_open_dir(hfile,0,path,true)
44cd70
		? toks_open_file(hfile,0,path,true)
44cd70
		: NT_STATUS_SUCCESS;
44cd70
}
44cd70
0021e3
int toks_uuid_from_path(const char * path, struct toks_uuid * uuid)
44cd70
{
44cd70
	int32_t                         status;
44cd70
	void *				hfile;
44cd70
	void *				hevent;
44cd70
	nt_iosb                         iosb;
44cd70
	nt_file_object_id_buffer        objid;
44cd70
44cd70
	toks_init();
44cd70
44cd70
	if ((status = toks_uuid_path_open(&hfile,path)))
44cd70
		return status;
44cd70
44cd70
	status = ntapi->tt_create_private_event(
44cd70
		&hevent,
44cd70
		NT_NOTIFICATION_EVENT,
44cd70
		NT_EVENT_NOT_SIGNALED);
44cd70
44cd70
	if (status) {
44cd70
		ntapi->zw_close(hfile);
44cd70
		return status;
44cd70
	}
44cd70
44cd70
	iosb.status = NT_STATUS_PENDING;
44cd70
44cd70
	status = ntapi->zw_fs_control_file(
44cd70
		hfile,
44cd70
		hevent,0,0,
44cd70
		&iosb,
44cd70
		NT_FSCTL_CREATE_OR_GET_OBJECT_ID,
44cd70
		0,0,&objid,sizeof(objid));
44cd70
44cd70
	if (status == NT_STATUS_PENDING)
44cd70
		ntapi->zw_wait_for_single_object(
44cd70
			hevent,
44cd70
			NT_SYNC_NON_ALERTABLE,
44cd70
			0);
44cd70
44cd70
	ntapi->zw_close(hfile);
44cd70
	ntapi->zw_close(hevent);
44cd70
44cd70
	if (iosb.status == NT_STATUS_SUCCESS) {
44cd70
		uuid->data1    = (objid.obj_id[0]);
44cd70
		uuid->data1   |= (objid.obj_id[1] << 8);
44cd70
		uuid->data1   |= (objid.obj_id[2] << 16);
44cd70
		uuid->data1   |= (objid.obj_id[3] << 24);
44cd70
44cd70
		uuid->data2    = (objid.obj_id[4]);
44cd70
		uuid->data2   |= (objid.obj_id[5] << 8);
44cd70
44cd70
		uuid->data3    = (objid.obj_id[6]);
44cd70
		uuid->data3   |= (objid.obj_id[7] << 8);
44cd70
44cd70
		uuid->data4[0] = (objid.obj_id[8]);
44cd70
		uuid->data4[1] = (objid.obj_id[9]);
44cd70
		uuid->data4[2] = (objid.obj_id[10]);
44cd70
		uuid->data4[3] = (objid.obj_id[11]);
44cd70
		uuid->data4[4] = (objid.obj_id[12]);
44cd70
		uuid->data4[5] = (objid.obj_id[13]);
44cd70
		uuid->data4[6] = (objid.obj_id[14]);
44cd70
		uuid->data4[7] = (objid.obj_id[15]);
44cd70
	}
44cd70
44cd70
	return iosb.status;
44cd70
}