ReactOS 0.4.16-dev-125-g798ea90
cmdShare.c File Reference
#include "net.h"
Include dependency graph for cmdShare.c:

Go to the source code of this file.

Functions

NET_API_STATUS EnumerateShares (VOID)
 
NET_API_STATUS DisplayShare (PWSTR pShareName)
 
INT cmdShare (INT argc, WCHAR **argv)
 

Function Documentation

◆ cmdShare()

INT cmdShare ( INT  argc,
WCHAR **  argv 
)

Definition at line 94 of file cmdShare.c.

97{
98 SHARE_INFO_2 ShareInfo;
99 PWSTR pszShareName = NULL;
100 PWSTR pszSharePath = NULL;
101 PWSTR ptr;
102 BOOL bDelete = FALSE;
103 INT len;
104 INT i, result = 0;
106
107 i = 2;
108 if (argc > 2 && argv[i][0] != L'/')
109 {
110 ptr = wcschr(argv[i], L'=');
111 if (ptr != NULL)
112 {
113 if (ptr[1] != UNICODE_NULL)
114 {
115 len = wcslen(&ptr[i]);
116 pszSharePath = HeapAlloc(GetProcessHeap(),
118 (len + 1) * sizeof(WCHAR));
119 if (pszSharePath == NULL)
120 {
121 // FIXME: Proper error code!
122 return 1;
123 }
124
125 wcscpy(pszSharePath, &ptr[1]);
126 }
127
128 len = ((INT_PTR)ptr - (INT_PTR)argv[i]) / sizeof(WCHAR);
129 pszShareName = HeapAlloc(GetProcessHeap(),
131 (len + 1) * sizeof(WCHAR));
132 if (pszShareName == NULL)
133 {
134 // FIXME: Proper error code!
135 return 1;
136 }
137
138 wcsncpy(pszShareName, argv[i], len);
139 }
140 else
141 {
142 len = wcslen(argv[i]);
143 pszShareName = HeapAlloc(GetProcessHeap(),
145 (len + 1) * sizeof(WCHAR));
146 if (pszShareName == NULL)
147 {
148 // FIXME: Proper error code!
149 return 1;
150 }
151
152 wcscpy(pszShareName, argv[i]);
153 }
154
155 i++;
156 }
157
158 for (; i < argc; i++)
159 {
160 if (_wcsicmp(argv[i], L"/help") == 0)
161 {
162 /* Print full help text*/
163 PrintMessageString(4381);
164 ConPuts(StdOut, L"\n");
165 PrintNetMessage(MSG_SHARE_SYNTAX);
166 PrintNetMessage(MSG_SHARE_HELP);
167 return 0;
168 }
169 else if (_wcsicmp(argv[i], L"/delete") == 0)
170 {
171 bDelete = TRUE;
172 }
173 }
174
175 printf("pszShareName: '%S'\n", pszShareName);
176 printf("pszSharePath: '%S'\n", pszSharePath);
177
178 if (pszShareName == NULL && pszSharePath == NULL)
179 {
181 ConPrintf(StdOut, L"Status: %lu\n", Status);
182 }
183 else if (pszShareName != NULL && pszSharePath == NULL)
184 {
185 if (bDelete == TRUE)
186 {
188 pszShareName,
189 0);
190 }
191 else
192 {
193 Status = DisplayShare(pszShareName);
194 }
195
196 ConPrintf(StdOut, L"Status: %lu\n", Status);
197 }
198 else if (pszShareName != NULL && pszSharePath != NULL)
199 {
200 ZeroMemory(&ShareInfo, sizeof(SHARE_INFO_2));
201 ShareInfo.shi2_netname = pszShareName;
202 ShareInfo.shi2_path = pszSharePath;
203
205 2,
206 (LPBYTE)&ShareInfo,
207 NULL);
208
209 ConPrintf(StdOut, L"Status: %lu\n", Status);
210 }
211
212 if (pszSharePath != NULL)
213 HeapFree(GetProcessHeap(), 0, pszSharePath);
214
215 if (pszShareName != NULL)
216 HeapFree(GetProcessHeap(), 0, pszShareName);
217
218 return result;
219}
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
NET_API_STATUS EnumerateShares(VOID)
Definition: cmdShare.c:12
NET_API_STATUS DisplayShare(PWSTR pShareName)
Definition: cmdShare.c:52
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
NET_API_STATUS WINAPI NetShareDel(_In_ LMSTR servername, _In_ LMSTR netname, _In_ DWORD reserved)
Definition: srvsvc.c:911
NET_API_STATUS WINAPI NetShareAdd(_In_ LMSTR servername, _In_ DWORD level, _In_ LPBYTE buf, _Out_ LPDWORD parm_err)
Definition: srvsvc.c:850
unsigned int BOOL
Definition: ntddk_ex.h:94
#define printf
Definition: freeldr.h:97
Status
Definition: gdiplustypes.h:25
GLenum GLsizei len
Definition: glext.h:6722
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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static PVOID ptr
Definition: dispmode.c:27
#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)
LPTSTR shi2_path
Definition: lmshare.h:57
LPTSTR shi2_netname
Definition: lmshare.h:51
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT_PTR
Definition: typedefs.h:64
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define ZeroMemory
Definition: winbase.h:1712
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ DisplayShare()

NET_API_STATUS DisplayShare ( PWSTR  pShareName)

Definition at line 52 of file cmdShare.c.

54{
56 INT nPaddedLength = 22;
58
60 pShareName,
61 2,
62 (LPBYTE*)&pBuffer);
63 if (Status != NERR_Success)
64 return Status;
65
66 PrintPaddedMessageString(4731, nPaddedLength);
67 ConPrintf(StdOut, L"%s\n", pBuffer->shi2_netname);
68
69 PrintPaddedMessageString(4339, nPaddedLength);
70 ConPrintf(StdOut, L"%s\n", pBuffer->shi2_path);
71
72 PrintPaddedMessageString(4334, nPaddedLength);
73 ConPrintf(StdOut, L"%s\n", pBuffer->shi2_remark);
74
75 PrintPaddedMessageString(4735, nPaddedLength);
76 if (pBuffer->shi2_max_uses == (DWORD)-1)
78 else
79 ConPrintf(StdOut, L"%lu", pBuffer->shi2_max_uses);
80 ConPrintf(StdOut, L"\n");
81
82 PrintPaddedMessageString(4737, nPaddedLength);
83 if (pBuffer->shi2_current_uses > 0)
84 ConPrintf(StdOut, L"%lu", pBuffer->shi2_current_uses);
85 ConPrintf(StdOut, L"\n");
86
88
89 return NERR_Success;
90}
VOID PrintPaddedMessageString(DWORD dwMessage, INT nPaddedLength)
Definition: main.c:143
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NET_API_STATUS WINAPI NetShareGetInfo(_In_ LMSTR servername, _In_ LMSTR netname, _In_ DWORD level, _Out_ LPBYTE *bufptr)
Definition: srvsvc.c:1177
unsigned long DWORD
Definition: ntddk_ex.h:95
#define NERR_Success
Definition: lmerr.h:5
PVOID pBuffer

Referenced by cmdShare().

◆ EnumerateShares()

NET_API_STATUS EnumerateShares ( VOID  )

Definition at line 12 of file cmdShare.c.

13{
15 DWORD dwRead = 0, dwTotal = 0;
16 DWORD ResumeHandle = 0, i;
18
19 ConPuts(StdOut, L"\n");
21 ConPuts(StdOut, L"\n");
22 PrintPadding(L'-', 79);
23 ConPuts(StdOut, L"\n");
24
25 do
26 {
28 2,
29 (LPBYTE*)&pBuffer,
31 &dwRead,
32 &dwTotal,
33 &ResumeHandle);
35 return Status;
36
37 for (i = 0; i < dwRead; i++)
38 {
39 ConPrintf(StdOut, L"%-12s %-31s %s\n", pBuffer[i].shi2_netname, pBuffer[i].shi2_path, pBuffer[i].shi2_remark);
40 }
41
43 pBuffer = NULL;
44 }
45 while (Status == ERROR_MORE_DATA);
46
47 return NERR_Success;
48}
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:63
#define ERROR_MORE_DATA
Definition: dderror.h:13
NET_API_STATUS WINAPI NetShareEnum(_In_ LMSTR servername, _In_ DWORD level, _Out_ LPBYTE *bufptr, _In_ DWORD prefmaxlen, _Out_ LPDWORD entriesread, _Out_ LPDWORD totalentries, _Inout_ LPDWORD resume_handle)
Definition: srvsvc.c:973
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48

Referenced by cmdShare().