ReactOS  0.4.14-dev-342-gdc047f9
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
#define TRUE
Definition: types.h:120
LPTSTR shi2_netname
Definition: lmshare.h:51
uint16_t * PWSTR
Definition: typedefs.h:54
LPTSTR shi2_path
Definition: lmshare.h:57
#define ZeroMemory
Definition: winbase.h:1642
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:228
int32_t INT_PTR
Definition: typedefs.h:62
#define argv
Definition: mplay32.c:18
NET_API_STATUS WINAPI NetShareDel(_In_ LMSTR servername, _In_ LMSTR netname, _In_ DWORD reserved)
Definition: srvsvc.c:914
int32_t INT
Definition: typedefs.h:56
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
static PVOID ptr
Definition: dispmode.c:27
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
NET_API_STATUS DisplayShare(PWSTR pShareName)
Definition: cmdShare.c:52
NET_API_STATUS EnumerateShares(VOID)
Definition: cmdShare.c:12
NET_API_STATUS WINAPI NetShareAdd(_In_ LMSTR servername, _In_ DWORD level, _In_ LPBYTE buf, _Out_ LPDWORD parm_err)
Definition: srvsvc.c:853
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
Status
Definition: gdiplustypes.h:24
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:109
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76
GLuint64EXT * result
Definition: glext.h:11304
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:402
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define printf
Definition: config.h:203

◆ 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)
77  PrintMessageString(4736);
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 }
int32_t INT
Definition: typedefs.h:56
#define NERR_Success
Definition: lmerr.h:5
unsigned char * LPBYTE
Definition: typedefs.h:52
NET_API_STATUS WINAPI NetShareGetInfo(_In_ LMSTR servername, _In_ LMSTR netname, _In_ DWORD level, _Out_ LPBYTE *bufptr)
Definition: srvsvc.c:1180
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
VOID PrintPaddedMessageString(DWORD dwMessage, INT nPaddedLength)
Definition: main.c:132
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:109
#define StdOut
Definition: stream.h:76

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");
20  PrintMessageString(4730);
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);
34  if ((Status != NERR_Success) && (Status != ERROR_MORE_DATA))
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 }
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
#define NERR_Success
Definition: lmerr.h:5
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
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:109
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:66
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
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:976
#define StdOut
Definition: stream.h:76

Referenced by cmdShare().