static
VOID
PrintGroupInfo_1(
    PLSA_GROUP_INFO_1 pGroupInfo
    )
{
    PSTR* ppszMembers = NULL;

    fprintf(stdout, "Group info (Level-1):\n");
    fprintf(stdout, "====================\n");
    fprintf(stdout, "Name: %s\n", LW_PRINTF_STRING(pGroupInfo->pszName));
    fprintf(stdout, "Gid:  %u\n", (unsigned int)pGroupInfo->gid);
    fprintf(stdout, "SID:  %s\n", LW_PRINTF_STRING(pGroupInfo->pszSid));
    fprintf(stdout, "Members:\n");

    ppszMembers = pGroupInfo->ppszMembers;
    if (ppszMembers)
    {
        while (!LW_IS_NULL_OR_EMPTY_STR(*ppszMembers))
        {
            fprintf(stdout, "  %s\n", *ppszMembers);
            ppszMembers++;
        }
    }
    fprintf(stdout, "\n");
}
Beispiel #2
0
VOID
PrintUserInfo_2(
    PLSA_USER_INFO_2 pUserInfo,
    BOOLEAN bCheckUserInList,
    BOOLEAN bAllowedLogon
    )
{
    fprintf(stdout, "User info (Level-2):\n");
    fprintf(stdout, "====================\n");
    fprintf(stdout, "Name:                         %s\n", LW_PRINTF_STRING(pUserInfo->pszName));
    fprintf(stdout, "UPN:                          %s\n", LW_PRINTF_STRING(pUserInfo->pszUPN));
    fprintf(stdout, "Generated UPN:                %s\n", LW_PRINTF_YES_NO(pUserInfo->bIsGeneratedUPN));
    fprintf(stdout, "DN:                           %s\n",
            LW_IS_NULL_OR_EMPTY_STR(pUserInfo->pszDN) ? "<null>" : pUserInfo->pszDN);
    fprintf(stdout, "Uid:                          %u\n", (unsigned int)pUserInfo->uid);
    fprintf(stdout, "Gid:                          %u\n", (unsigned int)pUserInfo->gid);
    fprintf(stdout, "Gecos:                        %s\n", LW_PRINTF_STRING(pUserInfo->pszGecos));
    fprintf(stdout, "Shell:                        %s\n", LW_PRINTF_STRING(pUserInfo->pszShell));
    fprintf(stdout, "Home dir:                     %s\n", LW_PRINTF_STRING(pUserInfo->pszHomedir));
    fprintf(stdout, "LMHash length:                %u\n", pUserInfo->dwLMHashLen);
    fprintf(stdout, "NTHash length:                %u\n", pUserInfo->dwNTHashLen);
    fprintf(stdout, "Local User:                   %s\n", LW_PRINTF_YES_NO(pUserInfo->bIsLocalUser));
    fprintf(stdout, "Account disabled (or locked): %s\n", LW_PRINTF_TRUE_FALSE(pUserInfo->bAccountDisabled));
    fprintf(stdout, "Account Expired:              %s\n", LW_PRINTF_TRUE_FALSE(pUserInfo->bAccountExpired));
    fprintf(stdout, "Password never expires:       %s\n", LW_PRINTF_TRUE_FALSE(pUserInfo->bPasswordNeverExpires));
    fprintf(stdout, "Password Expired:             %s\n", LW_PRINTF_TRUE_FALSE(pUserInfo->bPasswordExpired));
    fprintf(stdout, "Prompt for password change:   %s\n", LW_PRINTF_YES_NO(pUserInfo->bPromptPasswordChange));
    fprintf(stdout, "User can change password:     %s\n", LW_PRINTF_YES_NO(pUserInfo->bUserCanChangePassword));
    fprintf(stdout, "Days till password expires:   %u\n", pUserInfo->dwDaysToPasswordExpiry);
    if (bCheckUserInList)
    {
        fprintf(stdout, "Logon restriction:            %s\n", LW_PRINTF_YES_NO(bAllowedLogon));
    }
    fprintf(stdout, "\n");
}
Beispiel #3
0
VOID
PrintUserInfo_1(
    PLSA_USER_INFO_1 pUserInfo,
    BOOLEAN bCheckUserInList,
    BOOLEAN bAllowedLogon
    )
{
    fprintf(stdout, "User info (Level-1):\n");
    fprintf(stdout, "====================\n");
    fprintf(stdout, "Name:              %s\n", LW_PRINTF_STRING(pUserInfo->pszName));
    fprintf(stdout, "UPN:               %s\n", LW_PRINTF_STRING(pUserInfo->pszUPN));
    fprintf(stdout, "Generated UPN:     %s\n", LW_PRINTF_YES_NO(pUserInfo->bIsGeneratedUPN));
    fprintf(stdout, "Uid:               %u\n", (unsigned int)pUserInfo->uid);
    fprintf(stdout, "Gid:               %u\n", (unsigned int)pUserInfo->gid);
    fprintf(stdout, "Gecos:             %s\n", LW_PRINTF_STRING(pUserInfo->pszGecos));
    fprintf(stdout, "Shell:             %s\n", LW_PRINTF_STRING(pUserInfo->pszShell));
    fprintf(stdout, "Home dir:          %s\n", LW_PRINTF_STRING(pUserInfo->pszHomedir));
    fprintf(stdout, "LMHash length:     %u\n", pUserInfo->dwLMHashLen);
    fprintf(stdout, "NTHash length:     %u\n", pUserInfo->dwNTHashLen);
    fprintf(stdout, "Local User:        %s\n", LW_PRINTF_YES_NO(pUserInfo->bIsLocalUser));
    if (bCheckUserInList)
    {
        fprintf(stdout, "Logon restriction: %s\n", LW_PRINTF_YES_NO(bAllowedLogon));
    }
    fprintf(stdout, "\n");
}
static
VOID
PrintGroupInfo_0(
    PLSA_GROUP_INFO_0 pGroupInfo
    )
{
    fprintf(stdout, "Group info (Level-0):\n");
    fprintf(stdout, "====================\n");
    fprintf(stdout, "Name: %s\n", LW_PRINTF_STRING(pGroupInfo->pszName));
    fprintf(stdout, "Gid:  %u\n", (unsigned int)pGroupInfo->gid);
    fprintf(stdout, "SID:  %s\n", LW_PRINTF_STRING(pGroupInfo->pszSid));
    fprintf(stdout, "\n");
}
Beispiel #5
0
VOID
RegPrintError(
    IN OPTIONAL PCSTR pszErrorPrefix,
    IN DWORD dwError
    )
{
    PCSTR pszUseErrorPrefix = NULL;
    size_t size = 0;
    PSTR pszErrorString = NULL;
    PCSTR pszWinError = NULL;

    if (dwError)
    {
        pszUseErrorPrefix = pszErrorPrefix;
        if (!pszUseErrorPrefix)
        {
            pszUseErrorPrefix = "LWREG ERROR: ";
        }

        size = LwRegGetErrorString(dwError, NULL, 0);
        if (size)
        {
            pszErrorString = malloc(size);
            if (pszErrorString)
            {
            	LwRegGetErrorString(dwError, pszErrorString, size);
            }
        }

        pszWinError = LW_PRINTF_STRING(RegWin32ExtErrorToName(dwError));

        if (!pszWinError)
        {
            pszWinError = "";
        }

        if (LW_IS_NULL_OR_EMPTY_STR(pszErrorString))
        {
            fprintf(stderr,
                    "%s (error = %u%s%s)\n",
                     pszUseErrorPrefix,
                     dwError,
                     *pszWinError ? " - " : "",
                     pszWinError);
        }
        else
        {
            fprintf(stderr,
                    "%s (error = %u%s%s)\n%s\n",
                    pszUseErrorPrefix,
                    dwError,
                    *pszWinError ? " - " : "",
                    pszWinError,
                    pszErrorString);
        }
    }
    LWREG_SAFE_FREE_STRING(pszErrorString);
}
Beispiel #6
0
VOID
PrintUserInfo_0(
    PLSA_USER_INFO_0 pUserInfo,
    BOOLEAN bCheckUserInList,
    BOOLEAN bAllowedLogon
    )
{
    fprintf(stdout, "User info (Level-0):\n");
    fprintf(stdout, "====================\n");
    fprintf(stdout, "Name:              %s\n", LW_PRINTF_STRING(pUserInfo->pszName));
    fprintf(stdout, "Uid:               %u\n", (unsigned int)pUserInfo->uid);
    fprintf(stdout, "Gid:               %u\n", (unsigned int)pUserInfo->gid);
    fprintf(stdout, "Gecos:             %s\n", LW_PRINTF_STRING(pUserInfo->pszGecos));
    fprintf(stdout, "Shell:             %s\n", LW_PRINTF_STRING(pUserInfo->pszShell));
    fprintf(stdout, "Home dir:          %s\n", LW_PRINTF_STRING(pUserInfo->pszHomedir));
    if (bCheckUserInList)
    {
        fprintf(stdout, "Logon restriction: %s\n", LW_PRINTF_YES_NO(bAllowedLogon));
    }
    fprintf(stdout, "\n");
}
Beispiel #7
0
VOID
PrintErrorMessage(
    IN DWORD ErrorCode
    )
{
    PCSTR pszErrorName = LwWin32ExtErrorToName(ErrorCode);
    PSTR pszErrorMessage = NULL;
    DWORD size = LwGetErrorString(ErrorCode, NULL, 0);

    if (size > 0)
    {
        DWORD dwError = LwAllocateMemory(size, OUT_PPVOID(&pszErrorMessage));
        if (!dwError)
        {
            (void) LwGetErrorString(ErrorCode, pszErrorMessage, size);
        }
    }

    if (!LW_IS_NULL_OR_EMPTY_STR(pszErrorMessage))
    {
        fprintf(stderr,
                "Error code %u (%s).\n%s\n",
                ErrorCode,
                LW_PRINTF_STRING(pszErrorName),
                pszErrorMessage);
    }
    else
    {
        fprintf(stderr,
                "Error code %u (%s).\n",
                ErrorCode,
                LW_PRINTF_STRING(pszErrorName));
    }

    LW_SAFE_FREE_STRING(pszErrorMessage);
}
Beispiel #8
0
int
ad_cache_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    HANDLE hLsaConnection = (HANDLE)NULL;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;
    PSTR    pszOperation = "complete operation";
    DWORD   dwAction = ACTION_NONE;
    PSTR    pszDomainName = NULL;
    PSTR    pszName = NULL;
    uid_t   uid = 0;
    gid_t   gid = 0;
    bool    bForceOfflineDelete;
    DWORD   dwBatchSize = 10;

    if (argc < 2 ||
        (strcmp(argv[1], "--help") == 0) ||
        (strcmp(argv[1], "-h") == 0))
    {
        ShowUsage(GetProgramName(argv[0]));
        exit(0);
    }

    if (geteuid() != 0) {
        fprintf(stderr, "This program requires super-user privileges.\n");
        dwError = LW_ERROR_ACCESS_DENIED;
        BAIL_ON_LSA_ERROR(dwError);
    }

    dwError = ParseArgs(
                  argc,
                  argv,
                  &dwAction,
                  &pszDomainName,
                  &pszName,
                  &uid,
                  &gid,
                  &bForceOfflineDelete,
                  &dwBatchSize);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    switch (dwAction)
    {
        case ACTION_DELETE_ALL:
            pszOperation = "empty cache";

            dwError = LsaAdEmptyCache(
                          hLsaConnection,
                          pszDomainName,
                          bForceOfflineDelete);
            BAIL_ON_LSA_ERROR(dwError);

            fprintf(stdout, "The cache has been emptied successfully.\n");

            break;

        case ACTION_DELETE_USER:
            pszOperation = "delete user";

            if ( pszName )
            {
                dwError = LsaAdRemoveUserByNameFromCache(
                              hLsaConnection,
                              pszDomainName,
                              pszName);
                BAIL_ON_LSA_ERROR(dwError);
            }
            else
            {
                dwError = LsaAdRemoveUserByIdFromCache(
                              hLsaConnection,
                              pszDomainName,
                              uid);
                BAIL_ON_LSA_ERROR(dwError);
            }

            fprintf(stdout, "The user has been deleted from the cache successfully.\n");

            break;

        case ACTION_DELETE_GROUP:
            pszOperation = "delete group";

            if ( pszName )
            {
                dwError = LsaAdRemoveGroupByNameFromCache(
                              hLsaConnection,
                              pszDomainName,
                              pszName);
                BAIL_ON_LSA_ERROR(dwError);
            }
            else
            {
                dwError = LsaAdRemoveGroupByIdFromCache(
                              hLsaConnection,
                              pszDomainName,
                              gid);
                BAIL_ON_LSA_ERROR(dwError);
            }

            fprintf(stdout, "The group has been deleted from the cache successfully.\n");

            break;

        case ACTION_ENUM_USERS:
            pszOperation = "enumerate users";

            dwError = EnumerateUsers(
                          hLsaConnection,
                          pszDomainName,
                          dwBatchSize);
            BAIL_ON_LSA_ERROR(dwError);

            break;

        case ACTION_ENUM_GROUPS:
            pszOperation = "enumerate groups";

            dwError = EnumerateGroups(
                          hLsaConnection,
                          pszDomainName,
                          dwBatchSize);
            BAIL_ON_LSA_ERROR(dwError);

        break;
    }

cleanup:

    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    return dwError;

error:

    dwError = MapErrorCode(dwError);
    
    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);
    
    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;
        
        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);
        
        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);
            
            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr,
                        "Failed to %s.  Error code %u (%s).\n%s\n",
                        pszOperation,
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }
        
        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }
    
    if (bPrintOrigError)
    {
        fprintf(stderr,
                "Failed to %s.  Error code %u (%s).\n",
                pszOperation,
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }
    
    goto cleanup;
}
int
set_log_level_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    LsaLogLevel logLevel = LSA_LOG_LEVEL_ERROR;
    HANDLE hLsaConnection = (HANDLE)NULL;
    PLSA_LOG_INFO pLogInfo = NULL;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;
    
    if (geteuid() != 0) {
        fprintf(stderr, "This program requires super-user privileges.\n");
        dwError = LW_ERROR_ACCESS_DENIED;
        BAIL_ON_LSA_ERROR(dwError);
    }

    dwError = ParseArgs(argc, argv, &logLevel);
    BAIL_ON_LSA_ERROR(dwError);
    
    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);
    
    dwError = LsaSetLogLevel(
                    hLsaConnection,
                    logLevel);
    BAIL_ON_LSA_ERROR(dwError);
    
    fprintf(stdout, "The log level was set successfully\n\n");
    
    dwError = LsaGetLogInfo(
                    hLsaConnection,
                    &pLogInfo);
    BAIL_ON_LSA_ERROR(dwError);
    
    dwError = PrintLogInfo(pLogInfo);
    BAIL_ON_LSA_ERROR(dwError);

cleanup:

    if (pLogInfo)
    {
        LsaFreeLogInfo(pLogInfo);
    }
    
    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    return (dwError);

error:

    dwError = MapErrorCode(dwError);
    
    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);
    
    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;
        
        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);
        
        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);
            
            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr,
                        "Failed to set log level.  Error code %u (%s).\n%s\n",
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }
        
        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }
    
    if (bPrintOrigError)
    {
        fprintf(stderr,
                "Failed to set log level.  Error code %u (%s).\n",
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}
DWORD
LsaAddGroupMain(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    PSTR  pszGid = NULL;
    PSTR  pszGroup = NULL;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;

    if (geteuid() != 0) {
        fprintf(stderr, "This program requires super-user privileges.\n");
        dwError = LW_ERROR_ACCESS_DENIED;
        BAIL_ON_LSA_ERROR(dwError);
    }

    dwError = ParseArgs(
                    argc,
                    argv,
                    &pszGid,
                    &pszGroup);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = AddGroup(
                    pszGid,
                    pszGroup);
    BAIL_ON_LSA_ERROR(dwError);

    fprintf(stdout, "Successfully added group %s\n", pszGroup);

cleanup:

    LW_SAFE_FREE_STRING(pszGid);
    LW_SAFE_FREE_STRING(pszGroup);

    return dwError;

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr,
                        "Failed to add group.  Error code %u (%s).\n%s\n",
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(stderr,
                "Failed to add group.  Error code %u (%s).\n",
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}
Beispiel #11
0
int
get_metrics_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    DWORD dwInfoLevel = 0;
    PVOID pMetricPack = NULL;
    HANDLE hLsaConnection = (HANDLE)NULL;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;

    ParseArgs(argc, argv, &dwInfoLevel);

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaGetMetrics(
                    hLsaConnection,
                    dwInfoLevel,
                    &pMetricPack);
    BAIL_ON_LSA_ERROR(dwError);

    switch (dwInfoLevel)
    {
        case 0:

            PrintMetricPack_0(
                (PLSA_METRIC_PACK_0)pMetricPack);

            break;

        case 1:

            PrintMetricPack_1(
                 (PLSA_METRIC_PACK_1)pMetricPack);

            break;

    }

cleanup:

    LW_SAFE_FREE_MEMORY(pMetricPack);

    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    return (dwError);

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(
                    stderr,
                    "Failed to query metrics from LSA service.  Error code %u (%s).\n%s\n",
                    dwError,
                    LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                    pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(
            stderr,
            "Failed to query metrics from LSA service.  Error code %u (%s).\n",
            dwError,
            LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}
int
enum_groups_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    DWORD dwGroupInfoLevel = 0;
    DWORD dwBatchSize = 10;
    HANDLE hLsaConnection = (HANDLE)NULL;
    HANDLE hResume = (HANDLE)NULL;
    PVOID* ppGroupInfoList = NULL;
    DWORD  dwNumGroupsFound = 0;
    DWORD  dwTotalGroupsFound = 0;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = FALSE;
    BOOLEAN bCheckGroupMembersOnline = FALSE;

    dwError = ParseArgs(argc, argv, &dwGroupInfoLevel, &dwBatchSize, &bCheckGroupMembersOnline);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaBeginEnumGroupsWithCheckOnlineOption(
                    hLsaConnection,
                    dwGroupInfoLevel,
                    dwBatchSize,
                    bCheckGroupMembersOnline,
                    0,
                    &hResume);
    BAIL_ON_LSA_ERROR(dwError);

    do
    {
        DWORD iGroup = 0;

        if (ppGroupInfoList) {
           LsaFreeGroupInfoList(dwGroupInfoLevel, ppGroupInfoList, dwNumGroupsFound);
           ppGroupInfoList = NULL;
        }

        dwError = LsaEnumGroups(
                    hLsaConnection,
                    hResume,
                    &dwNumGroupsFound,
                    &ppGroupInfoList);
        BAIL_ON_LSA_ERROR(dwError);

        if (!dwNumGroupsFound) {
            break;
        }

        dwTotalGroupsFound+=dwNumGroupsFound;

        for (iGroup = 0; iGroup < dwNumGroupsFound; iGroup++)
        {
            PVOID pGroupInfo = *(ppGroupInfoList + iGroup);

            switch(dwGroupInfoLevel)
            {
                case 0:
                    PrintGroupInfo_0((PLSA_GROUP_INFO_0)pGroupInfo);
                    break;
                case 1:
                    PrintGroupInfo_1((PLSA_GROUP_INFO_1)pGroupInfo);
                    break;
                default:

                    fprintf(stderr,
                            "Error: Invalid Group info level %u\n",
                            dwGroupInfoLevel);
                    break;
            }
        }
    } while (dwNumGroupsFound);

    fprintf(stdout, "TotalNumGroupsFound: %u\n", dwTotalGroupsFound);

cleanup:

    if (ppGroupInfoList) {
       LsaFreeGroupInfoList(dwGroupInfoLevel, ppGroupInfoList, dwNumGroupsFound);
    }

    if ((hResume != (HANDLE)NULL) &&
        (hLsaConnection != (HANDLE)NULL)) {
        LsaEndEnumGroups(hLsaConnection, hResume);
    }

    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    return (dwError);

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr, "Failed to enumerate groups.  Error code %u (%s).\n"
                        "%s\n",
                        dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }

            if (dwError == ERROR_INVALID_DATA)
            {
                fprintf(stderr, "The groups list has changed while enumerating. "
                        "Try again.\n");
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(stderr, "Failed to enumerate groups.  Error code %u (%s).\n",
                dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}
Beispiel #13
0
int
main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;

    PSTR pszTargetFQDN = NULL;
    PSTR pszSiteName = NULL;
    PSTR pszPrimaryDomain = NULL;
    PLWNET_DC_INFO pDCInfo = NULL;
    DWORD dwFlags = 0;
    CHAR szErrorBuf[1024];
    
    INT i = 0;
    
    dwError = ParseArgs(
                argc,
                argv,
                &pszTargetFQDN,
                &pszSiteName,
                &pszPrimaryDomain,
                &dwFlags
                );
    BAIL_ON_LWNET_ERROR(dwError);

    lwnet_init_logging_to_file(LWNET_LOG_LEVEL_VERBOSE, TRUE, "");

    dwError = LWNetGetDCNameExt(
                NULL,
                pszTargetFQDN,
                pszSiteName,
                pszPrimaryDomain,
                dwFlags,
                0,
                NULL,
                &pDCInfo
                );
    BAIL_ON_LWNET_ERROR(dwError); 

    printf("Printing LWNET_DC_INFO fields:\n");
    printf("===============================\n");
    if(pDCInfo == NULL)
    {
        printf("<NULL>");
    }
    else
    {
        printf("dwDomainControllerAddressType = %u\n", pDCInfo->dwDomainControllerAddressType); 
        printf("dwFlags = %u\n", pDCInfo->dwFlags); 
        printf("dwVersion = %u\n", pDCInfo->dwVersion);       
        printf("wLMToken = %u\n", pDCInfo->wLMToken);  
        printf("wNTToken = %u\n", pDCInfo->wNTToken);
        
        safePrintString("pszDomainControllerName", pDCInfo->pszDomainControllerName);
        safePrintString("pszDomainControllerAddress", pDCInfo->pszDomainControllerAddress);
        
        printf("pucDomainGUID(hex) = ");
        for(i = 0; i < LWNET_GUID_SIZE; i++)
        {
            printf("%.2X ", pDCInfo->pucDomainGUID[i]);
        }
        printf("\n");
        
        safePrintString("pszNetBIOSDomainName", pDCInfo->pszNetBIOSDomainName);    
        safePrintString("pszFullyQualifiedDomainName", pDCInfo->pszFullyQualifiedDomainName);     
        safePrintString("pszDnsForestName", pDCInfo->pszDnsForestName);       
        safePrintString("pszDCSiteName", pDCInfo->pszDCSiteName);      
        safePrintString("pszClientSiteName", pDCInfo->pszClientSiteName); 
        safePrintString("pszNetBIOSHostName", pDCInfo->pszNetBIOSHostName);   
        safePrintString("pszUserName", pDCInfo->pszUserName);     
        
    }

error:
    if (dwError)
    {
        DWORD dwLen = LwGetErrorString(dwError, szErrorBuf, 1024);

        if (dwLen)
        {
            fprintf(
                 stderr,
                 "Failed communication with the LWNET Agent.  Error code %u (%s).\n%s\n",
                 dwError,
                 LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                 szErrorBuf);
        }
        else
        {
            fprintf(
                 stderr,
                 "Failed communication with the LWNET Agent.  Error code %u (%s).\n",
                 dwError,
                 LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
        }
    }

    LWNET_SAFE_FREE_DC_INFO(pDCInfo);
    LWNET_SAFE_FREE_STRING(pszTargetFQDN);
    LWNET_SAFE_FREE_STRING(pszSiteName);
    return dwError;
}
int
find_group_by_name_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    PSTR  pszGroupId = NULL;
    DWORD dwInfoLevel = 0;
    HANDLE hLsaConnection = (HANDLE)NULL;
    PVOID pGroupInfo = NULL;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;
    BOOLEAN bCountOnly = FALSE;
    LSA_FIND_FLAGS FindFlags = 0;

    dwError = ParseArgs(argc, argv, &pszGroupId, &FindFlags, &dwInfoLevel, &bCountOnly);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaFindGroupByName(
                    hLsaConnection,
                    pszGroupId,
                    FindFlags,
                    dwInfoLevel,
                    &pGroupInfo);
    BAIL_ON_LSA_ERROR(dwError);

    switch(dwInfoLevel)
    {
        case 0:
            PrintGroupInfo_0((PLSA_GROUP_INFO_0)pGroupInfo);
            break;
        case 1:
            PrintGroupInfo_1((PLSA_GROUP_INFO_1)pGroupInfo, bCountOnly);
            break;
        default:

            fprintf(stderr, "Error: Invalid group info level [%u]\n", dwInfoLevel);
            break;
    }

cleanup:

    if (pGroupInfo) {
       LsaFreeGroupInfo(dwInfoLevel, pGroupInfo);
    }

    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    LW_SAFE_FREE_STRING(pszGroupId);

    return (dwError);

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr,
                        "Failed to locate group.  Error code %u (%s).\n%s\n",
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(stderr,
                "Failed to locate group.  Error code %u (%s).\n",
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}
int
list_groups_for_user_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    HANDLE hLsaConnection = (HANDLE)NULL;
    PCSTR pszUserName = NULL;
    DWORD  dwNumGroups = 0;
    DWORD  iGroup = 0;
    LSA_FIND_FLAGS FindFlags = 0;
    DWORD dwGroupInfoLevel = 0;
    PVOID* ppGroupInfoList = NULL;
    DWORD dwId = 0;
    BOOLEAN bShowSid = FALSE;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;

    ParseArgs(argc, argv, &pszUserName, &dwId, &bShowSid);

    if (pszUserName)
    {
        dwError = LsaValidateUserName(pszUserName);
        BAIL_ON_LSA_ERROR(dwError);
    }

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    if (pszUserName)
    {
        dwError = LsaGetGroupsForUserByName(
                        hLsaConnection,
                        pszUserName,
                        FindFlags,
                        dwGroupInfoLevel,
                        &dwNumGroups,
                        &ppGroupInfoList);
        BAIL_ON_LSA_ERROR(dwError);
    }
    else
    {
        dwError = LsaGetGroupsForUserById(
                        hLsaConnection,
                        dwId,
                        FindFlags,
                        dwGroupInfoLevel,
                        &dwNumGroups,
                        &ppGroupInfoList);
        BAIL_ON_LSA_ERROR(dwError);
    }

    if (pszUserName)
    {
        printf("Number of groups found for user '%s' : %u\n", pszUserName, dwNumGroups);
    }
    else
    {
        printf("Number of groups found for uid %u : %u\n", dwId, dwNumGroups);
    }

    switch(dwGroupInfoLevel)
    {
        case 0:

            for (iGroup = 0; iGroup < dwNumGroups; iGroup++)
            {
                PLSA_GROUP_INFO_0* pGroupInfoList = (PLSA_GROUP_INFO_0*)ppGroupInfoList;

                if (bShowSid)
                {
                    fprintf(stdout,
                            "Group[%u of %u] name = %s (gid = %u, sid = %s)\n",
                            iGroup+1,
                            dwNumGroups,
                            pGroupInfoList[iGroup]->pszName,
                            (unsigned int) pGroupInfoList[iGroup]->gid,
                            pGroupInfoList[iGroup]->pszSid);
                }
                else
                {
                    fprintf(stdout,
                            "Group[%u of %u] name = %s (gid = %u)\n",
                            iGroup+1,
                            dwNumGroups,
                            pGroupInfoList[iGroup]->pszName,
                            (unsigned int) pGroupInfoList[iGroup]->gid);
                }
            }

            break;

        default:
            dwError = LW_ERROR_UNSUPPORTED_GROUP_LEVEL;
            BAIL_ON_LSA_ERROR(dwError);
            break;
    }

cleanup:

    if (ppGroupInfoList)
    {
        LsaFreeGroupInfoList(dwGroupInfoLevel, ppGroupInfoList, dwNumGroups);
    }

    if (hLsaConnection)
    {
        LsaCloseServer(hLsaConnection);
    }

    return (dwError);

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                if (pszUserName)
                {
                    fprintf(
                        stderr,
                        "Failed to find groups for user '%s'.  Error code %u (%s).\n%s\n",
                        pszUserName,
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                }
                else
                {
                    fprintf(
                        stderr,
                        "Failed to find groups for uid %u.  Error code %u (%s).\n%s\n",
                        dwId,
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                }
                bPrintOrigError = FALSE;
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        if (pszUserName)
        {
            fprintf(
                stderr,
                "Failed to find groups for user '%s'.  Error code %u (%s).\n",
                pszUserName,
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
        }
        else
        {
            fprintf(
                stderr,
                "Failed to find groups for uid %u.  Error code %u (%s).\n",
                dwId,
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
        }
    }

    goto cleanup;
}
Beispiel #16
0
int
enum_users_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    DWORD dwUserInfoLevel = 0;
    DWORD dwBatchSize = 10;
    HANDLE hLsaConnection = (HANDLE)NULL;
    HANDLE hResume = (HANDLE)NULL;
    PVOID* ppUserInfoList = NULL;
    DWORD  dwNumUsersFound = 0;
    DWORD  dwTotalUsersFound = 0;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;
    BOOLEAN bCheckUserInList = FALSE;

    dwError = ParseArgs(argc, argv, &dwUserInfoLevel, &dwBatchSize, &bCheckUserInList);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaBeginEnumUsers(
                    hLsaConnection,
                    dwUserInfoLevel,
                    dwBatchSize,
                    0,
                    &hResume);
    BAIL_ON_LSA_ERROR(dwError);

    do
    {
        DWORD iUser = 0;

        if (ppUserInfoList) {
           LsaFreeUserInfoList(dwUserInfoLevel, ppUserInfoList, dwNumUsersFound);
           ppUserInfoList = NULL;
        }

        dwError = LsaEnumUsers(
                    hLsaConnection,
                    hResume,
                    &dwNumUsersFound,
                    &ppUserInfoList);
        BAIL_ON_LSA_ERROR(dwError);

        if (!dwNumUsersFound) {
            break;
        }

        dwTotalUsersFound+=dwNumUsersFound;

        for (iUser = 0; iUser < dwNumUsersFound; iUser++)
        {
            BOOLEAN bAllowedLogon = TRUE;
            PVOID pUserInfo = *(ppUserInfoList + iUser);

            if (bCheckUserInList)
            {
                dwError = LsaCheckUserInList(
                                          hLsaConnection,
                                          ((PLSA_USER_INFO_0)pUserInfo)->pszName,
                                          NULL);
                if (dwError)
                {
                    bAllowedLogon = FALSE;
                }
            }

            switch(dwUserInfoLevel)
            {
                case 0:
                    PrintUserInfo_0((PLSA_USER_INFO_0)pUserInfo,
                                    bCheckUserInList,
                                    bAllowedLogon);
                    break;
                case 1:
                    PrintUserInfo_1((PLSA_USER_INFO_1)pUserInfo,
                                    bCheckUserInList,
                                    bAllowedLogon);
                    break;
                case 2:
                    PrintUserInfo_2((PLSA_USER_INFO_2)pUserInfo,
                                    bCheckUserInList,
                                    bAllowedLogon);
                    break;
                default:

                    fprintf(stderr,
                            "Error: Invalid user info level %u\n",
                            dwUserInfoLevel);
                    break;
            }
        }
    } while (dwNumUsersFound);

    fprintf(stdout, "TotalNumUsersFound: %u\n", dwTotalUsersFound);

cleanup:

    if (ppUserInfoList) {
       LsaFreeUserInfoList(dwUserInfoLevel, ppUserInfoList, dwNumUsersFound);
    }

    if ((hResume != (HANDLE)NULL) &&
        (hLsaConnection != (HANDLE)NULL)) {
        LsaEndEnumUsers(hLsaConnection, hResume);
    }

    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    return (dwError);

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr, "Failed to enumerate users.  Error code %u (%s).\n"
                        "%s\n",
                        dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }

            if (dwError == ERROR_INVALID_DATA)
            {
                fprintf(stderr, "The users list has changed while enumerating. "
                        "Try again.\n");
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(stderr, "Failed to enumerate users.  Error code %u (%s).\n",
                dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}
int
lw_ypcat_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    HANDLE hLsaConnection = (HANDLE)NULL;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;
    PSTR    pszMapName = NULL;
    PSTR    pszDomain = NULL;
    BOOLEAN bPrintKeys = FALSE;
    BOOLEAN bPrintNicknameTable = FALSE;
    BOOLEAN bUseNicknameTable = TRUE;
    PDLINKEDLIST pNISNicknameList = NULL;
    BOOLEAN bNoNicknameFile = FALSE;
    PCSTR   pszNicknameFilePath = "/var/yp/nicknames";
    BOOLEAN bCheckGroupMembersOnline = FALSE;
    BOOLEAN bIndexById = FALSE;

    dwError = ParseArgs(
                    argc,
                    argv,
                    &pszMapName,
                    &pszDomain,
                    &bPrintKeys,
                    &bPrintNicknameTable,
                    &bUseNicknameTable,
                    &bCheckGroupMembersOnline);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = LsaNISGetNicknames(
                    pszNicknameFilePath,
                    &pNISNicknameList);
    if (dwError == ENOENT)
    {
        bNoNicknameFile = TRUE;
        dwError = 0;
    }

    if (bPrintNicknameTable)
    {
        if (bNoNicknameFile)
        {
            printf("nickname file %s does not exist.\n", pszNicknameFilePath);
            goto cleanup;
        }

        if (pNISNicknameList)
        {
            PrintNicknameTable(pNISNicknameList);
        }

        goto cleanup;
    }

    if (bUseNicknameTable)
    {
        PCSTR pszLookupName = NULL;

        if (bNoNicknameFile)
        {
            printf("nickname file %s does not exist.\n", pszNicknameFilePath);
        }

        if (pNISNicknameList)
        {
            pszLookupName = LsaNISLookupAlias(
                                pNISNicknameList,
                                pszMapName);

            if (pszLookupName)
            {
                LW_SAFE_FREE_STRING(pszMapName);

                dwError = LwAllocateString(
                                pszLookupName,
                                &pszMapName);
                BAIL_ON_LSA_ERROR(dwError);
            }
        }
    }

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    if (!strcasecmp(pszMapName, "passwd.byname") ||
        !strcasecmp(pszMapName, "passwd"))
    {
        dwError = EnumerateUsers(hLsaConnection, bPrintKeys, bIndexById);
    }
    else if (!strcasecmp(pszMapName, "passwd.byid") ||
             !strcasecmp(pszMapName, "passwd.byuid"))
    {
        bIndexById = TRUE;

        dwError = EnumerateUsers(hLsaConnection, bPrintKeys, bIndexById);
    }
    else if (!strcasecmp(pszMapName, "group.byname") ||
             !strcasecmp(pszMapName, "group"))
    {
        dwError = EnumerateGroups(
                        hLsaConnection,
                        bCheckGroupMembersOnline,
                        bPrintKeys,
                        bIndexById);
    }
    else if (!strcasecmp(pszMapName, "group.byid") ||
             !strcasecmp(pszMapName, "group.bygid"))
    {
        bIndexById = TRUE;

        dwError = EnumerateGroups(
                        hLsaConnection,
                        bCheckGroupMembersOnline,
                        bPrintKeys,
                        bIndexById);
    }
    else
    {
        dwError = EnumerateMaps(
                        hLsaConnection,
                        pszMapName,
                        bPrintKeys);
    }
    BAIL_ON_LSA_ERROR(dwError);

cleanup:

    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    if (pNISNicknameList)
    {
        LsaNISFreeNicknameList(pNISNicknameList);
    }

    LW_SAFE_FREE_STRING(pszMapName);
    LW_SAFE_FREE_STRING(pszDomain);

    return (dwError);

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr,
                        "Failed to enumerate maps.  Error code %u (%s).\n%s\n",
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(stderr,
                "Failed to enumerate maps.  Error code %u (%s).\n",
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    dwError = 1;

    goto cleanup;
}
Beispiel #18
0
int
set_machine_sid_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    PSTR pszMachineSid = NULL;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;

    if (geteuid() != 0) {
        fprintf(stderr, "This program requires super-user privileges.\n");
        dwError = LW_ERROR_ACCESS_DENIED;
        BAIL_ON_LSA_ERROR(dwError);
    }

    dwError = ParseArgs(argc, argv,
                        &pszMachineSid);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = ValidateParameters(pszMachineSid);
    BAIL_ON_LSA_ERROR(dwError);

    dwError = SetMachineSid(pszMachineSid);
    BAIL_ON_LSA_ERROR(dwError);

cleanup:
    if (pszMachineSid) {
        LW_SAFE_FREE_STRING(pszMachineSid);
    }

    return dwError;

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR  pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                     dwErrorBufferSize,
                     (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = 0;

            dwLen = LwGetErrorString(dwError,
                                      pszErrorBuffer,
                                      dwErrorBufferSize);
            if ((dwLen == dwErrorBufferSize) &&
                !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(stderr,
                        "Failed to modify SID.  Error code %u (%s).\n%s\n",
                        dwError,
                        LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                        pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(stderr,
                "Failed to modify SID.  Error code %u (%s).\n",
                dwError,
                LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}
int
trace_info_main(
    int argc,
    char* argv[]
    )
{
    DWORD dwError = 0;
    HANDLE hLsaConnection = (HANDLE)NULL;
    DWORD dwTraceFlag = 0;
    PLSA_TRACE_INFO pTraceFlag = NULL;
    PLSA_TRACE_INFO pTraceFlagArray = NULL;
    DWORD dwNumFlags = 0;
    size_t dwErrorBufferSize = 0;
    BOOLEAN bPrintOrigError = TRUE;

    if (argc > 1)
    {
        dwError = ParseArgs(
                        argc,
                        argv,
                        &pTraceFlagArray,
                        &dwNumFlags,
                        &dwTraceFlag);
        BAIL_ON_LSA_ERROR(dwError);
    }

    if (pTraceFlagArray)
    {
        if (geteuid() != 0) {
            fprintf(stderr, "This program requires super-user privileges.\n");
            dwError = LW_ERROR_ACCESS_DENIED;
            BAIL_ON_LSA_ERROR(dwError);
        }
    }

    dwError = LsaOpenServer(&hLsaConnection);
    BAIL_ON_LSA_ERROR(dwError);

    if (pTraceFlagArray)
    {
        dwError = LsaSetTraceFlags(
                    hLsaConnection,
                    pTraceFlagArray,
                    dwNumFlags);
        BAIL_ON_LSA_ERROR(dwError);

        printf("The trace levels were set successfully\n\n");
    }

    if (dwTraceFlag)
    {
        dwError = LsaGetTraceFlag(
                    hLsaConnection,
                    dwTraceFlag,
                    &pTraceFlag);
        BAIL_ON_LSA_ERROR(dwError);

        dwError = PrintTraceInfo(pTraceFlag);
        BAIL_ON_LSA_ERROR(dwError);
    }

    if (dwTraceFlag && pTraceFlagArray)
    {
       DWORD iFlag = 0;

       dwError = LsaEnumTraceFlags(
                    hLsaConnection,
                    &pTraceFlagArray,
                    &dwNumFlags);
       BAIL_ON_LSA_ERROR(dwError);

       for(; iFlag < dwNumFlags; iFlag++)
       {
           PLSA_TRACE_INFO pInfo = &pTraceFlagArray[iFlag];

           dwError = PrintTraceInfo(pInfo);
           BAIL_ON_LSA_ERROR(dwError);
       }
    }

cleanup:

    if (hLsaConnection != (HANDLE)NULL) {
        LsaCloseServer(hLsaConnection);
    }

    LW_SAFE_FREE_MEMORY(pTraceFlag);
    LW_SAFE_FREE_MEMORY(pTraceFlagArray);

    return (dwError);

error:

    dwError = MapErrorCode(dwError);

    dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0);

    if (dwErrorBufferSize > 0)
    {
        DWORD dwError2 = 0;
        PSTR   pszErrorBuffer = NULL;

        dwError2 = LwAllocateMemory(
                    dwErrorBufferSize,
                    (PVOID*)&pszErrorBuffer);

        if (!dwError2)
        {
            DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize);

            if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
            {
                fprintf(
                    stderr,
                    "Failed to manage trace flags.  Error code %u (%s).\n%s\n",
                    dwError,
                    LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)),
                    pszErrorBuffer);
                bPrintOrigError = FALSE;
            }
        }

        LW_SAFE_FREE_STRING(pszErrorBuffer);
    }

    if (bPrintOrigError)
    {
        fprintf(
            stderr,
            "Failed to manage trace flags.  Error code %u (%s).\n",
            dwError,
            LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)));
    }

    goto cleanup;
}