server: Add a helper function for creating a Unicode string.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-03-24 12:47:44 +01:00
parent 7b41b7510f
commit faaea5cd00
4 changed files with 25 additions and 28 deletions

View File

@ -270,12 +270,12 @@ static void create_session( unsigned int id )
static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)}; static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)};
static const struct unicode_str link_session_str = {link_sessionW, sizeof(link_sessionW)}; static const struct unicode_str link_session_str = {link_sessionW, sizeof(link_sessionW)};
static const WCHAR fmt_u[] = {'%','u',0};
static struct directory *dir_bno_global, *dir_sessions, *dir_bnolinks; static struct directory *dir_bno_global, *dir_sessions, *dir_bnolinks;
struct directory *dir_id, *dir_bno, *dir_dosdevices, *dir_windows, *dir_winstation; struct directory *dir_id, *dir_bno, *dir_dosdevices, *dir_windows, *dir_winstation;
struct object *link_global, *link_local, *link_session, *link_bno, *link_windows; struct object *link_global, *link_local, *link_session, *link_bno, *link_windows;
struct unicode_str id_str; struct unicode_str id_str;
WCHAR id_strW[10]; char id_strA[10];
WCHAR *id_strW;
if (!id) if (!id)
{ {
@ -287,9 +287,8 @@ static void create_session( unsigned int id )
make_object_static( (struct object *)dir_sessions ); make_object_static( (struct object *)dir_sessions );
} }
sprintfW( id_strW, fmt_u, id ); sprintf( id_strA, "%u", id );
id_str.str = id_strW; id_strW = ascii_to_unicode_str( id_strA, &id_str );
id_str.len = strlenW( id_strW ) * sizeof(WCHAR);
dir_id = create_directory( &dir_sessions->obj, &id_str, 0, HASH_SIZE, NULL ); dir_id = create_directory( &dir_sessions->obj, &id_str, 0, HASH_SIZE, NULL );
dir_dosdevices = create_directory( &dir_id->obj, &dir_dosdevices_str, 0, HASH_SIZE, NULL ); dir_dosdevices = create_directory( &dir_id->obj, &dir_dosdevices_str, 0, HASH_SIZE, NULL );
@ -325,6 +324,7 @@ static void create_session( unsigned int id )
release_object( dir_windows ); release_object( dir_windows );
release_object( dir_bno ); release_object( dir_bno );
release_object( dir_id ); release_object( dir_id );
free( id_strW );
} }
void init_directories(void) void init_directories(void)

View File

@ -1740,25 +1740,16 @@ static int load_init_registry_from_file( const char *filename, struct key *key )
static WCHAR *format_user_registry_path( const SID *sid, struct unicode_str *path ) static WCHAR *format_user_registry_path( const SID *sid, struct unicode_str *path )
{ {
static const WCHAR prefixW[] = {'U','s','e','r','\\','S',0}; char buffer[7 + 11 + 11 + 11 * SID_MAX_SUB_AUTHORITIES], *p = buffer;
static const WCHAR formatW[] = {'-','%','u',0};
WCHAR buffer[7 + 10 + 10 + 10 * SID_MAX_SUB_AUTHORITIES];
WCHAR *p = buffer;
unsigned int i; unsigned int i;
strcpyW( p, prefixW ); p += sprintf( p, "User\\S-%u-%u", sid->Revision,
p += strlenW( prefixW ); MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5],
p += sprintfW( p, formatW, sid->Revision ); sid->IdentifierAuthority.Value[4] ),
p += sprintfW( p, formatW, MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5], MAKEWORD( sid->IdentifierAuthority.Value[3],
sid->IdentifierAuthority.Value[4] ), sid->IdentifierAuthority.Value[2] )));
MAKEWORD( sid->IdentifierAuthority.Value[3], for (i = 0; i < sid->SubAuthorityCount; i++) p += sprintf( p, "-%u", sid->SubAuthority[i] );
sid->IdentifierAuthority.Value[2] ))); return ascii_to_unicode_str( buffer, path );
for (i = 0; i < sid->SubAuthorityCount; i++)
p += sprintfW( p, formatW, sid->SubAuthority[i] );
path->len = (p - buffer) * sizeof(WCHAR);
path->str = p = memdup( buffer, path->len );
return p;
} }
/* get the cpu architectures that can be supported in the current prefix */ /* get the cpu architectures that can be supported in the current prefix */

View File

@ -51,6 +51,17 @@ static inline char to_hex( char ch )
return tolower(ch) - 'a' + 10; return tolower(ch) - 'a' + 10;
} }
WCHAR *ascii_to_unicode_str( const char *str, struct unicode_str *ret )
{
data_size_t i, len = strlen(str);
WCHAR *p;
ret->len = len * sizeof(WCHAR);
ret->str = p = mem_alloc( ret->len );
if (p) for (i = 0; i < len; i++) p[i] = (unsigned char)str[i];
return p;
}
/* parse an escaped string back into Unicode */ /* parse an escaped string back into Unicode */
/* return the number of chars read from the input, or -1 on output overflow */ /* return the number of chars read from the input, or -1 on output overflow */
int parse_strW( WCHAR *buffer, data_size_t *len, const char *src, char endchar ) int parse_strW( WCHAR *buffer, data_size_t *len, const char *src, char endchar )

View File

@ -27,12 +27,7 @@
#include "wine/unicode.h" #include "wine/unicode.h"
#include "object.h" #include "object.h"
static inline WCHAR *strdupW( const WCHAR *str ) extern WCHAR *ascii_to_unicode_str( const char *str, struct unicode_str *ret );
{
size_t len = (strlenW(str) + 1) * sizeof(WCHAR);
return memdup( str, len );
}
extern int parse_strW( WCHAR *buffer, data_size_t *len, const char *src, char endchar ); extern int parse_strW( WCHAR *buffer, data_size_t *len, const char *src, char endchar );
extern int dump_strW( const WCHAR *str, data_size_t len, FILE *f, const char escape[2] ); extern int dump_strW( const WCHAR *str, data_size_t len, FILE *f, const char escape[2] );