ReactOS  0.4.14-dev-115-g4576127
cmdComputer.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS net command
4  * FILE: base/applications/network/net/cmdComputer.c
5  * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
6  */
7 
8 #include "net.h"
9 
10 INT
12  INT argc,
13  WCHAR **argv)
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 */
52  PrintMessageString(4381);
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*/
61  PrintMessageString(4381);
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  {
89  PrintMessageString(4381);
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 }
148 
149 /* EOF */
DWORD usri1_password_age
Definition: lmaccess.h:205
static int argc
Definition: ServiceArgs.c:12
LPWSTR usri1_password
Definition: lmaccess.h:204
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
uint16_t * PWSTR
Definition: typedefs.h:54
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:228
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
#define NERR_Success
Definition: lmerr.h:5
#define USER_PRIV_USER
Definition: lmaccess.h:117
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
unsigned char * LPBYTE
Definition: typedefs.h:52
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
INT cmdComputer(INT argc, WCHAR **argv)
Definition: cmdComputer.c:11
NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
Definition: user.c:2273
smooth NULL
Definition: ftsmooth.c:416
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPWSTR usri1_comment
Definition: lmaccess.h:208
#define MAX_PATH
Definition: compat.h:26
LPWSTR usri1_name
Definition: lmaccess.h:203
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
Definition: user.c:2543
static const WCHAR L[]
Definition: oid.c:1250
#define UF_WORKSTATION_TRUST_ACCOUNT
Definition: lmaccess.h:32
LPWSTR usri1_script_path
Definition: lmaccess.h:210
Status
Definition: gdiplustypes.h:24
_CRTIMP wchar_t *__cdecl _wcslwr(_Inout_z_ wchar_t *_String)
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:109
DWORD usri1_priv
Definition: lmaccess.h:206
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define LM20_PWLEN
Definition: lmcons.h:38
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76
DWORD usri1_flags
Definition: lmaccess.h:209
GLuint64EXT * result
Definition: glext.h:11304
LPWSTR usri1_home_dir
Definition: lmaccess.h:207
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define UF_SCRIPT
Definition: lmaccess.h:23