BOOL active_main(INT argc, LPWSTR *argv) { ConPuts(StdOut, L"\nActive\n"); return TRUE; }
INT unimplemented(INT argc, WCHAR **argv) { ConPuts(StdOut, L"This command is not implemented yet\n"); return 1; }
VOID ConErrResPuts(UINT resID) { TCHAR szMsg[RC_STRING_MAX_SIZE]; LoadString(CMD_ModuleHandle, resID, szMsg, RC_STRING_MAX_SIZE); ConPuts(szMsg, STD_ERROR_HANDLE); }
VOID ConErrPuts(LPTSTR szText) { ConPuts(szText, STD_ERROR_HANDLE); }
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; }
VOID ConOutPuts(LPTSTR szText) { ConPuts(szText, STD_OUTPUT_HANDLE); }
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; }
INT cmdUser( INT argc, WCHAR **argv) { INT i, j; INT result = 0; BOOL bAdd = FALSE; BOOL bDelete = FALSE; #if 0 BOOL bDomain = FALSE; #endif BOOL bRandomPassword = FALSE; LPWSTR lpUserName = NULL; LPWSTR lpPassword = NULL; PUSER_INFO_4 pUserInfo = NULL; USER_INFO_4 UserInfo; LPWSTR pWorkstations = NULL; LPWSTR p; LPWSTR endptr; DWORD value; BOOL bPasswordAllocated = FALSE; NET_API_STATUS Status; i = 2; if ((i < argc) && (argv[i][0] != L'/')) { lpUserName = argv[i]; // ConPrintf(StdOut, L"User: %s\n", lpUserName); i++; } if ((i < argc) && (argv[i][0] != L'/')) { lpPassword = argv[i]; // ConPrintf(StdOut, L"Password: %s\n", lpPassword); i++; } for (j = i; j < argc; j++) { if (_wcsicmp(argv[j], L"/help") == 0) { PrintNetMessage(MSG_USER_HELP); return 0; } else if (_wcsicmp(argv[j], L"/add") == 0) { bAdd = TRUE; } else if (_wcsicmp(argv[j], L"/delete") == 0) { bDelete = TRUE; } else if (_wcsicmp(argv[j], L"/domain") == 0) { ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n"); #if 0 bDomain = TRUE; #endif } else if (_wcsicmp(argv[j], L"/random") == 0) { bRandomPassword = TRUE; GenerateRandomPassword(&lpPassword, &bPasswordAllocated); } } if (lpUserName == NULL && lpPassword == NULL) { Status = EnumerateUsers(); ConPrintf(StdOut, L"Status: %lu\n", Status); return 0; } else if (lpUserName != NULL && lpPassword == NULL) { Status = DisplayUser(lpUserName); ConPrintf(StdOut, L"Status: %lu\n", Status); return 0; } if (bAdd && bDelete) { result = 1; goto done; } /* Interactive password input */ if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0) { ReadPassword(&lpPassword, &bPasswordAllocated); } if (!bAdd && !bDelete) { /* Modify the user */ Status = NetUserGetInfo(NULL, lpUserName, 4, (LPBYTE*)&pUserInfo); if (Status != NERR_Success) { ConPrintf(StdOut, L"Status: %lu\n", Status); result = 1; goto done; } } else if (bAdd && !bDelete) { /* Add the user */ ZeroMemory(&UserInfo, sizeof(USER_INFO_4)); UserInfo.usri4_name = lpUserName; UserInfo.usri4_password = lpPassword; UserInfo.usri4_flags = UF_SCRIPT | UF_NORMAL_ACCOUNT; UserInfo.usri4_acct_expires = TIMEQ_FOREVER; UserInfo.usri4_primary_group_id = DOMAIN_GROUP_RID_USERS; pUserInfo = &UserInfo; } for (j = i; j < argc; j++) { if (_wcsnicmp(argv[j], L"/active:", 8) == 0) { p = &argv[i][8]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_ACCOUNTDISABLE; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_ACCOUNTDISABLE; } else { PrintMessageStringV(3952, L"/ACTIVE"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/comment:", 9) == 0) { pUserInfo->usri4_comment = &argv[j][9]; } else if (_wcsnicmp(argv[j], L"/countrycode:", 13) == 0) { p = &argv[i][13]; value = wcstoul(p, &endptr, 10); if (*endptr != 0) { PrintMessageStringV(3952, L"/COUNTRYCODE"); result = 1; goto done; } /* Verify the country code */ if (GetCountryFromCountryCode(value, 0, NULL)) pUserInfo->usri4_country_code = value; } else if (_wcsnicmp(argv[j], L"/expires:", 9) == 0) { p = &argv[i][9]; if (_wcsicmp(p, L"never") == 0) { pUserInfo->usri4_acct_expires = TIMEQ_FOREVER; } else if (!ParseDate(p, &pUserInfo->usri4_acct_expires)) { PrintMessageStringV(3952, L"/EXPIRES"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/fullname:", 10) == 0) { pUserInfo->usri4_full_name = &argv[j][10]; } else if (_wcsnicmp(argv[j], L"/homedir:", 9) == 0) { pUserInfo->usri4_home_dir = &argv[j][9]; } else if (_wcsnicmp(argv[j], L"/passwordchg:", 13) == 0) { p = &argv[i][13]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_PASSWD_CANT_CHANGE; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_PASSWD_CANT_CHANGE; } else { PrintMessageStringV(3952, L"/PASSWORDCHG"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/passwordreq:", 13) == 0) { p = &argv[i][13]; if (_wcsicmp(p, L"yes") == 0) { pUserInfo->usri4_flags &= ~UF_PASSWD_NOTREQD; } else if (_wcsicmp(p, L"no") == 0) { pUserInfo->usri4_flags |= UF_PASSWD_NOTREQD; } else { PrintMessageStringV(3952, L"/PASSWORDREQ"); result = 1; goto done; } } else if (_wcsnicmp(argv[j], L"/profilepath:", 13) == 0) { pUserInfo->usri4_profile = &argv[j][13]; } else if (_wcsnicmp(argv[j], L"/scriptpath:", 12) == 0) { pUserInfo->usri4_script_path = &argv[j][12]; } else if (_wcsnicmp(argv[j], L"/times:", 7) == 0) { /* FIXME */ ConPuts(StdErr, L"The /TIMES option is not supported yet.\n"); } else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0) { pUserInfo->usri4_usr_comment = &argv[j][13]; } else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0) { p = &argv[i][14]; if (wcscmp(p, L"*") == 0 || wcscmp(p, L"") == 0) { pUserInfo->usri4_workstations = NULL; } else { Status = BuildWorkstationsList(&pWorkstations, p); if (Status == NERR_Success) { pUserInfo->usri4_workstations = pWorkstations; } else { ConPrintf(StdOut, L"Status %lu\n\n", Status); result = 1; goto done; } } } } if (!bAdd && !bDelete) { /* Modify the user */ Status = NetUserSetInfo(NULL, lpUserName, 4, (LPBYTE)pUserInfo, NULL); ConPrintf(StdOut, L"Status: %lu\n", Status); } else if (bAdd && !bDelete) { /* Add the user */ Status = NetUserAdd(NULL, 4, (LPBYTE)pUserInfo, NULL); ConPrintf(StdOut, L"Status: %lu\n", Status); } else if (!bAdd && bDelete) { /* Delete the user */ Status = NetUserDel(NULL, lpUserName); ConPrintf(StdOut, L"Status: %lu\n", Status); } if (Status == NERR_Success && lpPassword != NULL && bRandomPassword == TRUE) { PrintMessageStringV(3968, lpUserName, lpPassword); } done: if (pWorkstations != NULL) HeapFree(GetProcessHeap(), 0, pWorkstations); if ((bPasswordAllocated == TRUE) && (lpPassword != NULL)) HeapFree(GetProcessHeap(), 0, lpPassword); if (!bAdd && !bDelete && pUserInfo != NULL) NetApiBufferFree(pUserInfo); if (result != 0) { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_USER_SYNTAX); } return result; }
static INT DisplayWorkstationConfig(VOID) { PWKSTA_INFO_100 WorkstationInfo = NULL; PWKSTA_USER_INFO_1 UserInfo = NULL; PWKSTA_TRANSPORT_INFO_0 TransportInfo = NULL; DWORD dwRead = 0, dwTotal = 0, i; INT nPaddedLength = 38; NET_API_STATUS Status; Status = NetWkstaGetInfo(NULL, 100, (PBYTE*)&WorkstationInfo); if (Status != NERR_Success) goto done; Status = NetWkstaUserGetInfo(NULL, 1, (PBYTE*)&UserInfo); if (Status != NERR_Success) goto done; Status = NetWkstaTransportEnum(NULL, 0, (PBYTE*)&TransportInfo, MAX_PREFERRED_LENGTH, &dwRead, &dwTotal, NULL); if (Status != NERR_Success) goto done; PrintPaddedMessageString(4450, nPaddedLength); ConPrintf(StdOut, L"\\\\%s\n", WorkstationInfo->wki100_computername); PrintPaddedMessageString(4468, nPaddedLength); ConPuts(StdOut, L"...\n"); PrintPaddedMessageString(4451, nPaddedLength); ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_username); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4453, nPaddedLength); ConPuts(StdOut, L"\n"); for (i = 0; i < dwRead; i++) { ConPrintf(StdOut, L" %s (%s)\n", &TransportInfo[i].wkti0_transport_name[8], TransportInfo[i].wkti0_transport_address); } ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4452, nPaddedLength); ConPrintf(StdOut, L"%lu.%lu\n", WorkstationInfo->wki100_ver_major, WorkstationInfo->wki100_ver_minor); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4455, nPaddedLength); ConPrintf(StdOut, L"%s\n", WorkstationInfo->wki100_langroup); PrintPaddedMessageString(4469, nPaddedLength); ConPuts(StdOut, L"...\n"); PrintPaddedMessageString(4456, nPaddedLength); ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_logon_domain); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4458, nPaddedLength); ConPuts(StdOut, L"...\n"); PrintPaddedMessageString(4459, nPaddedLength); ConPuts(StdOut, L"...\n"); PrintPaddedMessageString(4460, nPaddedLength); ConPuts(StdOut, L"...\n"); done: if (TransportInfo != NULL) NetApiBufferFree(TransportInfo); if (UserInfo != NULL) NetApiBufferFree(UserInfo); if (WorkstationInfo != NULL) NetApiBufferFree(WorkstationInfo); return 0; }
static INT DisplayServerConfig( PSERVER_INFO_102 ServerInfo) { PSERVER_TRANSPORT_INFO_0 TransportInfo = NULL; DWORD dwRead, dwTotal, i; INT nPaddedLength = 38; NET_API_STATUS Status; Status = NetServerTransportEnum(NULL, 0, (PBYTE*)&TransportInfo, MAX_PREFERRED_LENGTH, &dwRead, &dwTotal, NULL); if (Status != NERR_Success) goto done; PrintPaddedMessageString(4481, nPaddedLength); ConPrintf(StdOut, L"\\\\%s\n", ServerInfo->sv102_name); PrintPaddedMessageString(4482, nPaddedLength); ConPrintf(StdOut, L"%s\n\n", ServerInfo->sv102_comment); PrintPaddedMessageString(4484, nPaddedLength); ConPrintf(StdOut, L"%lu.%lu\n", ServerInfo->sv102_version_major, ServerInfo->sv102_version_minor); PrintPaddedMessageString(4489, nPaddedLength); ConPuts(StdOut, L"\n"); for (i = 0; i < dwRead; i++) { ConPrintf(StdOut, L" %s (%s)\n", &TransportInfo[i].svti0_transportname[8], TransportInfo[i].svti0_networkaddress); } ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4492, nPaddedLength); PrintMessageString((ServerInfo->sv102_hidden == SV_HIDDEN) ? 4300 : 4301); ConPuts(StdOut, L"\n"); PrintPaddedMessageString(4506, nPaddedLength); ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_users); PrintPaddedMessageString(4511, nPaddedLength); ConPuts(StdOut, L"...\n\n"); PrintPaddedMessageString(4520, nPaddedLength); if (ServerInfo->sv102_disc == SV_NODISC) PrintMessageString(4306); else ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_disc); done: if (TransportInfo != NULL) NetApiBufferFree(TransportInfo); return 0; }
INT cmdConfig( INT argc, WCHAR **argv) { INT i, result = 0; BOOL bServer = FALSE; BOOL bWorkstation = FALSE; PWSTR p, endptr; BOOL bModify = FALSE; LONG lValue; PSERVER_INFO_102 ServerInfo = NULL; NET_API_STATUS Status; for (i = 2; i < argc; i++) { if (_wcsicmp(argv[i], L"server") == 0) { if (bWorkstation == FALSE) bServer = TRUE; continue; } if (_wcsicmp(argv[i], L"workstation") == 0) { if (bServer == FALSE) bWorkstation = TRUE; continue; } if (_wcsicmp(argv[i], L"help") == 0) { /* Print short syntax help */ if (bServer == TRUE) { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_CONFIG_SERVER_SYNTAX); } else { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_CONFIG_SYNTAX); } return 0; } if (_wcsicmp(argv[i], L"/help") == 0) { /* Print full help text*/ if (bServer == TRUE) { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_CONFIG_SERVER_SYNTAX); PrintNetMessage(MSG_CONFIG_SERVER_HELP); } else { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_CONFIG_SYNTAX); PrintNetMessage(MSG_CONFIG_HELP); } return 0; } } if (bServer) { Status = NetServerGetInfo(NULL, 102, (PBYTE*)&ServerInfo); if (Status != NERR_Success) goto done; for (i = 2; i < argc; i++) { if (argv[i][0] != L'/') continue; if (_wcsnicmp(argv[i], L"/autodisconnect:", 16) == 0) { p = &argv[i][16]; lValue = wcstol(p, &endptr, 10); if (*endptr != 0) { PrintMessageStringV(3952, L"/AUTODISCONNECT"); result = 1; goto done; } if (lValue < -1 || lValue > 65535) { PrintMessageStringV(3952, L"/AUTODISCONNECT"); result = 1; goto done; } ServerInfo->sv102_disc = lValue; bModify = TRUE; } else if (_wcsnicmp(argv[i], L"/srvcomment:", 12) == 0) { ServerInfo->sv102_comment = &argv[i][12]; bModify = TRUE; } else if (_wcsnicmp(argv[i], L"/hidden:", 8) == 0) { p = &argv[i][8]; if (_wcsicmp(p, L"yes") != 0 && _wcsicmp(p, L"no") != 0) { PrintMessageStringV(3952, L"/HIDDEN"); result = 1; goto done; } ServerInfo->sv102_hidden = (_wcsicmp(p, L"yes") == 0) ? TRUE : FALSE; bModify = TRUE; } else { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_CONFIG_SERVER_SYNTAX); result = 1; goto done; } } if (bModify) { Status = NetServerSetInfo(NULL, 102, (PBYTE)&ServerInfo, NULL); if (Status != NERR_Success) result = 1; } else { result = DisplayServerConfig(ServerInfo); } } else if (bWorkstation) { result = DisplayWorkstationConfig(); } else { PrintMessageString(4378); ConPuts(StdOut, L"\n"); ConPuts(StdOut, L" Server\n"); ConPuts(StdOut, L" Workstation\n"); ConPuts(StdOut, L"\n"); } done: if (ServerInfo != NULL) NetApiBufferFree(ServerInfo); if (result == 0) PrintErrorMessage(ERROR_SUCCESS); return result; }
static void Ping(void) { PVOID ReplyBuffer = NULL; PVOID SendBuffer = NULL; DWORD ReplySize = 0; DWORD Status; SendBuffer = malloc(RequestSize); if (SendBuffer == NULL) { ConResPrintf(StdErr, IDS_NO_RESOURCES); exit(1); } ZeroMemory(SendBuffer, RequestSize); if (Family == AF_INET6) ReplySize += sizeof(ICMPV6_ECHO_REPLY); else ReplySize += sizeof(ICMP_ECHO_REPLY); ReplySize += RequestSize + SIZEOF_ICMP_ERROR + SIZEOF_IO_STATUS_BLOCK; ReplyBuffer = malloc(ReplySize); if (ReplyBuffer == NULL) { ConResPrintf(StdErr, IDS_NO_RESOURCES); free(SendBuffer); exit(1); } ZeroMemory(ReplyBuffer, ReplySize); EchosSent++; if (Family == AF_INET6) { struct sockaddr_in6 Source; ZeroMemory(&Source, sizeof(Source)); Source.sin6_family = AF_INET6; Status = Icmp6SendEcho2(hIcmpFile, NULL, NULL, NULL, &Source, (struct sockaddr_in6 *)Target->ai_addr, SendBuffer, (USHORT)RequestSize, &IpOptions, ReplyBuffer, ReplySize, Timeout); } else { Status = IcmpSendEcho2(hIcmpFile, NULL, NULL, NULL, ((PSOCKADDR_IN)Target->ai_addr)->sin_addr.s_addr, SendBuffer, (USHORT)RequestSize, &IpOptions, ReplyBuffer, ReplySize, Timeout); } free(SendBuffer); if (Status == 0) { Status = GetLastError(); switch (Status) { case IP_REQ_TIMED_OUT: ConResPrintf(StdOut, IDS_REQUEST_TIMED_OUT); break; default: ConResPrintf(StdOut, IDS_TRANSMIT_FAILED, Status); break; } } else { SOCKADDR_IN6 SockAddrIn6; SOCKADDR_IN SockAddrIn; PSOCKADDR SockAddr; socklen_t Size; EchosReceived++; ZeroMemory(&SockAddrIn, sizeof(SockAddrIn)); ZeroMemory(&SockAddrIn6, sizeof(SockAddrIn6)); if (Family == AF_INET6) { PICMPV6_ECHO_REPLY pEchoReply; PIPV6_ADDRESS_EX Ipv6Addr; pEchoReply = (PICMPV6_ECHO_REPLY)ReplyBuffer; Ipv6Addr = (PIPV6_ADDRESS_EX)&pEchoReply->Address; SockAddrIn6.sin6_family = AF_INET6; CopyMemory(SockAddrIn6.sin6_addr.u.Word, Ipv6Addr->sin6_addr, sizeof(SockAddrIn6.sin6_addr)); //SockAddrIn6.sin6_addr = Ipv6Addr->sin6_addr; SockAddr = (PSOCKADDR)&SockAddrIn6; Size = sizeof(SOCKADDR_IN6); GetNameInfoW(SockAddr, Size, Address, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); ConResPrintf(StdOut, IDS_REPLY_FROM, Address); switch (pEchoReply->Status) { case IP_SUCCESS: { EchosSuccessful++; if (pEchoReply->RoundTripTime == 0) ConResPrintf(StdOut, IDS_REPLY_TIME_0MS); else ConResPrintf(StdOut, IDS_REPLY_TIME_MS, pEchoReply->RoundTripTime); if (pEchoReply->RoundTripTime < RTTMin || RTTMin == 0) RTTMin = pEchoReply->RoundTripTime; if (pEchoReply->RoundTripTime > RTTMax || RTTMax == 0) RTTMax = pEchoReply->RoundTripTime; ConPuts(StdOut, L"\n"); RTTTotal += pEchoReply->RoundTripTime; break; } case IP_DEST_NET_UNREACHABLE: ConResPrintf(StdOut, IDS_DEST_NET_UNREACHABLE); break; case IP_DEST_HOST_UNREACHABLE: ConResPrintf(StdOut, IDS_DEST_HOST_UNREACHABLE); break; case IP_TTL_EXPIRED_TRANSIT: ConResPrintf(StdOut, IDS_TTL_EXPIRED); break; default: ConResPrintf(StdOut, IDS_REPLY_STATUS, pEchoReply->Status); break; } } else { PICMP_ECHO_REPLY pEchoReply; IPAddr *IP4Addr; pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer; IP4Addr = (IPAddr *)&pEchoReply->Address; SockAddrIn.sin_family = AF_INET; SockAddrIn.sin_addr.S_un.S_addr = *IP4Addr; SockAddr = (PSOCKADDR)&SockAddrIn; Size = sizeof(SOCKADDR_IN); GetNameInfoW(SockAddr, Size, Address, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); ConResPrintf(StdOut, IDS_REPLY_FROM, Address); switch (pEchoReply->Status) { case IP_SUCCESS: { EchosSuccessful++; ConResPrintf(StdOut, IDS_REPLY_BYTES, pEchoReply->DataSize); if (pEchoReply->RoundTripTime == 0) ConResPrintf(StdOut, IDS_REPLY_TIME_0MS); else ConResPrintf(StdOut, IDS_REPLY_TIME_MS, pEchoReply->RoundTripTime); ConResPrintf(StdOut, IDS_REPLY_TTL, pEchoReply->Options.Ttl); if (pEchoReply->RoundTripTime < RTTMin || RTTMin == 0) RTTMin = pEchoReply->RoundTripTime; if (pEchoReply->RoundTripTime > RTTMax || RTTMax == 0) RTTMax = pEchoReply->RoundTripTime; RTTTotal += pEchoReply->RoundTripTime; break; } case IP_DEST_NET_UNREACHABLE: ConResPrintf(StdOut, IDS_DEST_NET_UNREACHABLE); break; case IP_DEST_HOST_UNREACHABLE: ConResPrintf(StdOut, IDS_DEST_HOST_UNREACHABLE); break; case IP_TTL_EXPIRED_TRANSIT: ConResPrintf(StdOut, IDS_TTL_EXPIRED); break; default: ConResPrintf(StdOut, IDS_REPLY_STATUS, pEchoReply->Status); break; } } } free(ReplyBuffer); }
INT cmdStatistics( INT argc, WCHAR **argv) { INT i, result = 0; BOOL bServer = FALSE; BOOL bWorkstation = FALSE; for (i = 2; i < argc; i++) { if (_wcsicmp(argv[i], L"server") == 0) { if (bWorkstation == FALSE) bServer = TRUE; continue; } if (_wcsicmp(argv[i], L"workstation") == 0) { if (bServer == FALSE) bWorkstation = TRUE; continue; } if (_wcsicmp(argv[i], L"help") == 0) { /* Print short syntax help */ PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_STATISTICS_SYNTAX); return 0; } if (_wcsicmp(argv[i], L"/help") == 0) { /* Print full help text*/ PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_STATISTICS_SYNTAX); PrintNetMessage(MSG_STATISTICS_HELP); return 0; } } if (bServer) { result = DisplayServerStatistics(); } else if (bWorkstation) { result = DisplayWorkstationStatistics(); } else { PrintMessageString(4379); ConPuts(StdOut, L"\n"); ConPuts(StdOut, L" Server\n"); ConPuts(StdOut, L" Workstation\n"); ConPuts(StdOut, L"\n"); } if (result == 0) PrintErrorMessage(ERROR_SUCCESS); return result; }
int main(int argc, const char ** argv) { struct IntuiMessage *winmsg; ULONG signals, conreadsig, windowsig; LONG lch; WORD InControl = 0; BOOL Done = FALSE; UBYTE ch, ibuf; UBYTE obuf[200]; BYTE error; FromWb = (argc==0L) ? TRUE : FALSE; if(!(IntuitionBase=OpenLibrary("intuition.library",0))) cleanexit("Can't open intuition\n",RETURN_FAIL); /* Create reply port and io block for writing to console */ if(!(writePort = CreatePort("RKM.console.write",0))) cleanexit("Can't create write port\n",RETURN_FAIL); if(!(writeReq = (struct IOStdReq *) CreateExtIO(writePort,(LONG)sizeof(struct IOStdReq)))) cleanexit("Can't create write request\n",RETURN_FAIL); /* Create reply port and io block for reading from console */ if(!(readPort = CreatePort("RKM.console.read",0))) cleanexit("Can't create read port\n",RETURN_FAIL); if(!(readReq = (struct IOStdReq *) CreateExtIO(readPort,(LONG)sizeof(struct IOStdReq)))) cleanexit("Can't create read request\n",RETURN_FAIL); /* Open a window */ if(!(win = OpenWindow(&nw))) cleanexit("Can't open window\n",RETURN_FAIL); /* Now, attach a console to the window */ if(error = OpenConsole(writeReq,readReq,win)) cleanexit("Can't open console.device\n",RETURN_FAIL); else OpenedConsole = TRUE; /* Demonstrate some console escape sequences */ ConPuts(writeReq,"Here's some normal text\n"); sprintf(obuf,"%s%sHere's text in color 3 & italics\n",COLOR03,ITALICS); ConPuts(writeReq,obuf); ConPuts(writeReq,NORMAL); Delay(50); /* Delay for dramatic demo effect */ ConPuts(writeReq,"We will now delete this asterisk =*="); Delay(50); ConPuts(writeReq,"\b\b"); /* backspace twice */ Delay(50); ConPuts(writeReq,DELCHAR); /* delete the character */ Delay(50); QueueRead(readReq,&ibuf); /* send the first console read request */ ConPuts(writeReq,"\n\nNow reading console\n"); ConPuts(writeReq,"Type some keys. Close window when done.\n\n"); conreadsig = 1 << readPort->mp_SigBit; windowsig = 1 << win->UserPort->mp_SigBit; while(!Done) { /* A character, or an IDCMP msg, or both could wake us up */ signals = Wait(conreadsig|windowsig); /* If a console signal was received, get the character */ if (signals & conreadsig) { if((lch = ConMayGetChar(readPort,&ibuf)) != -1) { ch = lch; /* Show hex and ascii (if printable) for char we got. * If you want to parse received control sequences, such as * function or Help keys,you would buffer control sequences * as you receive them, starting to buffer whenever you * receive 0x9B (or 0x1B[ for user-typed sequences) and * ending when you receive a valid terminating character * for the type of control sequence you are receiving. * For CSI sequences, valid terminating characters * are generally 0x40 through 0x7E. * In our example, InControl has the following values: * 0 = no, 1 = have 0x1B, 2 = have 0x9B OR 0x1B and [, * 3 = now inside control sequence, -1 = normal end esc, * -2 = non-CSI(no [) 0x1B end esc * NOTE - a more complex parser is required to recognize * other types of control sequences. */ /* 0x1B ESC not followed by '[', is not CSI seq */ if (InControl==1) { if(ch=='[') InControl = 2; else InControl = -2; } if ((ch==0x9B)||(ch==0x1B)) /* Control seq starting */ { InControl = (ch==0x1B) ? 1 : 2; ConPuts(writeReq,"=== Control Seq ===\n"); } /* We'll show value of this char we received */ if (((ch >= 0x1F)&&(ch <= 0x7E))||(ch >= 0xA0)) sprintf(obuf,"Received: hex %02x = %c\n",ch,ch); else sprintf(obuf,"Received: hex %02x\n",ch); ConPuts(writeReq,obuf); /* Valid ESC sequence terminator ends an ESC seq */ if ((InControl==3)&&((ch >= 0x40) && (ch <= 0x7E))) { InControl = -1; } if (InControl==2) InControl = 3; /* ESC sequence finished (-1 if OK, -2 if bogus) */ if (InControl < 0) { InControl = 0; ConPuts(writeReq,"=== End Control ===\n"); } } } /* If IDCMP messages received, handle them */ if (signals & windowsig) { /* We have to ReplyMsg these when done with them */ while (winmsg = (struct IntuiMessage *)GetMsg(win->UserPort)) { switch(winmsg->Class) { case IDCMP_CLOSEWINDOW: Done = TRUE; break; default: break; } ReplyMsg((struct Message *)winmsg); } } } /* We always have an outstanding queued read request * so we must abort it if it hasn't completed, * and we must remove it. */ if(!(CheckIO(readReq))) AbortIO(readReq); WaitIO(readReq); /* clear it from our replyport */ cleanup(); exit(RETURN_OK); }
BOOL automount_main(INT argc, LPWSTR *argv) { ConPuts(StdOut, L"Automount\n"); return TRUE; }