3 * Copyright (C) 2004 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * FILE: lib/userenv/misc.c
24 * PURPOSE: User profile code
25 * PROGRAMMER: Eric Kohl
31 /* FUNCTIONS ***************************************************************/
34 AppendBackslash (LPWSTR String
)
38 Length
= lstrlenW (String
);
39 if (String
[Length
- 1] != L
'\\')
41 String
[Length
] = L
'\\';
43 String
[Length
] = (WCHAR
)0;
46 return &String
[Length
];
51 GetUserSidFromToken (HANDLE hToken
,
52 PUNICODE_STRING SidString
)
54 PSID_AND_ATTRIBUTES SidBuffer
;
59 SidBuffer
= LocalAlloc (0,
61 if (SidBuffer
== NULL
)
64 Status
= NtQueryInformationToken (hToken
,
69 if (Status
== STATUS_BUFFER_TOO_SMALL
)
71 SidBuffer
= LocalReAlloc (SidBuffer
,
74 if (SidBuffer
== NULL
)
77 Status
= NtQueryInformationToken (hToken
,
84 if (!NT_SUCCESS (Status
))
86 LocalFree (SidBuffer
);
90 DPRINT ("SidLength: %lu\n", RtlLengthSid (SidBuffer
[0].Sid
));
92 Status
= RtlConvertSidToUnicodeString (SidString
,
96 LocalFree (SidBuffer
);
98 if (!NT_SUCCESS (Status
))
101 DPRINT ("SidString.Length: %lu\n", SidString
->Length
);
102 DPRINT ("SidString.MaximumLength: %lu\n", SidString
->MaximumLength
);
103 DPRINT ("SidString: '%wZ'\n", SidString
);
108 /* Dynamic DLL loading interface **********************************************/
110 /* OLE32.DLL import table */
111 DYN_MODULE DynOle32
=
124 * Use this function to load functions from other modules. We cannot statically
125 * link to e.g. ole32.dll because those dlls would get loaded on startup with
126 * winlogon and they may try to register classes etc when not even a window station
130 LoadDynamicImports(PDYN_MODULE Module
, PDYN_FUNCS DynFuncs
)
135 ZeroMemory(DynFuncs
, sizeof(DYN_FUNCS
));
137 DynFuncs
->hModule
= LoadLibraryW(Module
->Library
);
138 if (!DynFuncs
->hModule
)
143 fn
= &DynFuncs
->fn
.foo
;
145 /* load the imports */
146 for (fname
= Module
->Functions
; *fname
!= NULL
; fname
++)
148 *fn
= GetProcAddress(DynFuncs
->hModule
, *fname
);
151 FreeLibrary(DynFuncs
->hModule
);
152 DynFuncs
->hModule
= (HMODULE
)0;
165 UnloadDynamicImports(PDYN_FUNCS DynFuncs
)
167 if (DynFuncs
->hModule
)
169 FreeLibrary(DynFuncs
->hModule
);
170 DynFuncs
->hModule
= (HMODULE
)0;