ReactOS 0.4.15-dev-8058-ga7cbb60
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.

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.

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 eprintf("GetSystemDirectoryA failed with error %ld\n", GetLastError());
181 return FALSE;
182 }
183
184 fd = fopen(config_path, "r");
185#else
186
187 fd = fopen(FILE_NETCONFIG, "r");
188#endif
189 if (fd == NULL) {
190#ifdef __REACTOS__
191 fprintf(stderr,"nfsd() failed to open file '%s'\n", config_path);
192#else
193 fprintf(stderr,"nfsd() failed to open file '%s'\n", FILE_NETCONFIG);
194#endif
195 return FALSE;
196 }
197 fclose(fd);
198 return TRUE;
199}
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static const char FILE_NETCONFIG[]
Definition: nfs41_daemon.c:45
static int fd
Definition: io.c:51
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:320
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by ServiceStart().

◆ getdomainname()

static int getdomainname ( )
static

Definition at line 290 of file nfs41_daemon.c.

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

Referenced by get_default_domain(), and ServiceStart().

◆ 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.

63{
64 char username[UNLEN + 1];
65 DWORD len = UNLEN + 1;
66 int status = NO_ERROR;
67
68 if (!GetUserNameA(username, &len)) {
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 }
80out:
81 return status;
82}
#define NO_ERROR
Definition: dderror.h:5
BOOL WINAPI GetUserNameA(LPSTR lpszName, LPDWORD lpSize)
Definition: misc.c:246
int nfs41_idmap_name_to_ids(struct idmap_context *context, const char *username, uid_t *uid_out, gid_t *gid_out)
Definition: idmap.c:889
static WCHAR username[]
Definition: url.c:32
int default_uid
Definition: nfs41_daemon.c:50
int default_gid
Definition: nfs41_daemon.c:51
#define UNLEN
Definition: sspi.c:28

Referenced by thread_main().

◆ parse_cmdlineargs()

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

Definition at line 206 of file nfs41_daemon.c.

207{
208 int i;
209
210 /* set defaults. */
211 out->debug_level = 1;
212 out->ldap_enable = TRUE;
213
214 /* parse command line */
215 for (i = 1; i < argc; i++) {
216 if (argv[i][0] == TEXT('-')) {
217 if (_tcscmp(argv[i], TEXT("-h")) == 0) { /* help */
218 PrintUsage();
219 return FALSE;
220 }
221 else if (_tcscmp(argv[i], TEXT("-d")) == 0) { /* debug level */
222 ++i;
223 if (i >= argc) {
224 fprintf(stderr, "Missing debug level value\n");
225 PrintUsage();
226 return FALSE;
227 }
228 out->debug_level = _ttoi(argv[i]);
229 }
230 else if (_tcscmp(argv[i], TEXT("--noldap")) == 0) { /* no LDAP */
231 out->ldap_enable = FALSE;
232 }
233 else if (_tcscmp(argv[i], TEXT("--uid")) == 0) { /* no LDAP, setting default uid */
234 ++i;
235 if (i >= argc) {
236 fprintf(stderr, "Missing uid value\n");
237 PrintUsage();
238 return FALSE;
239 }
241 if (!default_uid) {
242 fprintf(stderr, "Invalid (or missing) anonymous uid value of %d\n",
244 return FALSE;
245 }
246 }
247 else if (_tcscmp(argv[i], TEXT("--gid")) == 0) { /* no LDAP, setting default gid */
248 ++i;
249 if (i >= argc) {
250 fprintf(stderr, "Missing gid value\n");
251 PrintUsage();
252 return FALSE;
253 }
255 }
256 else
257 fprintf(stderr, "Unrecognized option '%s', disregarding.\n", argv[i]);
258 }
259 }
260 fprintf(stdout, "parse_cmdlineargs: debug_level %d ldap is %d\n",
261 out->debug_level, out->ldap_enable);
262 return TRUE;
263}
static int argc
Definition: ServiceArgs.c:12
#define stdout
Definition: stdio.h:99
#define _tcscmp
Definition: tchar.h:1424
#define TEXT(s)
Definition: k32.h:26
#define argv
Definition: mplay32.c:18
static void PrintUsage()
Definition: nfs41_daemon.c:201
#define _ttoi
Definition: xmlstorage.h:195

Referenced by ServiceStart().

◆ print_getaddrinfo()

static void print_getaddrinfo ( struct addrinfo ptr)
static

Definition at line 265 of file nfs41_daemon.c.

266{
267 char ipstringbuffer[46];
268 DWORD ipbufferlength = 46;
269
270 dprintf(1, "getaddrinfo response flags: 0x%x\n", ptr->ai_flags);
271 switch (ptr->ai_family) {
272 case AF_UNSPEC: dprintf(1, "Family: Unspecified\n"); break;
273 case AF_INET:
274 dprintf(1, "Family: AF_INET IPv4 address %s\n",
275 inet_ntoa(((struct sockaddr_in *)ptr->ai_addr)->sin_addr));
276 break;
277 case AF_INET6:
278 if (WSAAddressToString((LPSOCKADDR)ptr->ai_addr, (DWORD)ptr->ai_addrlen,
279 NULL, ipstringbuffer, &ipbufferlength))
280 dprintf(1, "WSAAddressToString failed with %u\n", WSAGetLastError());
281 else
282 dprintf(1, "Family: AF_INET6 IPv6 address %s\n", ipstringbuffer);
283 break;
284 case AF_NETBIOS: dprintf(1, "AF_NETBIOS (NetBIOS)\n"); break;
285 default: dprintf(1, "Other %ld\n", ptr->ai_family); break;
286 }
287 dprintf(1, "Canonical name: %s\n", ptr->ai_canonname);
288}
#define inet_ntoa(addr)
Definition: inet.h:100
#define WSAAddressToString
Definition: winsock2.h:2443
#define AF_NETBIOS
Definition: winsock.h:363
#define AF_UNSPEC
Definition: winsock.h:344

Referenced by getdomainname().

◆ PrintUsage()

static void PrintUsage ( void  )
static

Definition at line 201 of file nfs41_daemon.c.

202{
203 fprintf(stderr, "Usage: nfsd.exe -d <debug_level> --noldap "
204 "--uid <non-zero value> --gid\n");
205}

Referenced by parse_cmdlineargs().

◆ ServiceStart()

VOID ServiceStart ( DWORD  argc,
LPTSTR argv 
)

Definition at line 381 of file nfs41_daemon.c.

383{
384 DWORD status = 0, len;
385 // handle to our drivers
386 HANDLE pipe;
388 nfs41_idmapper *idmapper = NULL;
389 int i;
390 nfsd_args cmd_args;
391
392 if (!check_for_files())
393 exit(0);
394 if (!parse_cmdlineargs(argc, argv, &cmd_args))
395 exit(0);
398
399#ifdef __REACTOS__
400 /* Start the kernel part */
401 {
403 if (hSvcMan)
404 {
405 HANDLE hSvc = OpenService(hSvcMan, "nfs41_driver", SERVICE_ALL_ACCESS);
406 if (hSvc)
407 {
408 SERVICE_STATUS SvcSt;
409 QueryServiceStatus(hSvc, &SvcSt);
410 if (SvcSt.dwCurrentState != SERVICE_RUNNING)
411 {
412 if (StartService(hSvc, 0, NULL))
413 {
414 dprintf(1, "NFS41 driver started\n");
415 }
416 else
417 {
418 eprintf("Driver failed to start: %d\n", GetLastError());
419 }
420 }
421 else
422 {
423 eprintf("Driver in state: %x\n", SvcSt.dwCurrentState);
424 }
425
426 CloseServiceHandle(hSvc);
427 }
428 else
429 {
430 eprintf("Failed to open service: %d\n", GetLastError());
431 }
432
433 CloseServiceHandle(hSvcMan);
434 }
435 else
436 {
437 eprintf("Failed to open service manager: %d\n", GetLastError());
438 }
439 }
440#endif
441
442#ifdef _DEBUG
443 /* dump memory leaks to stderr on exit; this requires the debug heap,
444 /* available only when built in debug mode under visual studio -cbodley */
447#pragma warning (push)
448#pragma warning (disable : 4306) /* conversion from 'int' to '_HFILE' of greater size */
450#pragma warning (pop)
451 dprintf(1, "debug mode. dumping memory leaks to stderr on exit.\n");
452#endif
453 /* acquire and store in global memory current dns domain name.
454 * needed for acls */
455 if (getdomainname())
456 exit(0);
457
459
460 if (cmd_args.ldap_enable) {
461 status = nfs41_idmap_create(&idmapper);
462 if (status) {
463 eprintf("id mapping initialization failed with %d\n", status);
464 goto out_logs;
465 }
466 }
467
469 dprintf(1, "NFS41 Daemon starting: version %d\n", NFS41D_VERSION);
470
473 0, NULL);
474 if (pipe == INVALID_HANDLE_VALUE)
475 {
476 eprintf("Unable to open upcall pipe %d\n", GetLastError());
477 goto out_idmap;
478 }
479
480 dprintf(1, "starting nfs41 mini redirector\n");
482 &NFS41D_VERSION, sizeof(DWORD), NULL, 0, (LPDWORD)&len, NULL);
483 if (!status) {
484 eprintf("IOCTL_NFS41_START failed with %d\n",
485 GetLastError());
486 goto out_pipe;
487 }
488
489#ifndef STANDALONE_NFSD
491 if (stop_event == NULL)
492 goto out_pipe;
493#endif
494
495 for (i = 0; i < MAX_NUM_THREADS; i++) {
497 idmapper, 0, &tids[i].tid);
498 if (tids[i].handle == INVALID_HANDLE_VALUE) {
500 eprintf("_beginthreadex failed %d\n", status);
501 goto out_pipe;
502 }
503 }
504#ifndef STANDALONE_NFSD
505 // report the status to the service control manager.
507 goto out_pipe;
509#else
510 //This can be changed to waiting on an array of handles and using waitformultipleobjects
511 dprintf(1, "Parent waiting for children threads\n");
512 for (i = 0; i < MAX_NUM_THREADS; i++)
514#endif
515 dprintf(1, "Parent woke up!!!!\n");
516
517out_pipe:
518 CloseHandle(pipe);
519out_idmap:
520 if (idmapper) nfs41_idmap_free(idmapper);
521out_logs:
522#ifndef STANDALONE_NFSD
524#endif
525 return;
526}
BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
Definition: service.c:240
#define _CRTDBG_MODE_FILE
Definition: crtdbg.h:24
#define _CRTDBG_LEAK_CHECK_DF
Definition: crtdbg.h:52
#define _CrtSetReportMode(t, f)
Definition: crtdbg.h:129
#define _CRT_WARN
Definition: crtdbg.h:19
#define _CRTDBG_FILE_STDERR
Definition: crtdbg.h:32
#define _CrtSetDbgFlag(f)
Definition: crtdbg.h:245
#define _CRTDBG_ALLOC_MEM_DF
Definition: crtdbg.h:47
#define _CrtSetReportFile(t, f)
Definition: crtdbg.h:130
void open_log_files()
Definition: daemon_debug.c:40
void set_debug_level(int level)
Definition: daemon_debug.c:35
void close_log_files()
Definition: daemon_debug.c:59
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
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
#define INFINITE
Definition: serial.h:102
int nfs41_idmap_create(struct idmap_context **context_out)
Definition: idmap.c:805
void nfs41_idmap_free(struct idmap_context *context)
Definition: idmap.c:867
static TfClientId tid
void nfs41_server_list_init()
Definition: nfs41_server.c:48
#define MAX_NUM_THREADS
Definition: nfs41_daemon.c:41
static unsigned int WINAPI thread_main(void *args)
Definition: nfs41_daemon.c:84
HANDLE stop_event
Definition: nfs41_daemon.c:55
static bool_t check_for_files()
Definition: nfs41_daemon.c:168
DWORD NFS41D_VERSION
Definition: nfs41_daemon.c:42
static int getdomainname()
Definition: nfs41_daemon.c:290
static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
Definition: nfs41_daemon.c:206
#define IOCTL_NFS41_START
Definition: nfs41_driver.h:43
#define NFS41_USER_DEVICE_NAME_A
Definition: nfs41_driver.h:28
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2845
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
_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 exit(n)
Definition: config.h:202
DWORD dwCurrentState
Definition: winsvc.h:100
bool_t ldap_enable
Definition: nfs41_daemon.c:164
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
PVOID HANDLE
Definition: typedefs.h:73
uint32_t * LPDWORD
Definition: typedefs.h:59
#define CreateEvent
Definition: winbase.h:3748
#define CreateFile
Definition: winbase.h:3749
#define OpenSCManager
Definition: winsvc.h:575
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define StartService
Definition: winsvc.h:585
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define OpenService
Definition: winsvc.h:576

Referenced by CmdDebugService(), and service_main().

◆ ServiceStop()

VOID ServiceStop ( )

Definition at line 156 of file nfs41_daemon.c.

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

Referenced by ControlHandler(), and service_ctrl().

◆ thread_main()

static unsigned int WINAPI thread_main ( void args)
static

Definition at line 84 of file nfs41_daemon.c.

85{
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) {
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
131
132write_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);
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));
146 }
147 if (upcall.status != NFSD_VERSION_MISMATCH)
149 }
150 CloseHandle(pipe);
151
152 return GetLastError();
153}
static int inbuf
Definition: adnsresfilter.c:73
const char * opcode2string(DWORD opcode)
Definition: daemon_debug.c:280
UINT32 uint32_t
Definition: types.h:75
#define printf
Definition: freeldr.h:97
#define UPCALL_BUF_SIZE
Definition: nfs41_const.h:42
static int map_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
Definition: nfs41_daemon.c:62
nfs41_updowncall_list upcall
Definition: nfs41_driver.c:273
#define IOCTL_NFS41_WRITE
Definition: nfs41_driver.h:49
#define IOCTL_NFS41_READ
Definition: nfs41_driver.h:48
@ NFS41_SHUTDOWN
Definition: nfs41_driver.h:70
Definition: match.c:390
void upcall_marshall(IN nfs41_upcall *upcall, OUT unsigned char *buffer, IN uint32_t length, OUT uint32_t *length_out)
Definition: upcall.c:157
int upcall_parse(IN unsigned char *buffer, IN uint32_t length, OUT nfs41_upcall *upcall)
Definition: upcall.c:75
void upcall_cleanup(IN nfs41_upcall *upcall)
Definition: upcall.c:197
int upcall_handle(IN nfs41_upcall *upcall)
Definition: upcall.c:138
void upcall_cancel(IN nfs41_upcall *upcall)
Definition: upcall.c:189
#define NFSD_VERSION_MISMATCH
Definition: upcall.h:28

Referenced by ServiceStart().

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