diff --git a/include/toksvc/toksvc.h b/include/toksvc/toksvc.h index 2a41b33..1621214 100644 --- a/include/toksvc/toksvc.h +++ b/include/toksvc/toksvc.h @@ -50,6 +50,7 @@ extern "C" { #define TOKS_DRIVER_MODE_SERVER 0X10000 #define TOKS_DRIVER_MODE_CLIENT 0X20000 +#define TOKS_DRIVER_ROOT_UUID 0x40000 #define TOKS_DRIVER_ACTION_ACQUIRE 0X100000 #define TOKS_DRIVER_ACTION_RELEASE 0X200000 diff --git a/src/driver/toks_driver_ctx.c b/src/driver/toks_driver_ctx.c index b885453..8853e17 100644 --- a/src/driver/toks_driver_ctx.c +++ b/src/driver/toks_driver_ctx.c @@ -6,6 +6,7 @@ #include #include +#include #include @@ -266,6 +267,58 @@ static int toks_split_argv( return 0; } +static int32_t toks_set_uuid_from_root( + struct toks_driver_ctx_impl * ctx, + struct _nt_guid * svcguid) +{ + int32_t status; + nt_iosb iosb; + nt_file_object_id_buffer objid; + + if (!ctx->rtdata->hroot) + return NT_STATUS_INVALID_PARAMETER; + + iosb.status = NT_STATUS_PENDING; + + status = ntapi->zw_fs_control_file( + ctx->rtdata->hroot, + ctx->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( + ctx->hevent, + NT_SYNC_NON_ALERTABLE, + 0); + + if (iosb.status) + return iosb.status; + + svcguid->data1 = (objid.obj_id[0]); + svcguid->data1 |= (objid.obj_id[1] << 8); + svcguid->data1 |= (objid.obj_id[2] << 16); + svcguid->data1 |= (objid.obj_id[3] << 24); + + svcguid->data2 = (objid.obj_id[4]); + svcguid->data2 |= (objid.obj_id[5] << 8); + + svcguid->data3 = (objid.obj_id[6]); + svcguid->data3 |= (objid.obj_id[7] << 8); + + svcguid->data4[0] = (objid.obj_id[8]); + svcguid->data4[1] = (objid.obj_id[9]); + svcguid->data4[2] = (objid.obj_id[10]); + svcguid->data4[3] = (objid.obj_id[11]); + svcguid->data4[4] = (objid.obj_id[12]); + svcguid->data4[5] = (objid.obj_id[13]); + svcguid->data4[6] = (objid.obj_id[14]); + svcguid->data4[7] = (objid.obj_id[15]); + + return NT_STATUS_SUCCESS; +} + int toks_get_driver_ctx( char ** argv, char ** envp, @@ -373,6 +426,10 @@ int toks_get_driver_ctx( uuid = entry; break; + case TAG_ROOTUUID: + cctx.drvflags |= TOKS_DRIVER_ROOT_UUID; + break; + case TAG_REFSTR: refstr = entry->arg; break; @@ -580,9 +637,6 @@ int toks_get_driver_ctx( } } - ntapi->tt_guid_copy( - &ctx->uuid, - uuid ? &svcguid : &ctx->rtdata->srv_guid); if ((toks_ntapi->tt_create_private_event( &ctx->hevent, @@ -590,6 +644,32 @@ int toks_get_driver_ctx( NT_EVENT_NOT_SIGNALED))) return toks_get_driver_ctx_fail(meta); + + if (uuid) { + ntapi->tt_guid_copy( + &ctx->uuid, + &svcguid); + + } else if (cctx.drvflags & TOKS_DRIVER_ROOT_UUID) { + if ((status = toks_set_uuid_from_root(ctx,&svcguid))) { + if (flags & TOKS_DRIVER_VERBOSITY_ERRORS) + toks_dprintf(STDERR_FILENO, + "%s: error: could not set the uuid " + "based on the sysroot directory [0x%08x].", + program,status); + return toks_get_driver_ctx_fail(meta); + } + + ntapi->tt_guid_copy( + &ctx->uuid, + &svcguid); + } else { + ntapi->tt_guid_copy( + &ctx->uuid, + &ctx->rtdata->srv_guid); + } + + if ((ntapi->tt_open_dev_object_directory( &ctx->hsvcdir, NT_SEC_READ_CONTROL diff --git a/src/internal/toksvc_driver_impl.h b/src/internal/toksvc_driver_impl.h index 6e5cc11..ad88393 100644 --- a/src/internal/toksvc_driver_impl.h +++ b/src/internal/toksvc_driver_impl.h @@ -30,6 +30,7 @@ enum app_tags { TAG_DAEMON, TAG_SYSROOT, TAG_UUID, + TAG_ROOTUUID, TAG_CONNECT, TAG_TOKENS, TAG_ABORT, diff --git a/src/skin/toks_skin_default.c b/src/skin/toks_skin_default.c index 74f49fe..a371160 100644 --- a/src/skin/toks_skin_default.c +++ b/src/skin/toks_skin_default.c @@ -23,6 +23,10 @@ const struct argv_option toks_default_options[] = { "set the service identifier to %s, which needs " "to be in the format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}."}, + {"root-uuid", 'U',TAG_ROOTUUID,ARGV_OPTARG_NONE,0,0,0, + "set the service identifier to a uuid based on " + "unique properties of the sysroot directory"}, + {"refstr", 'f',TAG_REFSTR,ARGV_OPTARG_REQUIRED,0,0,"", "include the reference string %s in log records" "that pertain to this client."},