青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

C++ Coder

HCP高性能計算架構,實現,編譯器指令優化,算法優化, LLVM CLANG OpenCL CUDA OpenACC C++AMP OpenMP MPI

C++博客 首頁 新隨筆 聯系 聚合 管理
  98 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks
http://www.cnblogs.com/bluesky_blog/archive/2009/04/29.html
管理用戶權限可以實現以編程方式使用下列步驟:
  1. 打開與 LsaOpenPolicy() 的目標計算機上的策略。 要授予的權限,打開 POLICY_CREATE_ACCOUNT 和 POLICY_LOOKUP_NAMES 訪問策略。 若要吊銷權限,打開 POLICY_LOOKUP_NAMES 訪問策略。
  2. 獲取一個 SID (安全標識符),表示用戶 / 組感興趣。 LookupAccountName() 和 LsaLookupNames() API 可以從一個帳戶名獲取 SID。
  3. 調用 LsaAddAccountRights() 向由提供的 SID 的用戶授予特權。
  4. 調用 LsaRemoveAccountRights() 撤消由提供的 SID 的用戶權限。
  5. 關閉該策略與 LsaClose()。
要成功授予和吊銷權限,調用方需要是目標系統上的管理員。

LSA API LsaEnumerateAccountRights() 可確定已授予的權限的帳戶。

LSA API LsaEnumerateAccountsWithUserRight() 可確定哪些帳戶已被授予指定的權限。

MSTOOLS\SECURITY 目錄中 Windows 32 SDK 中提供的這些 LSA API 的文檔和頭文件。

在 Win32 SDK 的最新版本中, 郵件頭顯示在 mstools\samples\win32\winnt\security\include 目錄中且文檔處于正在 \security\lsasamp\lsaapi.hlp。

注意: 這些 LSA API 是當前實現以 Unicode 格式僅。

本示例將授予特權 SeServiceLogonRight 為 argv [1] 上指定的帳戶。

此示例是依賴于這些導入庫
advapi32.lib (對于 LsaXxx)
user32.lib (對于 wsprintf)
本示例將工作正確編譯 ANSI 或 Unicode。

示例代碼

  1/*++
  2You can use domain\account as argv[1]. For instance, mydomain\scott will
  3grant the privilege to the mydomain domain account scott.
  4The optional target machine is specified as argv[2], otherwise, the
  5account database is updated on the local machine.
  6The LSA APIs used by this sample are Unicode only.
  7Use LsaRemoveAccountRights() to remove account rights.
  8Scott Field (sfield)    12-Jul-95
  9--*/

 10#ifndef UNICODE
 11#define UNICODE
 12#endif // UNICODE
 13#include <windows.h>
 14#include <stdio.h>
 15#include "ntsecapi.h"
 16NTSTATUS
 17OpenPolicy(
 18LPWSTR ServerName,          // machine to open policy on (Unicode)
 19DWORD DesiredAccess,        // desired access to policy
 20PLSA_HANDLE PolicyHandle    // resultant policy handle
 21);
 22BOOL
 23GetAccountSid(
 24LPTSTR SystemName,          // where to lookup account
 25LPTSTR AccountName,         // account of interest
 26PSID *Sid                   // resultant buffer containing SID
 27);
 28NTSTATUS
 29SetPrivilegeOnAccount(
 30LSA_HANDLE PolicyHandle,    // open policy handle
 31PSID AccountSid,            // SID to grant privilege to
 32LPWSTR PrivilegeName,       // privilege to grant (Unicode)
 33BOOL bEnable                // enable or disable
 34);
 35void
 36InitLsaString(
 37PLSA_UNICODE_STRING LsaString, // destination
 38LPWSTR String                  // source (Unicode)
 39);
 40void
 41DisplayNtStatus(
 42LPSTR szAPI,                // pointer to function name (ANSI)
 43NTSTATUS Status             // NTSTATUS error value
 44);
 45void
 46DisplayWinError(
 47LPSTR szAPI,                // pointer to function name (ANSI)
 48DWORD WinError              // DWORD WinError
 49);
 50#define RTN_OK 0
 51#define RTN_USAGE 1
 52#define RTN_ERROR 13
 53//
 54// If you have the ddk, include ntstatus.h.
 55//
 56#ifndef STATUS_SUCCESS
 57#define STATUS_SUCCESS  ((NTSTATUS)0x00000000L)
 58#endif
 59int _cdecl
 60main(int argc, char *argv[])
 61{
 62LSA_HANDLE PolicyHandle;
 63WCHAR wComputerName[256]=L"";   // static machine name buffer
 64TCHAR AccountName[256];         // static account name buffer
 65PSID pSid;
 66NTSTATUS Status;
 67int iRetVal=RTN_ERROR;          // assume error from main
 68if(argc == 1)
 69{
 70fprintf(stderr,"Usage: %s <Account> [TargetMachine]\n",
 71argv[0]);
 72return RTN_USAGE;
 73}

 74//
 75// Pick up account name on argv[1].
 76// Assumes source is ANSI. Resultant string is ANSI or Unicode
 77//
 78wsprintf(AccountName, TEXT("%hS"), argv[1]);
 79//
 80// Pick up machine name on argv[2], if appropriate
 81// assumes source is ANSI. Resultant string is Unicode.
 82//
 83if(argc == 3) wsprintfW(wComputerName, L"%hS", argv[2]);
 84//
 85// Open the policy on the target machine.
 86//
 87if((Status=OpenPolicy(
 88wComputerName,      // target machine
 89POLICY_CREATE_ACCOUNT | POLICY_LOOKUP_NAMES,
 90&PolicyHandle       // resultant policy handle
 91)) != STATUS_SUCCESS) {
 92DisplayNtStatus("OpenPolicy", Status);
 93return RTN_ERROR;
 94}

 95//
 96// Obtain the SID of the user/group.
 97// Note that we could target a specific machine, but we don't.
 98// Specifying NULL for target machine searches for the SID in the
 99// following order: well-known, Built-in and local, primary domain,
100// trusted domains.
101//
102if(GetAccountSid(
103NULL,       // default lookup logic
104AccountName,// account to obtain SID
105&pSid       // buffer to allocate to contain resultant SID
106)) {
107//
108// We only grant the privilege if we succeeded in obtaining the
109// SID. We can actually add SIDs which cannot be looked up, but
110// looking up the SID is a good sanity check which is suitable for
111// most cases.
112//
113// Grant the SeServiceLogonRight to users represented by pSid.
114//
115if((Status=SetPrivilegeOnAccount(
116PolicyHandle,           // policy handle
117pSid,                   // SID to grant privilege
118L"SeServiceLogonRight"// Unicode privilege
119TRUE                    // enable the privilege
120)) == STATUS_SUCCESS)
121iRetVal=RTN_OK;
122else
123DisplayNtStatus("AddUserRightToAccount", Status);
124}

125else {
126//
127// Error obtaining SID.
128//
129DisplayWinError("GetAccountSid", GetLastError());
130}

131//
132// Close the policy handle.
133//
134LsaClose(PolicyHandle);
135//
136// Free memory allocated for SID.
137//
138if(pSid != NULL) HeapFree(GetProcessHeap(), 0, pSid);
139return iRetVal;
140}

141void
142InitLsaString(
143PLSA_UNICODE_STRING LsaString,
144LPWSTR String
145)
146{
147DWORD StringLength;
148if (String == NULL) {
149LsaString->Buffer = NULL;
150LsaString->Length = 0;
151LsaString->MaximumLength = 0;
152return;
153}

154StringLength = wcslen(String);
155LsaString->Buffer = String;
156LsaString->Length = (USHORT) StringLength * sizeof(WCHAR);
157LsaString->MaximumLength=(USHORT)(StringLength+1* sizeof(WCHAR);
158}

159NTSTATUS
160OpenPolicy(
161LPWSTR ServerName,
162DWORD DesiredAccess,
163PLSA_HANDLE PolicyHandle
164)
165{
166LSA_OBJECT_ATTRIBUTES ObjectAttributes;
167LSA_UNICODE_STRING ServerString;
168PLSA_UNICODE_STRING Server = NULL;
169//
170// Always initialize the object attributes to all zeroes.
171//
172ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
173if (ServerName != NULL) {
174//
175// Make a LSA_UNICODE_STRING out of the LPWSTR passed in
176//
177InitLsaString(&ServerString, ServerName);
178Server = &ServerString;
179}

180//
181// Attempt to open the policy.
182//
183return LsaOpenPolicy(
184Server,
185&ObjectAttributes,
186DesiredAccess,
187PolicyHandle
188);
189}

190/*++
191This function attempts to obtain a SID representing the supplied
192account on the supplied system.
193If the function succeeds, the return value is TRUE. A buffer is
194allocated which contains the SID representing the supplied account.
195This buffer should be freed when it is no longer needed by calling
196HeapFree(GetProcessHeap(), 0, buffer)
197If the function fails, the return value is FALSE. Call GetLastError()
198to obtain extended error information.
199Scott Field (sfield)    12-Jul-95
200--*/

201BOOL
202GetAccountSid(
203LPTSTR SystemName,
204LPTSTR AccountName,
205PSID *Sid
206)
207{
208LPTSTR ReferencedDomain=NULL;
209DWORD cbSid=128;    // initial allocation attempt
210DWORD cchReferencedDomain=16// initial allocation size
211SID_NAME_USE peUse;
212BOOL bSuccess=FALSE; // assume this function will fail
213__try {
214//
215// initial memory allocations
216//
217if((*Sid=HeapAlloc(
218GetProcessHeap(),
2190,
220cbSid
221)) == NULL) __leave;
222if((ReferencedDomain=(LPTSTR)HeapAlloc(
223GetProcessHeap(),
2240,
225cchReferencedDomain * sizeof(TCHAR)
226)) == NULL) __leave;
227//
228// Obtain the SID of the specified account on the specified system.
229//
230while(!LookupAccountName(
231SystemName,         // machine to lookup account on
232AccountName,        // account to lookup
233*Sid,               // SID of interest
234&cbSid,             // size of SID
235ReferencedDomain,   // domain account was found on
236&cchReferencedDomain,
237&peUse
238)) {
239if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
240//
241// reallocate memory
242//
243if((*Sid=HeapReAlloc(
244GetProcessHeap(),
2450,
246*Sid,
247cbSid
248)) == NULL) __leave;
249if((ReferencedDomain=(LPTSTR)HeapReAlloc(
250GetProcessHeap(),
2510,
252ReferencedDomain,
253cchReferencedDomain * sizeof(TCHAR)
254)) == NULL) __leave;
255}

256else __leave;
257}

258//
259// Indicate success.
260//
261bSuccess=TRUE;
262}
 // finally
263__finally {
264//
265// Cleanup and indicate failure, if appropriate.
266//
267HeapFree(GetProcessHeap(), 0, ReferencedDomain);
268if(!bSuccess) {
269if(*Sid != NULL) {
270HeapFree(GetProcessHeap(), 0*Sid);
271*Sid = NULL;
272}

273}

274}
 // finally
275return bSuccess;
276}

277NTSTATUS
278SetPrivilegeOnAccount(
279LSA_HANDLE PolicyHandle,    // open policy handle
280PSID AccountSid,            // SID to grant privilege to
281LPWSTR PrivilegeName,       // privilege to grant (Unicode)
282BOOL bEnable                // enable or disable
283)
284{
285LSA_UNICODE_STRING PrivilegeString;
286//
287// Create a LSA_UNICODE_STRING for the privilege name.
288//
289InitLsaString(&PrivilegeString, PrivilegeName);
290//
291// grant or revoke the privilege, accordingly
292//
293if(bEnable) {
294return LsaAddAccountRights(
295PolicyHandle,       // open policy handle
296AccountSid,         // target SID
297&PrivilegeString,   // privileges
2981                   // privilege count
299);
300}

301else {
302return LsaRemoveAccountRights(
303PolicyHandle,       // open policy handle
304AccountSid,         // target SID
305FALSE,              // do not disable all rights
306&PrivilegeString,   // privileges
3071                   // privilege count
308);
309}

310}

311void
312DisplayNtStatus(
313LPSTR szAPI,
314NTSTATUS Status
315)
316{
317//
318// Convert the NTSTATUS to Winerror. Then call DisplayWinError().
319//
320DisplayWinError(szAPI, LsaNtStatusToWinError(Status));
321}

322void
323DisplayWinError(
324LPSTR szAPI,
325DWORD WinError
326)
327{
328LPSTR MessageBuffer;
329DWORD dwBufferLength;
330//
331// TODO: Get this fprintf out of here!
332//
333fprintf(stderr,"%s error!\n", szAPI);
334if(dwBufferLength=FormatMessageA(
335FORMAT_MESSAGE_ALLOCATE_BUFFER |
336FORMAT_MESSAGE_FROM_SYSTEM,
337NULL,
338WinError,
339GetUserDefaultLangID(),
340(LPSTR) &MessageBuffer,
3410,
342NULL
343))
344{
345DWORD dwBytesWritten; // unused
346//
347// Output message string on stderr.
348//
349WriteFile(
350GetStdHandle(STD_ERROR_HANDLE),
351MessageBuffer,
352dwBufferLength,
353&dwBytesWritten,
354NULL
355);
356//
357// Free the buffer allocated by the system.
358//
359LocalFree(MessageBuffer);
360}

361}

362
363/*++
364This function enables system access on the account represented by the
365supplied SID. An example of such access is the SeLogonServiceRight.
366Note: to disable a given system access, simply remove the supplied
367access flag from the existing flag, and apply the result to the
368account.
369If the function succeeds, the return value is STATUS_SUCCESS.
370If the function fails, the return value is an NTSTATUS value.
371Scott Field (sfield)    14-Jul-95
372--*/

373NTSTATUS
374AddSystemAccessToAccount(
375LSA_HANDLE PolicyHandle,
376PSID AccountSid,
377ULONG NewAccess
378)
379{
380LSA_HANDLE AccountHandle;
381ULONG PreviousAccess;
382NTSTATUS Status;
383//
384// open the account object. If it doesn't exist, create a new one
385//
386if((Status=LsaOpenAccount(
387PolicyHandle,
388AccountSid,
389ACCOUNT_ADJUST_SYSTEM_ACCESS | ACCOUNT_VIEW,
390&AccountHandle
391)) == STATUS_OBJECT_NAME_NOT_FOUND)
392{
393Status=LsaCreateAccount(
394PolicyHandle,
395AccountSid,
396ACCOUNT_ADJUST_SYSTEM_ACCESS | ACCOUNT_VIEW,
397&AccountHandle
398);
399}

400//
401// if an error occurred opening or creating, return
402//
403if(Status != STATUS_SUCCESS) return Status;
404//
405// obtain current system access flags
406//
407if((Status=LsaGetSystemAccessAccount(
408AccountHandle,
409&PreviousAccess
410)) == STATUS_SUCCESS)
411{
412//
413// Add the specified access to the account
414//
415Status=LsaSetSystemAccessAccount(
416AccountHandle,
417PreviousAccess | NewAccess
418);
419}

420LsaClose(AccountHandle);
421return Status;
422}

423/*++
424This function grants a privilege to the account represented by the
425supplied SID. An example of such a privilege is the
426SeBackupPrivilege.
427Note: To revoke a privilege, use LsaRemovePrivilegesFromAccount.
428If the function succeeds, the return value is STATUS_SUCCESS.
429If the function fails, the return value is an NTSTATUS value.
430Scott Field (sfield)    13-Jul-95
431--*/

432NTSTATUS
433AddPrivilegeToAccount(
434LSA_HANDLE PolicyHandle,
435PSID AccountSid,
436LPWSTR PrivilegeName
437)
438{
439PRIVILEGE_SET ps;
440LUID_AND_ATTRIBUTES luidattr;
441LSA_HANDLE AccountHandle;
442LSA_UNICODE_STRING PrivilegeString;
443NTSTATUS Status;
444//
445// Create a LSA_UNICODE_STRING for the privilege name
446//
447InitLsaString(&PrivilegeString, PrivilegeName);
448//
449// obtain the LUID of the supplied privilege
450//
451if((Status=LsaLookupPrivilegeValue(
452PolicyHandle,
453&PrivilegeString,
454&luidattr.Luid
455)) != STATUS_SUCCESS) return Status;
456//
457// setup PRIVILEGE_SET
458//
459luidattr.Attributes=0;
460ps.PrivilegeCount=1;
461ps.Control=0;
462ps.Privilege[0]=luidattr;
463//
464// open the account object if it doesn't exist, create a new one
465//
466if((Status=LsaOpenAccount(
467PolicyHandle,
468AccountSid,
469ACCOUNT_ADJUST_PRIVILEGES,
470&AccountHandle
471)) == STATUS_OBJECT_NAME_NOT_FOUND)
472{
473Status=LsaCreateAccount(
474PolicyHandle,
475AccountSid,
476ACCOUNT_ADJUST_PRIVILEGES,
477&AccountHandle
478);
479}

480//
481// if an error occurred opening or creating, return
482//
483if(Status != STATUS_SUCCESS) return Status;
484//
485// add the privileges to the account
486//
487Status=LsaAddPrivilegesToAccount(
488AccountHandle,
489&ps
490);
491LsaClose(AccountHandle);
492return Status;
493}

494
495
posted on 2012-10-18 10:29 jackdong 閱讀(916) 評論(0)  編輯 收藏 引用 所屬分類: Windows編程
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            99在线|亚洲一区二区| 日韩视频专区| 欧美大色视频| 久热国产精品视频| 美女尤物久久精品| 男女视频一区二区| 欧美伦理视频网站| 国产精品yjizz| 亚洲网站在线| 在线精品国精品国产尤物884a| 国内一区二区三区在线视频| 狠狠色狠色综合曰曰| 欧美精品一区在线观看| 欧美亚洲在线播放| 久久精品亚洲精品| 欧美电影免费网站| 国产精品jizz在线观看美国| 国产目拍亚洲精品99久久精品| 国产伦精品一区二区三区高清版| 国产一区二区三区无遮挡| 在线观看亚洲精品视频| 亚洲美女在线看| 香蕉亚洲视频| 欧美二区在线播放| 亚洲一区二区三区欧美| 老司机精品福利视频| 国产精品成人国产乱一区| 国内久久婷婷综合| 亚洲性av在线| 欧美成人国产一区二区| 亚洲精品久久久久久久久| 99re成人精品视频| 久久久综合网| 国产日韩av高清| 亚洲精品免费网站| 久久蜜桃精品| 亚洲一本视频| 欧美理论在线| 亚洲黄色免费电影| 久久精品一区二区三区不卡牛牛| 亚洲精品乱码久久久久久久久| 欧美一区二区三区久久精品茉莉花| 欧美韩国日本综合| 狠狠入ady亚洲精品| 亚洲欧美激情精品一区二区| 欧美凹凸一区二区三区视频| 亚洲欧美精品在线观看| 欧美激情va永久在线播放| 国产有码在线一区二区视频| 亚洲资源在线观看| 亚洲精品久久| 欧美人妖另类| 亚洲精品欧美一区二区三区| 免费成人毛片| 欧美一区二区高清在线观看| 国产精品久久久久久久电影| 99综合精品| 亚洲欧洲精品一区二区三区波多野1战4| 欧美一区二区在线免费观看| 国产精品毛片a∨一区二区三区| 亚洲伦伦在线| 亚洲人成网站999久久久综合| 久久久久久久久蜜桃| 国产专区一区| 久久在精品线影院精品国产| 免费欧美日韩国产三级电影| 午夜欧美不卡精品aaaaa| 亚洲日本一区二区| 欧美精品电影在线| 99这里只有精品| 99精品国产在热久久婷婷| 欧美日韩精品免费观看视频完整| 日韩视频在线一区二区三区| 亚洲精品一区在线| 欧美视频免费在线观看| 午夜精品av| 亚洲欧美日韩电影| 国产一区在线免费观看| 免费在线成人| 欧美精品色综合| 亚洲综合国产| 久久国产精品久久久| 亚洲成人在线免费| 91久久中文字幕| 国产精品jvid在线观看蜜臀| 欧美在线观看视频一区二区| 久久国产精品亚洲77777| 亚洲黄色免费| 一本色道久久88亚洲综合88| 国产欧美日韩视频一区二区三区| 久久免费精品日本久久中文字幕| 久久亚洲电影| 中日韩美女免费视频网站在线观看 | 亚洲在线免费观看| 好吊妞这里只有精品| 亚洲精品影院| 狠狠综合久久av一区二区老牛| 亚洲国产精品一区二区www| 欧美视频中文一区二区三区在线观看| 先锋影音网一区二区| 毛片av中文字幕一区二区| 亚洲综合国产精品| 欧美成人一区二区三区片免费| 亚洲欧美日韩另类精品一区二区三区| 久久国产精品久久久久久久久久 | 91久久黄色| 一本色道久久综合一区| 激情久久综合| 亚洲少妇一区| 亚洲久久一区二区| 欧美中文字幕久久| 亚洲女爱视频在线| 欧美激情久久久久| 亚洲欧美日韩第一区| 午夜精品久久久久久久白皮肤 | 国语自产精品视频在线看抢先版结局 | 久久久人成影片一区二区三区观看| 欧美成年人视频网站| 久久国产精品久久久久久电车| 欧美国产第二页| 久久综合网络一区二区| 国产精品夜夜嗨| 在线视频精品一| 日韩午夜电影| 蜜桃av一区| 美女999久久久精品视频| 国产一区二区0| 亚洲专区在线视频| 亚洲午夜精品久久久久久app| 免费不卡在线观看av| 裸体一区二区三区| 国产欧美视频一区二区| 亚洲婷婷综合久久一本伊一区| 99视频超级精品| 欧美国产一区视频在线观看| 欧美激情精品久久久六区热门| 亚洲电影在线播放| 久久综合五月| 欧美国产在线视频| 亚洲精品久久久久久久久久久 | 国产亚洲精品久久久久久| 亚洲一区二区精品在线| 亚洲一级二级| 国产精品成人在线观看| 在线视频日本亚洲性| 中文日韩在线| 国产精品乱码一区二区三区| 中文亚洲视频在线| 香蕉国产精品偷在线观看不卡| 国产精品美女久久久久久免费| 亚洲午夜激情免费视频| 欧美一区二区私人影院日本| 国产精品专区一| 久久精品亚洲精品国产欧美kt∨| 久久天天躁夜夜躁狠狠躁2022| 一区三区视频| 欧美二区在线| 亚洲图片自拍偷拍| 久久久免费精品| 亚洲欧洲精品一区二区精品久久久| 免费观看一级特黄欧美大片| 亚洲激情校园春色| 在线性视频日韩欧美| 国产精品久久久久天堂| 久久岛国电影| 亚洲精品久久久久| 久久久久**毛片大全| 亚洲欧洲午夜| 国产精品女主播一区二区三区| 欧美在线视频免费播放| 欧美黄色大片网站| 亚洲一本大道在线| 尤物yw午夜国产精品视频明星 | 亚洲国产欧美久久| 欧美三级欧美一级| 久久久久久精| 99综合在线| 欧美成人精品一区| 亚洲欧美国内爽妇网| 亚洲欧洲精品一区二区三区波多野1战4 | 亚洲特黄一级片| 久久综合九色综合欧美就去吻 | 美女视频黄免费的久久| 一区二区三区视频在线播放| 国内精品久久久| 欧美日韩大片一区二区三区| 欧美一级欧美一级在线播放| 最新高清无码专区| 久久久久久久久一区二区| 中文高清一区| 亚洲激情婷婷| 好吊成人免视频| 国产欧美欧洲在线观看| 欧美日韩三级在线| 免费中文日韩| 久久久免费精品视频| 翔田千里一区二区| 国产精品99久久不卡二区| 亚洲精品国产精品国自产观看| 亚洲国产精品ⅴa在线观看|