ReactOS
0.4.16-dev-755-g88f105e
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
11
cmdComputer
(
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
;
22
NET_API_STATUS
Status
=
NERR_Success
;
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
;
120
UserInfo.
usri1_flags
=
UF_SCRIPT
|
UF_WORKSTATION_TRUST_ACCOUNT
;
121
UserInfo.
usri1_script_path
=
NULL
;
122
123
/* Add the computer account */
124
Status
=
NetUserAdd
(
NULL
,
125
1,
126
(
LPBYTE
)&UserInfo,
127
NULL
);
128
}
129
else
if
(bDelete)
130
{
131
/* Delete the coputer account */
132
Status
=
NetUserDel
(
NULL
,
133
ComputerAccountName);
134
}
135
136
if
(
Status
==
NERR_Success
)
137
{
138
PrintErrorMessage
(
ERROR_SUCCESS
);
139
}
140
else
141
{
142
PrintErrorMessage
(
Status
);
143
result
= 1;
144
}
145
146
return
result
;
147
}
148
149
/* EOF */
argc
static int argc
Definition:
ServiceArgs.c:12
PrintErrorMessage
static VOID PrintErrorMessage(DWORD dwError)
Definition:
at.c:308
ConPuts
void ConPuts(FILE *fp, LPCWSTR psz)
Definition:
fc.c:16
StdOut
#define StdOut
Definition:
fc.c:14
PrintNetMessage
VOID PrintNetMessage(DWORD dwMessage)
Definition:
main.c:239
PrintMessageString
VOID PrintMessageString(DWORD dwMessage)
Definition:
main.c:120
cmdComputer
INT cmdComputer(INT argc, WCHAR **argv)
Definition:
cmdComputer.c:11
_wcslwr
_wcslwr
Definition:
corecrt_wstring.h:384
wcsncpy
wcsncpy
Definition:
corecrt_wstring.h:201
wcscat
wcscat
Definition:
corecrt_wstring.h:101
wcscpy
wcscpy
Definition:
corecrt_wstring.h:120
ERROR_SUCCESS
#define ERROR_SUCCESS
Definition:
deptool.c:10
NULL
#define NULL
Definition:
types.h:112
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
MAX_PATH
#define MAX_PATH
Definition:
compat.h:34
NetUserAdd
NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
Definition:
user.c:2273
NetUserDel
NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
Definition:
user.c:2543
BOOL
unsigned int BOOL
Definition:
ntddk_ex.h:94
Status
Status
Definition:
gdiplustypes.h:25
result
GLuint64EXT * result
Definition:
glext.h:11304
i
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
USER_PRIV_USER
#define USER_PRIV_USER
Definition:
lmaccess.h:117
UF_SCRIPT
#define UF_SCRIPT
Definition:
lmaccess.h:23
UF_WORKSTATION_TRUST_ACCOUNT
#define UF_WORKSTATION_TRUST_ACCOUNT
Definition:
lmaccess.h:32
LM20_PWLEN
#define LM20_PWLEN
Definition:
lmcons.h:38
NERR_Success
#define NERR_Success
Definition:
lmerr.h:5
argv
#define argv
Definition:
mplay32.c:18
NET_API_STATUS
DWORD NET_API_STATUS
Definition:
ms-dtyp.idl:91
UNICODE_NULL
#define UNICODE_NULL
L
#define L(x)
Definition:
ntvdm.h:50
_wcsicmp
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
net.h
Deprecated header file that includes net_sockets.h.
_USER_INFO_1
Definition:
lmaccess.h:202
_USER_INFO_1::usri1_flags
DWORD usri1_flags
Definition:
lmaccess.h:209
_USER_INFO_1::usri1_comment
LPWSTR usri1_comment
Definition:
lmaccess.h:208
_USER_INFO_1::usri1_password_age
DWORD usri1_password_age
Definition:
lmaccess.h:205
_USER_INFO_1::usri1_name
LPWSTR usri1_name
Definition:
lmaccess.h:203
_USER_INFO_1::usri1_script_path
LPWSTR usri1_script_path
Definition:
lmaccess.h:210
_USER_INFO_1::usri1_home_dir
LPWSTR usri1_home_dir
Definition:
lmaccess.h:207
_USER_INFO_1::usri1_password
LPWSTR usri1_password
Definition:
lmaccess.h:204
_USER_INFO_1::usri1_priv
DWORD usri1_priv
Definition:
lmaccess.h:206
PWSTR
uint16_t * PWSTR
Definition:
typedefs.h:56
LPBYTE
unsigned char * LPBYTE
Definition:
typedefs.h:53
INT
int32_t INT
Definition:
typedefs.h:58
WCHAR
__wchar_t WCHAR
Definition:
xmlstorage.h:180
base
applications
network
net
cmdComputer.c
Generated on Wed Feb 19 2025 06:02:32 for ReactOS by
1.9.6