void LWRaise( LWException** dest, DWORD code ) { DWORD ceError; char *shortMsg; char *longMsg; const char* desc = LwWin32ExtErrorToName(code); const char* help = LwWin32ExtErrorToDescription(code); if (!desc) { shortMsg = "Undocumented exception"; } if ((ceError = CTAllocateString(desc, &shortMsg))) { *dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL); return; } if (!help) { longMsg = "An undocumented exception has occurred. Please contact Likewise technical support and use the error code to identify this exception."; } if ((ceError = CTAllocateString(help, &longMsg))) { *dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL); return; } *dest = CreateException(code, NULL, 0, shortMsg, longMsg); }
DWORD NetShare( int argc, char ** argv ) { DWORD dwError = 0; PNET_SHARE_COMMAND_INFO pCommandInfo = NULL; dwError = NetShareParseArguments( argc, argv, &pCommandInfo ); BAIL_ON_LTNET_ERROR(dwError); dwError = NetShareInitialize(); BAIL_ON_LTNET_ERROR(dwError); switch (pCommandInfo->dwControlCode) { case NET_SHARE_ADD: dwError = NetExecShareAdd(pCommandInfo->ShareAddOrSetInfo); BAIL_ON_LTNET_ERROR(dwError); break; case NET_SHARE_DEL: dwError = NetExecShareDel(pCommandInfo->ShareDelInfo); BAIL_ON_LTNET_ERROR(dwError); break; case NET_SHARE_ENUM: dwError = NetExecShareEnum(pCommandInfo->ShareEnumInfo); BAIL_ON_LTNET_ERROR(dwError); break; case NET_SHARE_SETINFO: dwError = NetExecSetInfo(pCommandInfo->ShareAddOrSetInfo); BAIL_ON_LTNET_ERROR(dwError); break; default: break; } cleanup: NetShareFreeCommandInfo(pCommandInfo); LTNET_SAFE_FREE_MEMORY(pCommandInfo); pCommandInfo = NULL; return dwError; error: if (dwError) { fprintf(stderr, "%s\n", LwWin32ExtErrorToName(dwError)); } goto cleanup; }
int QueryMemberOfMain( int argc, char** ppszArgv ) { DWORD dwError = 0; dwError = ParseArguments(argc, ppszArgv); BAIL_ON_LSA_ERROR(dwError); if (gState.QueryType == LSA_QUERY_TYPE_UNDEFINED) { /* Default to querying by name */ gState.QueryType = LSA_QUERY_TYPE_BY_NAME; } if (!gState.bShowUsage) { if (!gState.dwCount) { dwError = LW_ERROR_INVALID_PARAMETER; BAIL_ON_LSA_ERROR(dwError); } dwError = QueryMemberOf(); BAIL_ON_LSA_ERROR(dwError); } error: if (gState.bShowUsage) { ShowUsage(ppszArgv[0], TRUE); } else if (dwError == LW_ERROR_INVALID_PARAMETER) { ShowUsage(ppszArgv[0], FALSE); } if (dwError) { printf("Error: %s (%x)\n", LwWin32ExtErrorToName(dwError), dwError); return 1; } else { return 0; } }
DWORD LWExceptionToString(const LWException *conv, PCSTR titlePrefix, BOOLEAN showSymbolicCode, BOOLEAN showTrace, PSTR *result) { DWORD ceError; PSTR ret = NULL; PSTR temp = NULL; PCSTR codeName = NULL; if(titlePrefix == NULL) titlePrefix = ""; if(showSymbolicCode) codeName = LwWin32ExtErrorToName(conv->code); if(codeName != NULL) { GCE(ceError = CTAllocateStringPrintf( &ret, "%s%s [%s]\n\n%s", titlePrefix, conv->shortMsg, codeName, conv->longMsg)); } else { GCE(ceError = CTAllocateStringPrintf( &ret, "%s%s [code 0x%.8x]\n\n%s", titlePrefix, conv->shortMsg, conv->code, conv->longMsg)); } if(showTrace) { const LWStackFrame *frame = &conv->stack; temp = ret; GCE(ceError = CTAllocateStringPrintf( &ret, "%s\n\nStack Trace:", temp)); CT_SAFE_FREE_STRING(temp); while(frame != NULL) { temp = ret; GCE(ceError = CTAllocateStringPrintf( &ret, "%s\n%s:%d", temp, frame->file, frame->line)); CT_SAFE_FREE_STRING(temp); frame = frame->down; } } *result = ret; ret = NULL; cleanup: CT_SAFE_FREE_STRING(temp); CT_SAFE_FREE_STRING(ret); return ceError; }
static PCSTR GetErrorString( IN DWORD dwError ) { PCSTR pszError = LwWin32ExtErrorToDescription(dwError); if (!pszError) { pszError = LwWin32ExtErrorToName(dwError); } if (!pszError) { pszError = "UNKNOWN"; } return pszError; }
int EnumObjectsMain( int argc, char** ppszArgv ) { DWORD dwError = 0; dwError = ParseArguments(argc, ppszArgv); BAIL_ON_LSA_ERROR(dwError); if (!gState.bShowUsage) { dwError = EnumObjects(); BAIL_ON_LSA_ERROR(dwError); } error: if (gState.bShowUsage) { ShowUsage(ppszArgv[0], TRUE); } else if (dwError == LW_ERROR_INVALID_PARAMETER) { ShowUsage(ppszArgv[0], FALSE); } if (dwError) { printf("Error: %s (%x)\n", LwWin32ExtErrorToName(dwError), dwError); return 1; } else { return 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); }
static DWORD LwSmDaemonize( VOID ) { DWORD dwError = 0; pid_t pid = -1; int ret = 0; int devNull = -1; int i = 0; /* Open a pipe so the daemon process can notify us when it is ready to accept connections. This means the foreground process will not exit until the daemon is fully usable */ if (pipe(gState.notifyPipe) != 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } pid = fork(); if (pid < 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } else if (pid > 0) { /* We are the foreground process */ /* Close the write end of the pipe since we don't need it */ close(gState.notifyPipe[1]); /* Wait until daemon process indicates it is fully started by sending error code */ do { ret = read(gState.notifyPipe[0], &dwError, sizeof(dwError)); } while (ret < 0 && errno == EINTR); if (dwError) { fprintf(stderr, "Error: %s (%d)\n", LwWin32ExtErrorToName(dwError), (int) dwError); } exit(dwError ? 1 : 0); } /* We are the intermediate background process. Isolate ourselves from the state of the foreground process by changing directory, becoming a session leader, redirecting stdout/stderr/stdin to /dev/null, and setting a reasonable umask */ if (chdir("/") != 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } if (setsid() < 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } if ((devNull = open("/dev/null", O_RDWR)) < 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } for (i = 0; i <= 2; i++) { if (dup2(devNull, i) < 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } } close(devNull); umask(0022); /* Now that we are isolated, fork the actual daemon process and exit */ pid = fork(); if (pid < 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } else if (pid > 0) { /* The intermediate background process exits here */ exit(0); } /* We are the actual daemon process, continue with startup */ /* Close the read end of the notification pipe now since we don't need it */ close(gState.notifyPipe[0]); /* Prevent the write end of the notification pipe from being inherited by children */ if (fcntl(gState.notifyPipe[1], F_SETFD, FD_CLOEXEC) < 0) { dwError = LwMapErrnoToLwError(errno); BAIL_ON_ERROR(dwError); } error: return dwError; }
int main( int argc, char** ppszArgv ) { DWORD dwError = 0; /* Parse command line */ dwError = LwSmParseArguments(argc, ppszArgv); BAIL_ON_ERROR(dwError); /* Block all signals */ dwError = LwNtStatusToWin32Error(LwRtlBlockSignals()); BAIL_ON_ERROR(dwError); /* Fork into background if running as a daemon */ if (gState.bStartAsDaemon) { dwError = LwSmDaemonize(); BAIL_ON_ERROR(dwError); } /* If we're starting as the control server, acquire lock */ if (!gState.bContainer) { dwError = LwSmControlLock(); BAIL_ON_ERROR(dwError); } /* Create thread pool */ dwError = LwNtStatusToWin32Error(LwRtlCreateThreadPool(&gpPool, NULL)); BAIL_ON_ERROR(dwError); dwError = LWNetExtendEnvironmentForKrb5Affinity(FALSE); BAIL_ON_ERROR(dwError); /* Mac OS X - avoid potential circular calls into directory services */ dwError = LwDsCacheAddPidException(getpid()); BAIL_ON_ERROR(dwError); /* Initialize i18n */ setlocale(LC_ALL, ""); /* Initialize logging subsystem */ LwSmLogInit(); /* Set up logging */ dwError = LwSmConfigureLogging(gState.pName); BAIL_ON_ERROR(dwError); /* Initialize the container subsystem */ dwError = LwSmContainerInit(); BAIL_ON_ERROR(dwError); /* Initialize the service table subsystem */ dwError = LwSmTableInit(); BAIL_ON_ERROR(dwError); /* Enter main loop */ dwError = LwSmMain(); BAIL_ON_ERROR(dwError); error: /* If we are starting as a daemon and have not notified the parent process yet, notify it of an error now */ if (gState.bStartAsDaemon && !gState.bNotified) { LwSmNotify(dwError); } /* Shut down service table */ LwSmTableShutdown(); /* Shut down containers */ LwSmContainerShutdown(); /* Shut down logging */ LwSmLoggingShutdown(); /* Remove DS cache exception */ LwDsCacheRemovePidException(getpid()); /* Free thread pool */ LwRtlFreeThreadPool(&gpPool); /* Close control file if it is open */ if (gState.ControlLock >= 0) { close(gState.ControlLock); } if (dwError) { fprintf(stderr, "Error: %s (%d)\n", LwWin32ExtErrorToName(dwError), (int) dwError); } return dwError ? 1 : 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; }
int main( int argc, char** ppszArgv ) { DWORD dwError = 0; DWORD dwIndex = 0; dwError = SrvSvcInitMemory(); BAIL_ON_SRVSVC_ERROR(dwError); if (argc < 2) { Usage(); return 1; } for (dwIndex = 1; dwIndex < argc; dwIndex++) { if (!strcasecmp(ppszArgv[dwIndex], "--server")) { dwError = LwMbsToWc16s(ppszArgv[++dwIndex], &gState.pwszServerName); BAIL_ON_SRVSVC_ERROR(dwError); } else if (!strcasecmp(ppszArgv[dwIndex], "--help")) { Help(); return 1; } else if (!strcasecmp(ppszArgv[dwIndex], "--usage")) { Help(); return 1; } else if (!strcasecmp(ppszArgv[dwIndex], "enum")) { dwError = Enum(argc - dwIndex, ppszArgv + dwIndex); BAIL_ON_SRVSVC_ERROR(dwError); break; } else if (!strcasecmp(ppszArgv[dwIndex], "enum-info")) { dwError = EnumInfo(argc - dwIndex, ppszArgv + dwIndex); BAIL_ON_SRVSVC_ERROR(dwError); break; } else if (!strcasecmp(ppszArgv[dwIndex], "get-info")) { dwError = GetInfo(argc - dwIndex, ppszArgv + dwIndex); BAIL_ON_SRVSVC_ERROR(dwError); break; } else if (!strcasecmp(ppszArgv[dwIndex], "set-info")) { dwError = SetInfo(argc - dwIndex, ppszArgv + dwIndex); BAIL_ON_SRVSVC_ERROR(dwError); break; } else if (!strcasecmp(ppszArgv[dwIndex], "add")) { dwError = Add(argc - dwIndex, ppszArgv + dwIndex); BAIL_ON_SRVSVC_ERROR(dwError); break; } else if (!strcasecmp(ppszArgv[dwIndex], "del")) { dwError = Del(argc - dwIndex, ppszArgv + dwIndex); BAIL_ON_SRVSVC_ERROR(dwError); break; } else { Usage(); return 1; } } error: if (dwError) { fprintf(stderr, "%s\n", LwWin32ExtErrorToName(dwError)); return 1; } else { return 0; } }
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; } }
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 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; }
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 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; }
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 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; }
PVOID UmnSrvPollerThreadRoutine( IN PVOID pUnused ) { DWORD dwError = 0; struct timeval now; struct timespec periodStart, periodUsed, nextWake, pushWait = {0}; DWORD dwPeriodSecs = 0; char regErrMsg[256] = {0}; char fqdn[1024] = {0}; BOOLEAN bMutexLocked = FALSE; UMN_LOG_INFO("User poller thread started"); dwError = pthread_mutex_lock(&gSignalPollerMutex); BAIL_ON_UMN_ERROR(dwError); bMutexLocked = TRUE; dwError = UmnSrvNow(&periodStart, &now); BAIL_ON_UMN_ERROR(dwError); while (!gbPollerThreadShouldExit) { dwError = UmnSrvGetCheckInterval(&dwPeriodSecs); BAIL_ON_UMN_ERROR(dwError); pushWait.tv_sec = dwPeriodSecs; UmnSrvTimespecAdd( &nextWake, &periodStart, &pushWait); UMN_LOG_INFO("User poller sleeping for %f seconds", pushWait.tv_sec + pushWait.tv_nsec / (double)NANOSECS_PER_SECOND); while (!gbPollerThreadShouldExit && !gbPollerRefresh) { BOOLEAN bWaitElapsed = FALSE; dwError = pthread_cond_timedwait( &gSignalPoller, &gSignalPollerMutex, &nextWake); if (dwError == EINTR) { UMN_LOG_DEBUG("User poller cond wait interrupted; continuing."); continue; } if (dwError == ETIMEDOUT) { UMN_LOG_DEBUG("User poller cond wait completed."); dwError = 0; break; } if (dwError != 0) { UMN_LOG_ERROR("Timed wait error: error %s (%d).", ErrnoToName(dwError), dwError); BAIL_ON_UMN_ERROR(dwError); } dwError = UmnSrvTimespecElapsed(&nextWake, &bWaitElapsed); if (dwError == 0 && bWaitElapsed == TRUE) { break; } } gbPollerRefresh = FALSE; if (!gbPollerThreadShouldExit) { dwError = UmnSrvNow(&periodStart, &now); BAIL_ON_UMN_ERROR(dwError); // obtain the fully qualified domain name and use it throughout this iteration UmnEvtFreeEventComputerName(); UmnEvtGetFQDN(fqdn, sizeof(fqdn)); UmnEvtSetEventComputerName(fqdn); dwError = UmnSrvUpdateAccountInfo(now.tv_sec); if (dwError == ERROR_CANCELLED) { UMN_LOG_INFO("User poller cancelled iteration"); dwError = 0; break; } // simply log other errors and attempt to continue if (dwError != LW_ERROR_SUCCESS) { if (LwRegIsRegistrySpecificError(dwError)) { LwRegGetErrorString(dwError, regErrMsg, sizeof(regErrMsg) - 1); UMN_LOG_ERROR("Failed updating account info, registry error = %d %s. Continuing.", dwError, regErrMsg); } else { UMN_LOG_ERROR("Failed updating account info, error = %d symbol = %s %s. Continuing.", dwError, LwWin32ExtErrorToName(dwError), LwWin32ExtErrorToDescription(dwError)); } dwError = 0; } // periodUsed = now - periodStart dwError = UmnSrvNow(&periodUsed, &now); BAIL_ON_UMN_ERROR(dwError); UmnSrvTimespecSubtract( &periodUsed, &periodUsed, &periodStart); UMN_LOG_DEBUG("Account activity update took %f seconds", periodUsed.tv_sec + periodUsed.tv_nsec / (double)NANOSECS_PER_SECOND); } } UMN_LOG_INFO("User poller thread stopped"); cleanup: if (bMutexLocked) { pthread_mutex_unlock(&gSignalPollerMutex); } if (dwError != 0) { UMN_LOG_ERROR( "User monitor polling thread exiting with code %d", dwError); kill(getpid(), SIGTERM); } return NULL; error: goto cleanup; }
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 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; }
void LWRaiseEx( LWException** dest, DWORD code, const char* file, unsigned int line, const char* _shortMsg, const char* fmt, ... ) { if (dest) { DWORD ceError; char* shortMsg; char* longMsg; va_list ap; va_start(ap, fmt); if (!_shortMsg) { _shortMsg = LwWin32ExtErrorToName(code); } if (!_shortMsg) { _shortMsg = "Undocumented exception"; } if (!fmt) { fmt = LwWin32ExtErrorToDescription(code); } if (!fmt) { fmt = "An undocumented exception has occurred. Please contact Likewise technical support and use the error code to identify this exception."; } if (_shortMsg) { if ((ceError = CTAllocateString(_shortMsg, &shortMsg))) { *dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL); return; } } else { shortMsg = NULL; } if (fmt) { if ((ceError = CTAllocateStringPrintfV(&longMsg, fmt, ap))) { CTFreeString(shortMsg); *dest = CreateException(ceError, __FILE__, __LINE__, NULL, NULL); return; } } else { longMsg = NULL; } *dest = CreateException(code, file, line, shortMsg, longMsg); } }
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; }
DWORD LwSmBootstrap( VOID ) { DWORD dwError = 0; PLW_SERVICE_INFO pInfo = NULL; PSM_BOOTSTRAP_SERVICE pService = NULL; PSM_TABLE_ENTRY pEntry = NULL; size_t i = 0; size_t j = 0; size_t len = 0; SM_LOG_VERBOSE("Bootstrapping"); for (i = 0; gBootstrapServices[i]; i++) { pService = gBootstrapServices[i]; dwError = LwAllocateMemory(sizeof(*pInfo), OUT_PPVOID(&pInfo)); BAIL_ON_ERROR(dwError); pInfo->type = pService->type; pInfo->bAutostart = 0; dwError = LwMbsToWc16s(pService->pszName, &pInfo->pwszName); BAIL_ON_ERROR(dwError); dwError = LwMbsToWc16s(pService->pszPath, &pInfo->pwszPath); BAIL_ON_ERROR(dwError); #ifdef SERVICE_DIRECT dwError = LwMbsToWc16s("direct", &pInfo->pwszGroup); #else dwError = LwMbsToWc16s(pService->pszName, &pInfo->pwszGroup); #endif BAIL_ON_ERROR(dwError); dwError = LwMbsToWc16s("Bootstrap service", &pInfo->pwszDescription); BAIL_ON_ERROR(dwError); for (len = 0; pService->ppszArgs[len]; len++); dwError = LwAllocateMemory( (len + 1) * sizeof(*pInfo->ppwszArgs), OUT_PPVOID(&pInfo->ppwszArgs)); BAIL_ON_ERROR(dwError); for (j = 0; j < len; j++) { dwError = LwMbsToWc16s(pService->ppszArgs[j], &pInfo->ppwszArgs[j]); BAIL_ON_ERROR(dwError); } /* Create empty Env list. */ dwError = LwAllocateMemory( 1 * sizeof(*pInfo->ppwszEnv), OUT_PPVOID(&pInfo->ppwszEnv)); BAIL_ON_ERROR(dwError); pInfo->ppwszEnv[0] = NULL; dwError = LwAllocateMemory( 1 * sizeof(*pInfo->ppwszDependencies), OUT_PPVOID(&pInfo->ppwszDependencies)); BAIL_ON_ERROR(dwError); dwError = LwSmTableAddEntry(pInfo, &pEntry); BAIL_ON_ERROR(dwError); dwError = LwSmTableStartEntry(pEntry); if (dwError) { SM_LOG_ERROR("Could not start bootstrap service: %s", LwWin32ExtErrorToName(dwError)); } BAIL_ON_ERROR(dwError); LwSmTableReleaseEntry(pEntry); pEntry = NULL; LwSmCommonFreeServiceInfo(pInfo); pInfo = NULL; } cleanup: if (pEntry) { LwSmTableReleaseEntry(pEntry); } if (pInfo) { LwSmCommonFreeServiceInfo(pInfo); } return dwError; error: goto cleanup; }
static DWORD LsaPstorepCallPlugin( IN PCSTR Operation, IN LSA_PSTORE_CALL_PLUGIN_CALLBACK Callback, IN PLSA_PSTORE_CALL_PLUGIN_ARGS Arguments ) { DWORD dwError = 0; int EE = 0; LSA_PSTORE_PLUGIN_INFO pluginInfo = { 0 }; PSTR* pluginNames = 0; DWORD pluginCount = 0; DWORD i = 0; PCSTR method = NULL; dwError = LsaPstorepGetPluginNames(&pluginNames, &pluginCount); GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE); for (i = 0; i < pluginCount; i++) { LsaPstorepCleanupPlugin(&pluginInfo); dwError = LsaPstorepInitializePlugin(&pluginInfo, pluginNames[i]); if (dwError) { LW_RTL_LOG_ERROR("Failed to load plugin %s with error = %u (%s)", pluginNames[i], dwError, LW_RTL_LOG_SAFE_STRING(LwWin32ExtErrorToName(dwError))); dwError = 0; continue; } dwError = Callback( pluginInfo.Name, pluginInfo.Dispatch, pluginInfo.Context, Arguments, &method); if (dwError) { if (method) { LW_RTL_LOG_ERROR( "Failed %s operation on plugin %s " "while calling %s method with error = %u (%s)", LW_RTL_LOG_SAFE_STRING(Operation), pluginNames[i], method, dwError, LW_RTL_LOG_SAFE_STRING(LwWin32ExtErrorToName(dwError))); } else { LW_RTL_LOG_ERROR( "Failed %s operation on plugin %s " "with error = %u (%s)", LW_RTL_LOG_SAFE_STRING(Operation), pluginNames[i], dwError, LW_RTL_LOG_SAFE_STRING(LwWin32ExtErrorToName(dwError))); } dwError = 0; continue; } } cleanup: LsaPstorepCleanupPlugin(&pluginInfo); LSA_PSTORE_FREE_STRING_ARRAY_A(&pluginNames, &pluginCount); LSA_PSTORE_LOG_LEAVE_ERROR_EE(dwError, EE); return dwError; }
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; }
DWORD LsaSrvInitAuthProviders( IN OPTIONAL PLSA_STATIC_PROVIDER pStaticProviders ) { DWORD dwError = 0; PLSA_AUTH_PROVIDER pUninitializedProviderList = NULL; PLSA_AUTH_PROVIDER pProviderList = NULL; PLSA_AUTH_PROVIDER pProvider = NULL; BOOLEAN bInLock = FALSE; dwError = LsaSrvAuthProviderAllocateProviderList( &pUninitializedProviderList); BAIL_ON_LSA_ERROR(dwError); while(pUninitializedProviderList) { pProvider = pUninitializedProviderList; pUninitializedProviderList = pUninitializedProviderList->pNext; pProvider->pNext = NULL; dwError = LsaSrvInitAuthProvider(pProvider, pStaticProviders); if (dwError) { LSA_LOG_ERROR("Failed to load provider '%s' from '%s' - error %u (%s)", LSA_SAFE_LOG_STRING(pProvider->pszId), LSA_SAFE_LOG_STRING(pProvider->pszProviderLibpath), dwError, LwWin32ExtErrorToName(dwError)); LsaSrvFreeAuthProvider(pProvider); pProvider = NULL; dwError = 0; } else { LsaSrvAppendAuthProviderList(&pProviderList, pProvider); pProvider = NULL; } } ENTER_AUTH_PROVIDER_LIST_WRITER_LOCK(bInLock); LsaSrvFreeAuthProviderList(gpAuthProviderList); gpAuthProviderList = pProviderList; pProviderList = NULL; LEAVE_AUTH_PROVIDER_LIST_WRITER_LOCK(bInLock); cleanup: if (pUninitializedProviderList) { LsaSrvFreeAuthProviderList(pUninitializedProviderList); } return dwError; error: if (pProviderList) { LsaSrvFreeAuthProviderList(pProviderList); } goto cleanup; }
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; }