Results 1 to 4 of 4

Thread: Act as part of the operating system

  1. #1

    Thread Starter
    Hyperactive Member Janaka's Avatar
    Join Date
    Nov 2001
    Posts
    277

    Act as part of the operating system

    I need to write a program to add an entry to Local Security Settings -> User Rights Assignment -> Act as part of the operating system.

    There is user in the network called \\lol_dev\yapa I need to add it to the computer that I am running the program (\\lol_dev\janaka).

    The code that I have written to do it is


    VB Code:
    1. #include "winNT.h"
    2. #include "NTSecAPI.h"
    3. #include "lm.h"
    4. #include "assert.h"
    5. #pragma hdrstop
    6. #pragma comment( lib, "netapi32.lib" )
    7.  
    8.  
    9. void CThirdDlg::AddUser() {
    10.  
    11.  
    12.     //char localgroup_name[100];
    13.     char domain_name[100];
    14.     DWORD domname_len = 100;
    15.     char psid_buffer[1024];
    16.     PSID psid = (PSID) psid_buffer;
    17.     DWORD sid_length = 1024;
    18.  
    19.     SID_NAME_USE acc_type;
    20.  
    21.  
    22.     BOOL fRet =  LookupAccountName (NULL, "\\lol_dev\yapa", psid,
    23.                   &sid_length, domain_name, &domname_len,
    24.                   &acc_type);
    25.    
    26.     ASSERT(fRet != 0);
    27.  
    28.     LSA_HANDLE          hPolicy = GetPolicyHandle();
    29.  
    30.    
    31.     LSA_UNICODE_STRING lsastrPrivs[1] = { 0 };
    32.  
    33.     //lsastrPrivs[0].Buffer = (PWSTR)SE_TCB_NAME;
    34.     lsastrPrivs[0].Buffer = (PWSTR)SE_SYSTEMTIME_NAME;
    35.     lsastrPrivs[0].Length = lstrlen((LPCSTR)lsastrPrivs[0].Buffer) * sizeof(WCHAR);
    36.     lsastrPrivs[0].MaximumLength = lsastrPrivs[0].Length + sizeof(WCHAR);
    37.  
    38.    
    39.     // this is the place I get the error
    40. NTSTATUS ntStatus = LsaAddAccountRights(hPolicy, psid, lsastrPrivs, 1);
    41.     ULONG lErr = LsaNtStatusToWinError(ntStatus);
    42.     CString msg = "Success";
    43.     if (lErr >0)
    44.     {
    45.        
    46.         msg.Format("Error %d", lErr);
    47.     }
    48.     AfxMessageBox( msg);
    49.  
    50. }
    51.  
    52. #define TARGET_SYSTEM_NAME L"JANAKA"
    53.  
    54.  
    55. LSA_HANDLE GetPolicyHandle()
    56. {
    57.   LSA_OBJECT_ATTRIBUTES ObjectAttributes;
    58.   WCHAR SystemName[] = TARGET_SYSTEM_NAME;
    59.   USHORT SystemNameLength;
    60.   LSA_UNICODE_STRING lusSystemName;
    61.   NTSTATUS ntsResult;
    62.   LSA_HANDLE lsahPolicyHandle;
    63.  
    64.   // Object attributes are reserved, so initialize to zeroes.
    65.   ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
    66.  
    67.   //Initialize an LSA_UNICODE_STRING to the server name.
    68.   SystemNameLength = wcslen(SystemName);
    69.   lusSystemName.Buffer = SystemName;
    70.   lusSystemName.Length = SystemNameLength * sizeof(WCHAR);
    71.   lusSystemName.MaximumLength = (SystemNameLength+1) * sizeof(WCHAR);
    72.  
    73.   // Get a handle to the Policy object.
    74.   ntsResult = LsaOpenPolicy(
    75.         &lusSystemName,    //Name of the target system.
    76.         &ObjectAttributes, //Object attributes.
    77.         POLICY_ALL_ACCESS, //Desired access permissions.
    78.         &lsahPolicyHandle  //Receives the policy handle.
    79.     );
    80.  
    81.   if (ntsResult != 0 )//STATUS_SUCCESS)
    82.   {
    83.     // An error occurred. Display it as a win32 error code.
    84.     wprintf(L"OpenPolicy returned %lu\n",
    85.       LsaNtStatusToWinError(ntsResult));
    86.     return NULL;
    87.   }
    88.   return lsahPolicyHandle;
    89. }

    when I run the program in the line

    VB Code:
    1. NTSTATUS ntStatus = LsaAddAccountRights(hPolicy, psid, lsastrPrivs, 1);
    I get the error the error code is 1313
    How do I fix it?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What does looking up code 1313 give you?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    It's a security rights violation.

    Are you sure you're running this app as an admin?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Hyperactive Member Janaka's Avatar
    Join Date
    Nov 2001
    Posts
    277
    yes i have admin rights.

    I need to write a program to add an entry to Local Security Settings -> User Rights Assignment -> Act as part of the operating system.

    I found these settings could be changed using Scripting Hosts too. Any idea about that?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width