void PrintCertificateDetails(CCertificateInfo* aCertInfo) { std::cout << "Certificate: " << std::endl; PrintWithIndent(std::cout, "Data:", 4); std::cout << std::endl; int version = aCertInfo->Version(); PrintWithIndent(std::cout, "Version: ", 8); std::cout << version+1 << "(0x" << version << ")" << std::endl; PrintWithIndent(std::cout, "Serial Number: ", 8); std::cout << aCertInfo->SerialNumber(); std::cout << std::endl; PrintWithIndent(std::cout, "Signature Algorithm: ", 8); std::cout << aCertInfo->SignatureAlgo() << std::endl; PrintWithIndent(std::wcout, L"Issuer: ", 8); std::wcout << aCertInfo->IssuerName(true) << std::endl; PrintWithIndent(std::cout, "Validity", 8); std::cout << std::endl; PrintWithIndent(std::cout, "Not Before: ", 12); PrintDateTime(aCertInfo->ValidFrom()); std::cout << std::endl; PrintWithIndent(std::cout, "Not After : ", 12); PrintDateTime(aCertInfo->ValidTo()); std::cout << std::endl; PrintWithIndent(std::wcout, L"Subject: ", 8); std::wcout << aCertInfo->SubjectName(true) << std::endl; PrintWithIndent(std::cout, "Subject Public Key Info:", 8); std::cout << std::endl; PrintWithIndent(std::cout, "Public Key Algorithm: ", 12); std::cout << aCertInfo->PublicKeyAlgo() << std::endl; aCertInfo->PrintPublicKey(std::cout, 16); const std::vector<TExtension>& extList = aCertInfo->Extensions(); PrintExtensions(extList, 8); aCertInfo->PrintSignature(std::cout, 12); }
/* * Display the local time. * * The value is constantly updated until the user presses a key. */ static void DisplayLocalTime(void) { time_t tt; struct _tm *ltm; uint_fast8_t i = 0; while (!kbhit()) { /* Get local time and print it. */ tt = time(NULL); ltm = localtime(&tt); printf(" [%c] Local time: ", rotor[++i & 3]); PrintDateTime(ltm); /* Calculate the offset from UTC in minutes. */ tt = _timezone; if (ltm->tm_isdst > 0) { tt += _dstbias; } tt /= -60L; /* Print UTC offset in format HH:MM. */ printf(" UTC%+03ld:%02ld \r", tt / 60L, abs(tt) % 60L); NutSleep(200); } putchar('\n'); }
/* * Display the coordinated universal time. * * The value is constantly updated until the user presses a key. */ static void DisplayZuluTime(void) { time_t secs; struct _tm *gmt; uint_fast8_t i = 0; while (!kbhit()) { secs = time(NULL); gmt = gmtime(&secs); printf(" [%c] Universal time: ", rotor[++i & 3]); PrintDateTime(gmt); printf(" \r"); NutSleep(500); } putchar('\n'); }
static NET_API_STATUS DisplayUser(LPWSTR lpUserName) { PUSER_MODALS_INFO_0 pUserModals = NULL; PUSER_INFO_4 pUserInfo = NULL; PLOCALGROUP_USERS_INFO_0 pLocalGroupInfo = NULL; PGROUP_USERS_INFO_0 pGroupInfo = NULL; DWORD dwLocalGroupRead, dwLocalGroupTotal; DWORD dwGroupRead, dwGroupTotal; DWORD dwLastSet; DWORD i; INT nPaddedLength = 29; NET_API_STATUS Status; /* Modify the user */ Status = NetUserGetInfo(NULL, lpUserName, 4, (LPBYTE*)&pUserInfo); if (Status != NERR_Success) return Status; Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&pUserModals); if (Status != NERR_Success) goto done; Status = NetUserGetLocalGroups(NULL, lpUserName, 0, 0, (LPBYTE*)&pLocalGroupInfo, MAX_PREFERRED_LENGTH, &dwLocalGroupRead, &dwLocalGroupTotal); if (Status != NERR_Success) goto done; Status = NetUserGetGroups(NULL, lpUserName, 0, (LPBYTE*)&pGroupInfo, MAX_PREFERRED_LENGTH, &dwGroupRead, &dwGroupTotal); if (Status != NERR_Success) goto done; PrintPaddedResourceString(IDS_USER_NAME, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_name); PrintPaddedResourceString(IDS_USER_FULL_NAME, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_full_name); PrintPaddedResourceString(IDS_USER_COMMENT, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_comment); PrintPaddedResourceString(IDS_USER_USER_COMMENT, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_usr_comment); PrintPaddedResourceString(IDS_USER_COUNTRY_CODE, nPaddedLength); ConPrintf(StdOut, L"%03ld ()\n", pUserInfo->usri4_country_code); PrintPaddedResourceString(IDS_USER_ACCOUNT_ACTIVE, nPaddedLength); if (pUserInfo->usri4_flags & UF_ACCOUNTDISABLE) ConResPuts(StdOut, IDS_GENERIC_NO); else if (pUserInfo->usri4_flags & UF_LOCKOUT) ConResPuts(StdOut, IDS_GENERIC_LOCKED); else ConResPuts(StdOut, IDS_GENERIC_YES); ConPuts(StdOut, L"\n"); PrintPaddedResourceString(IDS_USER_ACCOUNT_EXPIRES, nPaddedLength); if (pUserInfo->usri4_acct_expires == TIMEQ_FOREVER) ConResPuts(StdOut, IDS_GENERIC_NEVER); else PrintDateTime(pUserInfo->usri4_acct_expires); ConPuts(StdOut, L"\n\n"); PrintPaddedResourceString(IDS_USER_PW_LAST_SET, nPaddedLength); dwLastSet = GetTimeInSeconds() - pUserInfo->usri4_password_age; PrintDateTime(dwLastSet); PrintPaddedResourceString(IDS_USER_PW_EXPIRES, nPaddedLength); if ((pUserInfo->usri4_flags & UF_DONT_EXPIRE_PASSWD) || pUserModals->usrmod0_max_passwd_age == TIMEQ_FOREVER) ConResPuts(StdOut, IDS_GENERIC_NEVER); else PrintDateTime(dwLastSet + pUserModals->usrmod0_max_passwd_age); ConPuts(StdOut, L"\n"); PrintPaddedResourceString(IDS_USER_PW_CHANGEABLE, nPaddedLength); PrintDateTime(dwLastSet + pUserModals->usrmod0_min_passwd_age); PrintPaddedResourceString(IDS_USER_PW_REQUIRED, nPaddedLength); ConResPuts(StdOut, (pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? IDS_GENERIC_NO : IDS_GENERIC_YES); ConPuts(StdOut, L"\n"); PrintPaddedResourceString(IDS_USER_CHANGE_PW, nPaddedLength); ConResPuts(StdOut, (pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? IDS_GENERIC_NO : IDS_GENERIC_YES); ConPuts(StdOut, L"\n\n"); PrintPaddedResourceString(IDS_USER_WORKSTATIONS, nPaddedLength); if (pUserInfo->usri4_workstations == NULL || wcslen(pUserInfo->usri4_workstations) == 0) ConResPuts(StdOut, IDS_GENERIC_ALL); else ConPrintf(StdOut, L"%s", pUserInfo->usri4_workstations); ConPuts(StdOut, L"\n"); PrintPaddedResourceString(IDS_USER_LOGON_SCRIPT, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_script_path); PrintPaddedResourceString(IDS_USER_PROFILE, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_profile); PrintPaddedResourceString(IDS_USER_HOME_DIR, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_home_dir); PrintPaddedResourceString(IDS_USER_LAST_LOGON, nPaddedLength); if (pUserInfo->usri4_last_logon == 0) ConResPuts(StdOut, IDS_GENERIC_NEVER); else PrintDateTime(pUserInfo->usri4_last_logon); ConPuts(StdOut, L"\n\n"); PrintPaddedResourceString(IDS_USER_LOGON_HOURS, nPaddedLength); if (pUserInfo->usri4_logon_hours == NULL) ConResPuts(StdOut, IDS_GENERIC_ALL); ConPuts(StdOut, L"\n\n"); ConPuts(StdOut, L"\n"); PrintPaddedResourceString(IDS_USER_LOCAL_GROUPS, nPaddedLength); if (dwLocalGroupTotal != 0 && pLocalGroupInfo != NULL) { for (i = 0; i < dwLocalGroupTotal; i++) { if (i != 0) PrintPadding(L' ', nPaddedLength); ConPrintf(StdOut, L"*%s\n", pLocalGroupInfo[i].lgrui0_name); } } else { ConPuts(StdOut, L"\n"); } PrintPaddedResourceString(IDS_USER_GLOBAL_GROUPS, nPaddedLength); if (dwGroupTotal != 0 && pGroupInfo != NULL) { for (i = 0; i < dwGroupTotal; i++) { if (i != 0) PrintPadding(L' ', nPaddedLength); ConPrintf(StdOut, L"*%s\n", pGroupInfo[i].grui0_name); } } else { ConPuts(StdOut, L"\n"); } done: if (pGroupInfo != NULL) NetApiBufferFree(pGroupInfo); if (pLocalGroupInfo != NULL) NetApiBufferFree(pLocalGroupInfo); if (pUserModals != NULL) NetApiBufferFree(pUserModals); if (pUserInfo != NULL) NetApiBufferFree(pUserInfo); return NERR_Success; }
static NET_API_STATUS DisplayUser(LPWSTR lpUserName) { PUSER_MODALS_INFO_0 pUserModals = NULL; PUSER_INFO_4 pUserInfo = NULL; PLOCALGROUP_USERS_INFO_0 pLocalGroupInfo = NULL; PGROUP_USERS_INFO_0 pGroupInfo = NULL; DWORD dwLocalGroupRead, dwLocalGroupTotal; DWORD dwGroupRead, dwGroupTotal; DWORD dwLastSet; DWORD i; WCHAR szCountry[40]; INT nPaddedLength = 36; NET_API_STATUS Status; /* Modify the user */ Status = NetUserGetInfo(NULL, lpUserName, 4, (LPBYTE*)&pUserInfo); if (Status != NERR_Success) return Status; Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&pUserModals); if (Status != NERR_Success) goto done; Status = NetUserGetLocalGroups(NULL, lpUserName, 0, 0, (LPBYTE*)&pLocalGroupInfo, MAX_PREFERRED_LENGTH, &dwLocalGroupRead, &dwLocalGroupTotal); if (Status != NERR_Success) goto done; Status = NetUserGetGroups(NULL, lpUserName, 0, (LPBYTE*)&pGroupInfo, MAX_PREFERRED_LENGTH, &dwGroupRead, &dwGroupTotal); if (Status != NERR_Success) goto done; PrintPaddedMessageString(4411, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_name); PrintPaddedMessageString(4412, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_full_name); PrintPaddedMessageString(4413, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_comment); PrintPaddedMessageString(4414, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_usr_comment); PrintPaddedMessageString(4416, nPaddedLength); GetCountryFromCountryCode(pUserInfo->usri4_country_code, ARRAYSIZE(szCountry), szCountry); ConPrintf(StdOut, L"%03ld (%s)\n", pUserInfo->usri4_country_code, szCountry); PrintPaddedMessageString(4419, nPaddedLength); if (pUserInfo->usri4_flags & UF_ACCOUNTDISABLE) PrintMessageString(4301); else if (pUserInfo->usri4_flags & UF_LOCKOUT) PrintMessageString(4440); else PrintMessageString(4300); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4420, nPaddedLength); if (pUserInfo->usri4_acct_expires == TIMEQ_FOREVER) PrintMessageString(4305); else PrintDateTime(pUserInfo->usri4_acct_expires); ConPuts(StdOut, L"\n\n"); PrintPaddedMessageString(4421, nPaddedLength); dwLastSet = GetTimeInSeconds() - pUserInfo->usri4_password_age; PrintDateTime(dwLastSet); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4422, nPaddedLength); if ((pUserInfo->usri4_flags & UF_DONT_EXPIRE_PASSWD) || pUserModals->usrmod0_max_passwd_age == TIMEQ_FOREVER) PrintMessageString(4305); else PrintDateTime(dwLastSet + pUserModals->usrmod0_max_passwd_age); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4423, nPaddedLength); PrintDateTime(dwLastSet + pUserModals->usrmod0_min_passwd_age); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4437, nPaddedLength); PrintMessageString((pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? 4301 : 4300); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4438, nPaddedLength); PrintMessageString((pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? 4301 : 4300); ConPuts(StdOut, L"\n\n"); PrintPaddedMessageString(4424, nPaddedLength); if (pUserInfo->usri4_workstations == NULL || wcslen(pUserInfo->usri4_workstations) == 0) PrintMessageString(4302); else ConPrintf(StdOut, L"%s", pUserInfo->usri4_workstations); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4429, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_script_path); PrintPaddedMessageString(4439, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_profile); PrintPaddedMessageString(4436, nPaddedLength); ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_home_dir); PrintPaddedMessageString(4430, nPaddedLength); if (pUserInfo->usri4_last_logon == 0) PrintMessageString(4305); else PrintDateTime(pUserInfo->usri4_last_logon); ConPuts(StdOut, L"\n\n"); PrintPaddedMessageString(4432, nPaddedLength); if (pUserInfo->usri4_logon_hours == NULL) PrintMessageString(4302); ConPuts(StdOut, L"\n\n"); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4427, nPaddedLength); if (dwLocalGroupTotal != 0 && pLocalGroupInfo != NULL) { for (i = 0; i < dwLocalGroupTotal; i++) { if (i != 0) PrintPadding(L' ', nPaddedLength); ConPrintf(StdOut, L"*%s\n", pLocalGroupInfo[i].lgrui0_name); } } else { ConPuts(StdOut, L"\n"); } PrintPaddedMessageString(4431, nPaddedLength); if (dwGroupTotal != 0 && pGroupInfo != NULL) { for (i = 0; i < dwGroupTotal; i++) { if (i != 0) PrintPadding(L' ', nPaddedLength); ConPrintf(StdOut, L"*%s\n", pGroupInfo[i].grui0_name); } } else { ConPuts(StdOut, L"\n"); } done: if (pGroupInfo != NULL) NetApiBufferFree(pGroupInfo); if (pLocalGroupInfo != NULL) NetApiBufferFree(pLocalGroupInfo); if (pUserModals != NULL) NetApiBufferFree(pUserModals); if (pUserInfo != NULL) NetApiBufferFree(pUserInfo); return NERR_Success; }