ReactOS 0.4.16-dev-340-g0540c21
cmdComputer.c File Reference
#include "net.h"
Include dependency graph for cmdComputer.c:

Go to the source code of this file.

Functions

INT cmdComputer (INT argc, WCHAR **argv)
 

Function Documentation

◆ cmdComputer()

INT cmdComputer ( INT  argc,
WCHAR **  argv 
)

Definition at line 11 of file cmdComputer.c.

14{
15 WCHAR ComputerAccountName[MAX_PATH + 2];
16 WCHAR ComputerPassword[LM20_PWLEN + 1];
17 USER_INFO_1 UserInfo;
18 INT i, result = 0;
19 BOOL bAdd = FALSE;
20 BOOL bDelete = FALSE;
21 PWSTR pComputerName = NULL;
23/*
24 OSVERSIONINFOEX VersionInfo;
25
26 VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo);
27 if (!GetVersionEx((LPOSVERSIONINFO)&VersionInfo))
28 {
29 PrintErrorMessage(GetLastError());
30 return 1;
31 }
32
33 if (VersionInfo.wProductType != VER_NT_DOMAIN_CONTROLLER)
34 {
35 PrintErrorMessage(3515);
36 return 1;
37 }
38*/
39
40 i = 2;
41 if (argc > 2 && argv[i][0] == L'\\' && argv[i][1] == L'\\')
42 {
43 pComputerName = argv[i];
44 i++;
45 }
46
47 for (; i < argc; i++)
48 {
49 if (_wcsicmp(argv[i], L"help") == 0)
50 {
51 /* Print short syntax help */
53 ConPuts(StdOut, L"\n");
54 PrintNetMessage(MSG_COMPUTER_SYNTAX);
55 return 0;
56 }
57
58 if (_wcsicmp(argv[i], L"/help") == 0)
59 {
60 /* Print full help text*/
62 ConPuts(StdOut, L"\n");
63 PrintNetMessage(MSG_COMPUTER_SYNTAX);
64 PrintNetMessage(MSG_COMPUTER_HELP);
65 return 0;
66 }
67
68 if (_wcsicmp(argv[i], L"/add") == 0)
69 {
70 bAdd = TRUE;
71 continue;
72 }
73 else if (_wcsicmp(argv[i], L"/del") == 0)
74 {
75 bDelete = TRUE;
76 continue;
77 }
78 else
79 {
80 PrintErrorMessage(3506/*, argv[i]*/);
81 return 1;
82 }
83 }
84
85 if (pComputerName == NULL ||
86 (bAdd == FALSE && bDelete == FALSE) ||
87 (bAdd == TRUE && bDelete == TRUE))
88 {
90 ConPuts(StdOut, L"\n");
91 PrintNetMessage(MSG_COMPUTER_SYNTAX);
92 return 1;
93 }
94
95 /*
96 * Create the computer account name:
97 * Skip the leading '\\' and appand a '$'.
98 */
99 wcscpy(ComputerAccountName, &pComputerName[2]);
100 wcscat(ComputerAccountName, L"$");
101
102 if (bAdd)
103 {
104 /*
105 * Create the computer password:
106 * Skip the leading '\\', shorten to a maximum of 14 characters
107 * and convert to lower case
108 */
109 wcsncpy(ComputerPassword, &pComputerName[2], LM20_PWLEN);
110 ComputerPassword[LM20_PWLEN] = UNICODE_NULL;
111 _wcslwr(ComputerPassword);
112
113 /* Set the account data */
114 UserInfo.usri1_name = ComputerAccountName;
115 UserInfo.usri1_password = ComputerPassword;
116 UserInfo.usri1_password_age = 0;
117 UserInfo.usri1_priv = USER_PRIV_USER;
118 UserInfo.usri1_home_dir = NULL;
119 UserInfo.usri1_comment = NULL;
121 UserInfo.usri1_script_path = NULL;
122
123 /* Add the computer account */
125 1,
126 (LPBYTE)&UserInfo,
127 NULL);
128 }
129 else if (bDelete)
130 {
131 /* Delete the coputer account */
133 ComputerAccountName);
134 }
135
136 if (Status == NERR_Success)
137 {
139 }
140 else
141 {
143 result = 1;
144 }
145
146 return result;
147}
static int argc
Definition: ServiceArgs.c:12
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdOut
Definition: fc.c:14
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
Definition: user.c:2273
NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
Definition: user.c:2543
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
GLuint64EXT * result
Definition: glext.h:11304
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define USER_PRIV_USER
Definition: lmaccess.h:117
#define UF_SCRIPT
Definition: lmaccess.h:23
#define UF_WORKSTATION_TRUST_ACCOUNT
Definition: lmaccess.h:32
#define LM20_PWLEN
Definition: lmcons.h:38
#define NERR_Success
Definition: lmerr.h:5
#define argv
Definition: mplay32.c:18
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl _wcslwr(_Inout_z_ wchar_t *_String)
DWORD usri1_flags
Definition: lmaccess.h:209
LPWSTR usri1_comment
Definition: lmaccess.h:208
DWORD usri1_password_age
Definition: lmaccess.h:205
LPWSTR usri1_name
Definition: lmaccess.h:203
LPWSTR usri1_script_path
Definition: lmaccess.h:210
LPWSTR usri1_home_dir
Definition: lmaccess.h:207
LPWSTR usri1_password
Definition: lmaccess.h:204
DWORD usri1_priv
Definition: lmaccess.h:206
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
__wchar_t WCHAR
Definition: xmlstorage.h:180