コード例 #1
0
DWORD
LWNetGetErrorMessageForLoggingEvent(
    DWORD dwErrCode,
    PSTR* ppszErrorMsg
    )
{
    DWORD dwErrorBufferSize = 0;
    DWORD dwError = 0;
    DWORD dwLen = 0;
    PSTR  pszErrorMsg = NULL;
    PSTR  pszErrorBuffer = NULL;

    dwErrorBufferSize = LwGetErrorString(dwErrCode, NULL, 0);

    if (!dwErrorBufferSize)
        goto cleanup;

    dwError = LWNetAllocateMemory(
                dwErrorBufferSize,
                (PVOID*)&pszErrorBuffer);
    BAIL_ON_LWNET_ERROR(dwError);

    dwLen = LwGetErrorString(dwErrCode, pszErrorBuffer, dwErrorBufferSize);

    if ((dwLen == dwErrorBufferSize) && !IsNullOrEmptyString(pszErrorBuffer))
    {
        dwError = LwAllocateStringPrintf(
                     &pszErrorMsg,
                     "Error: %s [error code: %d]",
                     pszErrorBuffer,
                     dwErrCode);
        BAIL_ON_LWNET_ERROR(dwError);
    }

    *ppszErrorMsg = pszErrorMsg;

cleanup:

    LWNET_SAFE_FREE_STRING(pszErrorBuffer);

    return dwError;

error:

    LWNET_SAFE_FREE_STRING(pszErrorMsg);

    *ppszErrorMsg = NULL;

    goto cleanup;
}
コード例 #2
0
ファイル: conf2reg.c プロジェクト: twistround/pbis
static
DWORD
GetErrorMessage(
    DWORD dwErrCode,
    PSTR* ppszErrorMsg)
{
    DWORD dwError = 0;
    DWORD dwErrorBufferSize = 0;
    DWORD dwLen = 0;
    PSTR pszErrorMsg = NULL;
    PSTR pszErrorBuffer = NULL;

    dwErrorBufferSize = LwGetErrorString(dwErrCode, NULL, 0);

    if(!dwErrorBufferSize)
        goto cleanup;

    dwError = LwAllocateMemory(
                    dwErrorBufferSize,
                    OUT_PPVOID(&pszErrorBuffer));
    BAIL_ON_UP_ERROR(dwError);

    dwLen = LwGetErrorString(dwErrCode, pszErrorBuffer, dwErrorBufferSize);
    if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer))
    {
        dwError = LwAllocateStringPrintf(
                    &pszErrorMsg,
                    "Error: %s [error code: %d]", pszErrorBuffer,
                    dwErrCode);
        BAIL_ON_UP_ERROR(dwError);
    }

    *ppszErrorMsg = pszErrorMsg;

cleanup:
    LW_SAFE_FREE_MEMORY(pszErrorBuffer);

    return dwError;

error:
    LW_SAFE_FREE_STRING(pszErrorMsg);

    *ppszErrorMsg = NULL;

    goto cleanup;
}
コード例 #3
0
ファイル: common.c プロジェクト: borland667/pbis
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);
}
コード例 #4
0
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;
}
コード例 #5
0
ファイル: ad_cache_main.c プロジェクト: virtual-void/pbis
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;
}
コード例 #6
0
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;
}
コード例 #7
0
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;
}
コード例 #8
0
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;
}
コード例 #9
0
ファイル: enum_users_main.c プロジェクト: borland667/pbis
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;
}
コード例 #10
0
/*
 * FindUserByName1
 * 
 * Check that LsaFindUserByName gets LSA_USER_INFO_1 for given user.
 */
static
DWORD
FindUserByName1(
    HANDLE hLsaConnection,
    PLWTUSER pUser,
    PCSTR pszLookedUpBy,
    PLSA_USER_INFO_1 *ppUserInfo1
    )
{
    PCSTR pszTestDescription =
        "LsaFindUserByName retrieved LSA_USER_INFO_1 for given user.";
    PCSTR pszTestAPIs = 
        "LsaFindUserByName";
    char szTestMsg[128] = { 0 };
    DWORD dwError = LW_ERROR_SUCCESS;
    DWORD dwLocalError = LW_ERROR_SUCCESS;
    PLSA_USER_INFO_1 pUserInfo1 = NULL;

    snprintf( szTestMsg, 
              sizeof(szTestMsg), 
              "\n\tAccount %s.\n", 
              pszLookedUpBy);

    dwLocalError = LsaFindUserByName( hLsaConnection,
                                      pszLookedUpBy,
                                      1, 
                                      (PVOID*)&pUserInfo1);
    if ( dwLocalError )
    {
        char buf[128];
        char szErrorMsg[128];

        LwGetErrorString( dwLocalError, 
                          szErrorMsg, 
                          sizeof(szErrorMsg));

        snprintf( buf,
                  sizeof(buf),
                  "\tLsaFindUserByName reports %lu (%s)\n",
                  (unsigned long)dwLocalError,
                  szErrorMsg);

        Lwt_strcat(szTestMsg, sizeof(szTestMsg), buf);
        dwError = LW_ERROR_TEST_FAILED;
        goto error;
    }

cleanup:

    *ppUserInfo1 = pUserInfo1;

    LWT_LOG_TEST(szTestMsg);
    return dwError;

error:

    if ( pUserInfo1 )
    {
        LsaFreeUserInfo(1, pUserInfo1);
        pUserInfo1 = NULL;
    }

    goto cleanup;
}
コード例 #11
0
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;
}
コード例 #12
0
ファイル: main.c プロジェクト: FarazShaikh/LikewiseSMB2
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;
}
コード例 #13
0
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;
}
コード例 #14
0
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;
}
コード例 #15
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;
}
コード例 #16
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;
}
コード例 #17
0
ファイル: main.c プロジェクト: twistround/pbis
int
main(
    int argc,
    char** pArgv
    )
{
    DWORD dwError = 0;
    CHAR szErrorMessage[2048];
    int ret = 0;
    int i = 0;
    PCSTR pszErrorName = NULL;

    for (i = 1; i < argc; i++)
    {
        if (!strcmp(pArgv[i], "-h") ||
            !strcmp(pArgv[i], "--help"))
        {
            dwError = LwSmUsage(argc, pArgv);
            goto error;
        }
        if (!strcmp(pArgv[i], "-q") ||
            !strcmp(pArgv[i], "--quiet"))
        {
            gState.bQuiet = TRUE;
        }
        else if (!strcmp(pArgv[i], "list"))
        {
            dwError = LwSmList(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "start-only"))
        {
            dwError = LwSmStartOnly(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "start"))
        {
            dwError = LwSmStart(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "stop-only"))
        {
            dwError = LwSmStopOnly(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "stop"))
        {
            dwError = LwSmStop(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "info"))
        {
            dwError = LwSmInfo(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "status"))
        {
            dwError = LwSmStatus(argc-i, pArgv+i, &ret);
            goto error;
        }
        else if (!strcmp(pArgv[i], "refresh"))
        {
            dwError = LwSmDoRefresh(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "restart"))
        {
            dwError = LwSmRestart(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "proxy"))
        {
            dwError = LwSmProxy(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "gdb"))
        {
            dwError = LwSmGdb(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "set-log-target"))
        {
            dwError = LwSmSetLog(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "get-log"))
        {
            dwError = LwSmGetLog(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "set-log-level"))
        {
            dwError = LwSmCmdSetLogLevel(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "tap-log"))
        {
            dwError = LwSmCmdTapLog(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "autostart"))
        {
            dwError = LwSmAutostart(argc-i, pArgv+i);
            goto error;
        }
        else if (!strcmp(pArgv[i], "shutdown"))
        {
            dwError = LwSmShutdown();
            goto error;
        }
        else if (!strcmp(pArgv[i], "settings"))
        {
            dwError = LwSmCmdSettings();
            goto error;
        }
        else if (!strcmp(pArgv[i], "set"))
        {
            dwError = LwSmCmdSet(argc - 1, pArgv + 1);
            goto error;
        }
        else
        {
            dwError = LW_ERROR_INVALID_PARAMETER;
            BAIL_ON_ERROR(dwError);
        }
    }

    dwError = LwSmUsage(argc, pArgv);
    BAIL_ON_ERROR(dwError);

error:

    if (dwError)
    {
        memset(szErrorMessage, 0, sizeof(szErrorMessage));
        LwGetErrorString(dwError, szErrorMessage, sizeof(szErrorMessage) - 1);
        pszErrorName = LwWin32ExtErrorToName(dwError);

        if (!gState.bQuiet)
        {
            printf("Error: %s (%lu)\n", pszErrorName ? pszErrorName : "UNKNOWN", (unsigned long) dwError);
            printf("%s\n", szErrorMessage);
        }

        return 1;
    }
    else
    {
        return ret;
    }
}