diff options
Diffstat (limited to 'src/port')
-rw-r--r-- | src/port/ntapi_port_name_helper.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/src/port/ntapi_port_name_helper.c b/src/port/ntapi_port_name_helper.c index e55ffba..ae36c86 100644 --- a/src/port/ntapi_port_name_helper.c +++ b/src/port/ntapi_port_name_helper.c @@ -167,3 +167,147 @@ void __stdcall __ntapi_tt_port_name_from_attributes( return; } + + +static int32_t __tt_port_attr_from_name( + __out nt_port_attr * attr, + __in const nt_port_name * name) +{ + int i; + int type; + int32_t status; + const wchar16_t bno[] = __NT_BASED_NAMED_OBJECTS; + + /* base named objects */ + if (__ntapi->tt_strncmp_utf16( + name->base_named_objects, + bno,sizeof(bno))) + return NT_STATUS_INVALID_PARAMETER; + + /* service prefix */ + for (i=0, type=-1; i<NT_PORT_TYPE_CAP && type<0; i++) + if (!(__ntapi->tt_strncmp_utf16( + name->svc_prefix, + __port_service_prefixes[i][0], + sizeof(__port_service_prefix)))) + type = i; + + if (type < 0) + return NT_STATUS_INVALID_PARAMETER; + + /* port guid */ + if ((status = __ntapi->tt_string_to_guid_utf16( + (nt_guid_str_utf16 *)&name->port_guid, + &attr->guid))) + return status; + + /* port keys */ + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_1st, + &attr->keys.key[0]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_2nd, + &attr->keys.key[1]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_3rd, + &attr->keys.key[2]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_4th, + &attr->keys.key[3]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_5th, + &attr->keys.key[4]))) + return status; + + if ((status = __ntapi->tt_hex_utf16_to_uint32( + name->port_name_keys.key_6th, + &attr->keys.key[5]))) + return status; + + /* backslash and underscores */ + if (name->backslash != '\\') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_1st != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_2nd != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_3rd != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_4th != '_') + return NT_STATUS_INVALID_PARAMETER; + + if (name->port_name_keys.uscore_5th != '_') + return NT_STATUS_INVALID_PARAMETER; + + /* unknown defaults */ + attr->ver_major = 0; + attr->ver_minor = 0; + attr->options = 0; + attr->flags = 0; + + /* all done */ + return NT_STATUS_SUCCESS; +} + + +int32_t __stdcall __ntapi_tt_port_attr_from_name( + __out nt_port_attr * attr, + __in const nt_port_name * name) +{ + /* null termination */ + if (name->null_termination) + return NT_STATUS_INVALID_PARAMETER; + + return __tt_port_attr_from_name( + attr,name); +} + + +int32_t __stdcall __ntapi_tt_port_attr_from_string( + __out nt_port_attr * attr, + __in const nt_unicode_string * str) +{ + if (str->strlen != ((size_t)&(((nt_port_name *)0)->null_termination))) + return NT_STATUS_INVALID_PARAMETER; + + return __tt_port_attr_from_name( + attr,(const nt_port_name *)str->buffer); +} + + +int32_t __stdcall __ntapi_tt_port_attr_from_symlink( + __out nt_port_attr * attr, + __in void * symlink) +{ + int32_t status; + size_t size; + nt_unicode_string * target; + uintptr_t buffer[512/sizeof(uintptr_t)]; + + target = (nt_unicode_string *)buffer; + target->strlen = 0; + target->maxlen = sizeof(buffer) - sizeof(nt_unicode_string); + target->buffer = (wchar16_t *)&target[1]; + + if ((status = __ntapi->zw_query_symbolic_link_object( + symlink,target,&size))) + return status; + + if (target->strlen != ((size_t)&(((nt_port_name *)0)->null_termination))) + return NT_STATUS_INVALID_PARAMETER; + + return __tt_port_attr_from_name( + attr,(const nt_port_name *)target->buffer); +} |