ReactOS  0.4.12-dev-36-g472787f
nfs41_daemon.c File Reference
#include <windows.h>
#include <process.h>
#include <tchar.h>
#include <stdio.h>
#include <devioctl.h>
#include <lmcons.h>
#include <iphlpapi.h>
#include "nfs41_driver.h"
#include "nfs41_np.h"
#include "idmap.h"
#include "daemon_debug.h"
#include "upcall.h"
#include "util.h"
#include "service.h"
Include dependency graph for nfs41_daemon.c:

Go to the source code of this file.

Classes

struct  _nfs41_process_thread
 
struct  _nfsd_args
 

Macros

#define MAX_NUM_THREADS   128
 

Typedefs

typedef struct _nfs41_process_thread nfs41_process_thread
 
typedef struct _nfsd_args nfsd_args
 

Functions

static int map_user_to_ids (nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
 
static unsigned int WINAPI thread_main (void *args)
 
VOID ServiceStop ()
 
static bool_t check_for_files ()
 
static void PrintUsage ()
 
static bool_t parse_cmdlineargs (int argc, TCHAR *argv[], nfsd_args *out)
 
static void print_getaddrinfo (struct addrinfo *ptr)
 
static int getdomainname ()
 
VOID ServiceStart (DWORD argc, LPTSTR *argv)
 

Variables

DWORD NFS41D_VERSION = 0
 
static const char FILE_NETCONFIG [] = "C:\\ReactOS\\System32\\drivers\\etc\\netconfig"
 
char localdomain_name [NFS41_HOSTNAME_LEN]
 
int default_uid = 666
 
int default_gid = 777
 
HANDLE stop_event = NULL
 

Macro Definition Documentation

◆ MAX_NUM_THREADS

#define MAX_NUM_THREADS   128

Definition at line 41 of file nfs41_daemon.c.

Referenced by ServiceStart().

Typedef Documentation

◆ nfs41_process_thread

◆ nfsd_args

Function Documentation

◆ check_for_files()

static bool_t check_for_files ( )
static

Definition at line 168 of file nfs41_daemon.c.

Referenced by ServiceStart().

169 {
170  FILE *fd;
171 #ifdef __REACTOS__
172  char config_path[MAX_PATH];
173 
174  if (GetSystemDirectoryA(config_path, ARRAYSIZE(config_path)))
175  {
176  StringCchCatA(config_path, ARRAYSIZE(config_path), "\\drivers\\etc\\netconfig");
177  }
178  else
179  {
180  StringCchCopyA(config_path, ARRAYSIZE(config_path), "C:\\ReactOS\\system32\\drivers\\etc\\netconfig");
181  }
182 
183  fd = fopen(config_path, "r");
184 #else
185 
186  fd = fopen(FILE_NETCONFIG, "r");
187 #endif
188  if (fd == NULL) {
189 #ifdef __REACTOS__
190  fprintf(stderr,"nfsd() failed to open file '%s'\n", config_path);
191 #else
192  fprintf(stderr,"nfsd() failed to open file '%s'\n", FILE_NETCONFIG);
193 #endif
194  return FALSE;
195  }
196  fclose(fd);
197  return TRUE;
198 }
static const char FILE_NETCONFIG[]
Definition: nfs41_daemon.c:45
#define TRUE
Definition: types.h:120
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2282
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static int fd
Definition: io.c:51
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:320
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
FILE * stderr

◆ getdomainname()

static int getdomainname ( )
static

Definition at line 289 of file nfs41_daemon.c.

Referenced by get_default_domain(), and ServiceStart().

290 {
291  int status = 0;
292  PFIXED_INFO net_info = NULL;
293  DWORD size = 0;
294  BOOLEAN flag = FALSE;
295 
296  status = GetNetworkParams(net_info, &size);
297  if (status != ERROR_BUFFER_OVERFLOW) {
298  eprintf("getdomainname: GetNetworkParams returned %d\n", status);
299  goto out;
300  }
301  net_info = calloc(1, size);
302  if (net_info == NULL) {
303  status = GetLastError();
304  goto out;
305  }
306  status = GetNetworkParams(net_info, &size);
307  if (status) {
308  eprintf("getdomainname: GetNetworkParams returned %d\n", status);
309  goto out_free;
310  }
311 
312  if (net_info->DomainName[0] == '\0') {
313  struct addrinfo *result = NULL, *ptr = NULL, hints = { 0 };
314  char hostname[NI_MAXHOST], servInfo[NI_MAXSERV];
315 
316  hints.ai_socktype = SOCK_STREAM;
317  hints.ai_protocol = IPPROTO_TCP;
318 
319  status = getaddrinfo(net_info->HostName, NULL, &hints, &result);
320  if (status) {
321  status = WSAGetLastError();
322  eprintf("getdomainname: getaddrinfo failed with %d\n", status);
323  goto out_free;
324  }
325 
326  for (ptr=result; ptr != NULL; ptr=ptr->ai_next) {
327  print_getaddrinfo(ptr);
328 
329  switch (ptr->ai_family) {
330  case AF_INET6:
331  case AF_INET:
332  status = getnameinfo((struct sockaddr *)ptr->ai_addr,
333  (socklen_t)ptr->ai_addrlen, hostname, NI_MAXHOST,
334  servInfo, NI_MAXSERV, NI_NAMEREQD);
335  if (status)
336  dprintf(1, "getnameinfo failed %d\n", WSAGetLastError());
337  else {
338  size_t i, len = strlen(hostname);
339  char *p = hostname;
340  dprintf(1, "getdomainname: hostname %s %d\n", hostname, len);
341  for (i = 0; i < len; i++)
342  if (p[i] == '.')
343  break;
344  if (i == len)
345  break;
346  flag = TRUE;
347  memcpy(localdomain_name, &hostname[i+1], len-i);
348  dprintf(1, "getdomainname: domainname %s %d\n",
350  goto out_loop;
351  }
352  break;
353  default:
354  break;
355  }
356  }
357 out_loop:
358  if (!flag) {
359  status = ERROR_INTERNAL_ERROR;
360  eprintf("getdomainname: unable to get a domain name. "
361  "Set this machine's domain name:\n"
362  "System > ComputerName > Change > More > mydomain\n");
363  }
364  freeaddrinfo(result);
365  } else {
366  dprintf(1, "domain name is %s\n", net_info->DomainName);
367  memcpy(localdomain_name, net_info->DomainName,
368  strlen(net_info->DomainName));
369  localdomain_name[strlen(net_info->DomainName)] = '\0';
370  }
371 out_free:
372  free(net_info);
373 out:
374  return status;
375 }
char localdomain_name[NFS41_HOSTNAME_LEN]
Definition: nfs41_daemon.c:49
namespace GUID const ADDRINFOEXW * hints
Definition: sock.c:80
#define NI_NAMEREQD
Definition: ws2def.h:355
#define TRUE
Definition: types.h:120
#define freeaddrinfo
Definition: wspiapi.h:46
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:840
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define free
Definition: debug_ros.c:5
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
char * hostname
Definition: ftp.c:88
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define dprintf
Definition: regdump.c:33
static PVOID ptr
Definition: dispmode.c:27
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define AF_INET6
Definition: winsock.h:369
char DomainName[MAX_DOMAIN_NAME_LEN+4]
Definition: iptypes.h:82
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
GLsizeiptr size
Definition: glext.h:5919
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean flag
Definition: glfuncs.h:72
#define NI_MAXSERV
Definition: ws2def.h:360
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
int socklen_t
Definition: tcp.c:35
#define NI_MAXHOST
Definition: ws2def.h:359
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
char HostName[MAX_HOSTNAME_LEN+4]
Definition: iptypes.h:81
#define getnameinfo
Definition: wspiapi.h:45
static void print_getaddrinfo(struct addrinfo *ptr)
Definition: nfs41_daemon.c:264
#define calloc
Definition: rosglue.h:14
#define AF_INET
Definition: tcpip.h:117
#define SOCK_STREAM
Definition: tcpip.h:118
GLfloat GLfloat p
Definition: glext.h:8902
GLuint64EXT * result
Definition: glext.h:11304
static SERVICE_STATUS status
Definition: service.c:31
#define getaddrinfo
Definition: wspiapi.h:44
Definition: ps.c:97

◆ map_user_to_ids()

static int map_user_to_ids ( nfs41_idmapper idmapper,
uid_t uid,
gid_t gid 
)
static

Definition at line 62 of file nfs41_daemon.c.

Referenced by thread_main().

63 {
64  char username[UNLEN + 1];
65  DWORD len = UNLEN + 1;
66  int status = NO_ERROR;
67 
68  if (!GetUserNameA(username, &len)) {
69  status = GetLastError();
70  eprintf("GetUserName() failed with %d\n", status);
71  goto out;
72  }
73  dprintf(1, "map_user_to_ids: mapping user %s\n", username);
74 
75  if (nfs41_idmap_name_to_ids(idmapper, username, uid, gid)) {
76  /* instead of failing for auth_sys, fall back to 'nobody' uid/gid */
77  *uid = default_uid;
78  *gid = default_gid;
79  }
80 out:
81  return status;
82 }
int default_uid
Definition: nfs41_daemon.c:50
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
int nfs41_idmap_name_to_ids(struct idmap_context *context, const char *username, uid_t *uid_out, gid_t *gid_out)
Definition: idmap.c:887
#define NO_ERROR
Definition: dderror.h:5
int default_gid
Definition: nfs41_daemon.c:51
#define dprintf
Definition: regdump.c:33
static WCHAR username[]
Definition: url.c:32
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
BOOL WINAPI GetUserNameA(LPSTR lpszName, LPDWORD lpSize)
Definition: misc.c:246
#define UNLEN
Definition: sspi.c:28
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ parse_cmdlineargs()

static bool_t parse_cmdlineargs ( int  argc,
TCHAR argv[],
nfsd_args out 
)
static

Definition at line 205 of file nfs41_daemon.c.

Referenced by ServiceStart().

206 {
207  int i;
208 
209  /* set defaults. */
210  out->debug_level = 1;
211  out->ldap_enable = TRUE;
212 
213  /* parse command line */
214  for (i = 1; i < argc; i++) {
215  if (argv[i][0] == TEXT('-')) {
216  if (_tcscmp(argv[i], TEXT("-h")) == 0) { /* help */
217  PrintUsage();
218  return FALSE;
219  }
220  else if (_tcscmp(argv[i], TEXT("-d")) == 0) { /* debug level */
221  ++i;
222  if (i >= argc) {
223  fprintf(stderr, "Missing debug level value\n");
224  PrintUsage();
225  return FALSE;
226  }
227  out->debug_level = _ttoi(argv[i]);
228  }
229  else if (_tcscmp(argv[i], TEXT("--noldap")) == 0) { /* no LDAP */
230  out->ldap_enable = FALSE;
231  }
232  else if (_tcscmp(argv[i], TEXT("--uid")) == 0) { /* no LDAP, setting default uid */
233  ++i;
234  if (i >= argc) {
235  fprintf(stderr, "Missing uid value\n");
236  PrintUsage();
237  return FALSE;
238  }
239  default_uid = _ttoi(argv[i]);
240  if (!default_uid) {
241  fprintf(stderr, "Invalid (or missing) anonymous uid value of %d\n",
242  default_uid);
243  return FALSE;
244  }
245  }
246  else if (_tcscmp(argv[i], TEXT("--gid")) == 0) { /* no LDAP, setting default gid */
247  ++i;
248  if (i >= argc) {
249  fprintf(stderr, "Missing gid value\n");
250  PrintUsage();
251  return FALSE;
252  }
253  default_gid = _ttoi(argv[i]);
254  }
255  else
256  fprintf(stderr, "Unrecognized option '%s', disregarding.\n", argv[i]);
257  }
258  }
259  fprintf(stdout, "parse_cmdlineargs: debug_level %d ldap is %d\n",
260  out->debug_level, out->ldap_enable);
261  return TRUE;
262 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
int default_uid
Definition: nfs41_daemon.c:50
bool_t ldap_enable
Definition: nfs41_daemon.c:164
int default_gid
Definition: nfs41_daemon.c:51
static char ** argv
Definition: ServiceArgs.c:11
FILE * stdout
GLenum GLclampf GLint i
Definition: glfuncs.h:14
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static void PrintUsage()
Definition: nfs41_daemon.c:200
#define TEXT(s)
Definition: k32.h:26
int CDECL _ttoi(const _TCHAR *str)
Definition: atoi.c:10
FILE * stderr

◆ print_getaddrinfo()

static void print_getaddrinfo ( struct addrinfo ptr)
static

Definition at line 264 of file nfs41_daemon.c.

Referenced by getdomainname().

265 {
266  char ipstringbuffer[46];
267  DWORD ipbufferlength = 46;
268 
269  dprintf(1, "getaddrinfo response flags: 0x%x\n", ptr->ai_flags);
270  switch (ptr->ai_family) {
271  case AF_UNSPEC: dprintf(1, "Family: Unspecified\n"); break;
272  case AF_INET:
273  dprintf(1, "Family: AF_INET IPv4 address %s\n",
274  inet_ntoa(((struct sockaddr_in *)ptr->ai_addr)->sin_addr));
275  break;
276  case AF_INET6:
278  NULL, ipstringbuffer, &ipbufferlength))
279  dprintf(1, "WSAAddressToString failed with %u\n", WSAGetLastError());
280  else
281  dprintf(1, "Family: AF_INET6 IPv6 address %s\n", ipstringbuffer);
282  break;
283  case AF_NETBIOS: dprintf(1, "AF_NETBIOS (NetBIOS)\n"); break;
284  default: dprintf(1, "Other %ld\n", ptr->ai_family); break;
285  }
286  dprintf(1, "Canonical name: %s\n", ptr->ai_canonname);
287 }
#define AF_NETBIOS
Definition: winsock.h:363
#define dprintf
Definition: regdump.c:33
smooth NULL
Definition: ftsmooth.c:416
#define AF_INET6
Definition: winsock.h:369
#define AF_UNSPEC
Definition: winsock.h:344
char * ai_canonname
Definition: ws2def.h:670
#define inet_ntoa(addr)
Definition: inet.h:100
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
unsigned long DWORD
Definition: ntddk_ex.h:95
#define AF_INET
Definition: tcpip.h:117
size_t ai_addrlen
Definition: ws2def.h:669
int ai_flags
Definition: ws2def.h:665
#define WSAAddressToString
Definition: winsock2.h:2443
struct sockaddr * ai_addr
Definition: ws2def.h:671
int ai_family
Definition: ws2def.h:666

◆ PrintUsage()

static void PrintUsage ( void  )
static

Definition at line 200 of file nfs41_daemon.c.

Referenced by parse_cmdlineargs().

201 {
202  fprintf(stderr, "Usage: nfsd.exe -d <debug_level> --noldap "
203  "--uid <non-zero value> --gid\n");
204 }
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
FILE * stderr

◆ ServiceStart()

VOID ServiceStart ( DWORD  argc,
LPTSTR argv 
)

Definition at line 380 of file nfs41_daemon.c.

Referenced by CmdDebugService(), IopLoadServiceModule(), and service_main().

382 {
383  DWORD status = 0, len;
384  // handle to our drivers
385  HANDLE pipe;
387  nfs41_idmapper *idmapper = NULL;
388  int i;
389  nfsd_args cmd_args;
390 
391  if (!check_for_files())
392  exit(0);
393  if (!parse_cmdlineargs(argc, argv, &cmd_args))
394  exit(0);
395  set_debug_level(cmd_args.debug_level);
396  open_log_files();
397 
398 #ifdef __REACTOS__
399  /* Start the kernel part */
400  {
402  if (hSvcMan)
403  {
404  HANDLE hSvc = OpenService(hSvcMan, "nfs41_driver", SERVICE_ALL_ACCESS);
405  if (hSvc)
406  {
407  SERVICE_STATUS SvcSt;
408  QueryServiceStatus(hSvc, &SvcSt);
409  if (SvcSt.dwCurrentState != SERVICE_RUNNING)
410  {
411  if (StartService(hSvc, 0, NULL))
412  {
413  dprintf(1, "NFS41 driver started\n");
414  }
415  else
416  {
417  eprintf("Driver failed to start: %d\n", GetLastError());
418  }
419  }
420  else
421  {
422  eprintf("Driver in state: %x\n", SvcSt.dwCurrentState);
423  }
424 
425  CloseServiceHandle(hSvc);
426  }
427  else
428  {
429  eprintf("Failed to open service: %d\n", GetLastError());
430  }
431 
432  CloseServiceHandle(hSvcMan);
433  }
434  else
435  {
436  eprintf("Failed to open service manager: %d\n", GetLastError());
437  }
438  }
439 #endif
440 
441 #ifdef _DEBUG
442  /* dump memory leaks to stderr on exit; this requires the debug heap,
443  /* available only when built in debug mode under visual studio -cbodley */
446 #pragma warning (push)
447 #pragma warning (disable : 4306) /* conversion from 'int' to '_HFILE' of greater size */
449 #pragma warning (pop)
450  dprintf(1, "debug mode. dumping memory leaks to stderr on exit.\n");
451 #endif
452  /* acquire and store in global memory current dns domain name.
453  * needed for acls */
454  if (getdomainname())
455  exit(0);
456 
458 
459  if (cmd_args.ldap_enable) {
460  status = nfs41_idmap_create(&idmapper);
461  if (status) {
462  eprintf("id mapping initialization failed with %d\n", status);
463  goto out_logs;
464  }
465  }
466 
468  dprintf(1, "NFS41 Daemon starting: version %d\n", NFS41D_VERSION);
469 
472  0, NULL);
473  if (pipe == INVALID_HANDLE_VALUE)
474  {
475  eprintf("Unable to open upcall pipe %d\n", GetLastError());
476  goto out_idmap;
477  }
478 
479  dprintf(1, "starting nfs41 mini redirector\n");
480  status = DeviceIoControl(pipe, IOCTL_NFS41_START,
481  &NFS41D_VERSION, sizeof(DWORD), NULL, 0, (LPDWORD)&len, NULL);
482  if (!status) {
483  eprintf("IOCTL_NFS41_START failed with %d\n",
484  GetLastError());
485  goto out_pipe;
486  }
487 
488 #ifndef STANDALONE_NFSD
490  if (stop_event == NULL)
491  goto out_pipe;
492 #endif
493 
494  for (i = 0; i < MAX_NUM_THREADS; i++) {
496  idmapper, 0, &tids[i].tid);
497  if (tids[i].handle == INVALID_HANDLE_VALUE) {
498  status = GetLastError();
499  eprintf("_beginthreadex failed %d\n", status);
500  goto out_pipe;
501  }
502  }
503 #ifndef STANDALONE_NFSD
504  // report the status to the service control manager.
506  goto out_pipe;
508 #else
509  //This can be changed to waiting on an array of handles and using waitformultipleobjects
510  dprintf(1, "Parent waiting for children threads\n");
511  for (i = 0; i < MAX_NUM_THREADS; i++)
513 #endif
514  dprintf(1, "Parent woke up!!!!\n");
515 
516 out_pipe:
517  CloseHandle(pipe);
518 out_idmap:
519  if (idmapper) nfs41_idmap_free(idmapper);
520 out_logs:
521 #ifndef STANDALONE_NFSD
522  close_log_files();
523 #endif
524  return;
525 }
#define CreateEvent
Definition: winbase.h:3562
#define StartService
Definition: winsvc.h:585
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static bool_t check_for_files()
Definition: nfs41_daemon.c:168
DWORD dwCurrentState
Definition: winsvc.h:100
#define _CRTDBG_ALLOC_MEM_DF
Definition: crtdbg.h:55
#define _CRT_WARN
Definition: crtdbg.h:27
static int getdomainname()
Definition: nfs41_daemon.c:289
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
#define NFS41_USER_DEVICE_NAME_A
Definition: nfs41_driver.h:28
bool_t ldap_enable
Definition: nfs41_daemon.c:164
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
#define NO_ERROR
Definition: dderror.h:5
#define _CrtSetReportFile(t, f)
Definition: crtdbg.h:184
#define OpenService
Definition: winsvc.h:576
static char ** argv
Definition: ServiceArgs.c:11
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE stop_event
Definition: nfs41_daemon.c:55
void set_debug_level(int level)
Definition: daemon_debug.c:35
GLenum GLclampf GLint i
Definition: glfuncs.h:14
void nfs41_server_list_init()
Definition: nfs41_server.c:48
#define dprintf
Definition: regdump.c:33
#define GENERIC_WRITE
Definition: nt_native.h:90
#define SERVICE_RUNNING
Definition: winsvc.h:24
static unsigned int WINAPI thread_main(void *args)
Definition: nfs41_daemon.c:84
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:576
DWORD NFS41D_VERSION
Definition: nfs41_daemon.c:42
smooth NULL
Definition: ftsmooth.c:416
void close_log_files()
Definition: daemon_debug.c:59
#define OPEN_EXISTING
Definition: compat.h:426
#define IOCTL_NFS41_START
Definition: nfs41_driver.h:43
#define _CRTDBG_LEAK_CHECK_DF
Definition: crtdbg.h:60
#define OpenSCManager
Definition: winsvc.h:575
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2787
#define _CRTDBG_MODE_FILE
Definition: crtdbg.h:32
GLenum GLsizei len
Definition: glext.h:6722
#define _CRTDBG_FILE_STDERR
Definition: crtdbg.h:40
#define GENERIC_READ
Definition: compat.h:124
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
Definition: nfs41_daemon.c:205
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
uint32_t * LPDWORD
Definition: typedefs.h:57
void open_log_files()
Definition: daemon_debug.c:40
int nfs41_idmap_create(struct idmap_context **context_out)
Definition: idmap.c:803
void exit(int exitcode)
Definition: _exit.c:33
#define INFINITE
Definition: serial.h:102
static TfClientId tid
#define _CrtSetDbgFlag(f)
Definition: crtdbg.h:192
void nfs41_idmap_free(struct idmap_context *context)
Definition: idmap.c:865
#define _CrtSetReportMode(t, f)
Definition: crtdbg.h:183
BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
Definition: service.c:240
#define MAX_NUM_THREADS
Definition: nfs41_daemon.c:41
Definition: ps.c:97

◆ ServiceStop()

VOID ServiceStop ( )

Definition at line 156 of file nfs41_daemon.c.

Referenced by ControlHandler(), and service_ctrl().

157 {
158  if (stop_event)
160 }
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
HANDLE stop_event
Definition: nfs41_daemon.c:55

◆ thread_main()

static unsigned int WINAPI thread_main ( void args)
static

Definition at line 84 of file nfs41_daemon.c.

Referenced by ServiceStart().

85 {
86  nfs41_idmapper *idmapper = (nfs41_idmapper*)args;
87  DWORD status = 0;
88  HANDLE pipe;
89  // buffer used to process upcall, assumed to be fixed size.
90  // if we ever need to handle non-cached IO, need to make it dynamic
91  unsigned char outbuf[UPCALL_BUF_SIZE], inbuf[UPCALL_BUF_SIZE];
92  DWORD inbuf_len = UPCALL_BUF_SIZE, outbuf_len;
94 
97  0, NULL);
98  if (pipe == INVALID_HANDLE_VALUE)
99  {
100  eprintf("Unable to open upcall pipe %d\n", GetLastError());
101  return GetLastError();
102  }
103 
104  while(1) {
105  status = DeviceIoControl(pipe, IOCTL_NFS41_READ, NULL, 0,
106  outbuf, UPCALL_BUF_SIZE, (LPDWORD)&outbuf_len, NULL);
107  if (!status) {
108  eprintf("IOCTL_NFS41_READ failed %d\n", GetLastError());
109  continue;
110  }
111 
112  status = upcall_parse(outbuf, (uint32_t)outbuf_len, &upcall);
113  if (status) {
114  upcall.status = status;
115  goto write_downcall;
116  }
117 
118  /* map username to uid/gid */
119  status = map_user_to_ids(idmapper, &upcall.uid, &upcall.gid);
120  if (status) {
121  upcall.status = status;
122  goto write_downcall;
123  }
124 
125  if (upcall.opcode == NFS41_SHUTDOWN) {
126  printf("Shutting down..\n");
127  exit(0);
128  }
129 
130  status = upcall_handle(&upcall);
131 
132 write_downcall:
133  dprintf(1, "writing downcall: xid=%lld opcode=%s status=%d "
134  "get_last_error=%d\n", upcall.xid, opcode2string(upcall.opcode),
135  upcall.status, upcall.last_error);
136 
137  upcall_marshall(&upcall, inbuf, (uint32_t)inbuf_len, (uint32_t*)&outbuf_len);
138 
139  dprintf(2, "making a downcall: outbuf_len %ld\n\n", outbuf_len);
140  status = DeviceIoControl(pipe, IOCTL_NFS41_WRITE,
141  inbuf, inbuf_len, NULL, 0, (LPDWORD)&outbuf_len, NULL);
142  if (!status) {
143  eprintf("IOCTL_NFS41_WRITE failed with %d xid=%lld opcode=%s\n",
144  GetLastError(), upcall.xid, opcode2string(upcall.opcode));
145  upcall_cancel(&upcall);
146  }
147  if (upcall.status != NFSD_VERSION_MISMATCH)
148  upcall_cleanup(&upcall);
149  }
150  CloseHandle(pipe);
151 
152  return GetLastError();
153 }
void upcall_cancel(IN nfs41_upcall *upcall)
Definition: upcall.c:189
#define CloseHandle
Definition: compat.h:398
uint32_t status
Definition: upcall.h:196
uid_t uid
Definition: upcall.h:200
int upcall_parse(IN unsigned char *buffer, IN uint32_t length, OUT nfs41_upcall *upcall)
Definition: upcall.c:75
int upcall_handle(IN nfs41_upcall *upcall)
Definition: upcall.c:138
#define NFS41_USER_DEVICE_NAME_A
Definition: nfs41_driver.h:28
uint64_t xid
Definition: upcall.h:194
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
void upcall_cleanup(IN nfs41_upcall *upcall)
Definition: upcall.c:197
#define dprintf
Definition: regdump.c:33
#define GENERIC_WRITE
Definition: nt_native.h:90
#define NFSD_VERSION_MISMATCH
Definition: upcall.h:28
smooth NULL
Definition: ftsmooth.c:416
static int map_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
Definition: nfs41_daemon.c:62
#define OPEN_EXISTING
Definition: compat.h:426
unsigned long DWORD
Definition: ntddk_ex.h:95
uchar inbuf[M_BLOCK]
Definition: unzcrash.c:40
#define GENERIC_READ
Definition: compat.h:124
void upcall_marshall(IN nfs41_upcall *upcall, OUT unsigned char *buffer, IN uint32_t length, OUT uint32_t *length_out)
Definition: upcall.c:157
gid_t gid
Definition: upcall.h:201
uint32_t opcode
Definition: upcall.h:195
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#define UPCALL_BUF_SIZE
Definition: nfs41_const.h:42
uint32_t last_error
Definition: upcall.h:197
UINT32 uint32_t
Definition: types.h:75
const char * opcode2string(DWORD opcode)
Definition: daemon_debug.c:280
#define IOCTL_NFS41_READ
Definition: nfs41_driver.h:48
nfs41_updowncall_list upcall
Definition: nfs41_driver.c:273
#define IOCTL_NFS41_WRITE
Definition: nfs41_driver.h:49
uint32_t * LPDWORD
Definition: typedefs.h:57
void exit(int exitcode)
Definition: _exit.c:33
static SERVICE_STATUS status
Definition: service.c:31
#define printf
Definition: config.h:203
uchar outbuf[M_BLOCK_OUT]
Definition: unzcrash.c:41
Definition: ps.c:97

Variable Documentation

◆ default_gid

int default_gid = 777

Definition at line 51 of file nfs41_daemon.c.

Referenced by map_user_to_ids(), and parse_cmdlineargs().

◆ default_uid

int default_uid = 666

Definition at line 50 of file nfs41_daemon.c.

Referenced by map_user_to_ids(), and parse_cmdlineargs().

◆ FILE_NETCONFIG

const char FILE_NETCONFIG[] = "C:\\ReactOS\\System32\\drivers\\etc\\netconfig"
static

Definition at line 45 of file nfs41_daemon.c.

Referenced by check_for_files().

◆ localdomain_name

char localdomain_name[NFS41_HOSTNAME_LEN]

Definition at line 49 of file nfs41_daemon.c.

Referenced by getdomainname(), and handle_setacl().

◆ NFS41D_VERSION

DWORD NFS41D_VERSION = 0

Definition at line 42 of file nfs41_daemon.c.

Referenced by marshall_mount(), ServiceStart(), and upcall_parse().

◆ stop_event

HANDLE stop_event = NULL

Definition at line 55 of file nfs41_daemon.c.

Referenced by fileTransfer().