INT cmdContinue(INT argc, WCHAR **argv) { SC_HANDLE hManager = NULL; SC_HANDLE hService = NULL; SERVICE_STATUS status; INT nError = 0; INT i; if (argc != 3) { ConResPuts(StdOut, IDS_GENERIC_SYNTAX); PrintNetMessage(MSG_CONTINUE_SYNTAX); return 1; } for (i = 2; i < argc; i++) { if (_wcsicmp(argv[i], L"/help") == 0) { ConResPuts(StdOut, IDS_GENERIC_SYNTAX); PrintNetMessage(MSG_CONTINUE_SYNTAX); PrintNetMessage(MSG_CONTINUE_HELP); ConResPuts(StdOut, IDS_GENERIC_PAGE); return 1; } } hManager = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE); if (hManager == NULL) { ConPrintf(StdErr, L"[OpenSCManager] Error: %ld\n", GetLastError()); nError = 1; goto done; } hService = OpenService(hManager, argv[2], SERVICE_PAUSE_CONTINUE); if (hService == NULL) { ConPrintf(StdErr, L"[OpenService] Error: %ld\n", GetLastError()); nError = 1; goto done; } if (!ControlService(hService, SERVICE_CONTROL_CONTINUE, &status)) { ConPrintf(StdErr, L"[ControlService] Error: %ld\n", GetLastError()); nError = 1; } done: if (hService != NULL) CloseServiceHandle(hService); if (hManager != NULL) CloseServiceHandle(hManager); return nError; }
int wmain(int argc, WCHAR **argv) { WCHAR szDllBuffer[MAX_PATH]; PCOMMAND cmdptr; int nResult = 0; BOOL bRun = FALSE; /* Initialize the Console Standard Streams */ ConInitStdStreams(); /* Load netmsg.dll */ GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer)); wcscat(szDllBuffer, L"\\netmsg.dll"); hModuleNetMsg = LoadLibrary(szDllBuffer); if (hModuleNetMsg == NULL) { ConPrintf(StdErr, L"Failed to load netmsg.dll\n"); return 1; } if (argc < 2) { nResult = 1; goto done; } /* Scan the command table */ for (cmdptr = cmds; cmdptr->name; cmdptr++) { if (_wcsicmp(argv[1], cmdptr->name) == 0) { nResult = cmdptr->func(argc, argv); bRun = TRUE; break; } } done: if (bRun == FALSE) { PrintMessageString(4381); ConPuts(StdOut, L"\n"); PrintNetMessage(MSG_NET_SYNTAX); } if (hModuleNetMsg != NULL) FreeLibrary(hModuleNetMsg); return nResult; }
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; }
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; }
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; }