ReactOS  0.4.14-dev-50-g13bb5e2
dispatcher.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SECURITY_STATUS fork_helper (PNegoHelper *new_helper, const char *prog, char *const argv[]) DECLSPEC_HIDDEN
 
SECURITY_STATUS run_helper (PNegoHelper helper, char *buffer, unsigned int max_buflen, int *buflen) DECLSPEC_HIDDEN
 
void cleanup_helper (PNegoHelper helper) DECLSPEC_HIDDEN
 
void check_version (PNegoHelper helper) DECLSPEC_HIDDEN
 

Function Documentation

◆ check_version()

void check_version ( PNegoHelper  helper)

Definition at line 408 of file dispatcher.c.

409 {
410  char temp[80];
411  char *newline;
412  int major = 0, minor = 0, micro = 0, ret;
413 
414  TRACE("Checking version of helper\n");
415  if(helper != NULL)
416  {
417  int len = read(helper->pipe_in, temp, sizeof(temp)-1);
418  if (len > 8)
419  {
420  if((newline = memchr(temp, '\n', len)) != NULL)
421  *newline = '\0';
422  else
423  temp[len] = 0;
424 
425  TRACE("Exact version is %s\n", debugstr_a(temp));
426  ret = sscanf(temp, "Version %d.%d.%d", &major, &minor, &micro);
427  if(ret != 3)
428  {
429  ERR("Failed to get the helper version.\n");
430  helper->major = helper->minor = helper->micro = -1;
431  }
432  else
433  {
434  TRACE("Version recognized: %d.%d.%d\n", major, minor, micro);
435  helper->major = major;
436  helper->minor = minor;
437  helper->micro = micro;
438  }
439  }
440  }
441 }
int major
Definition: ntlm.h:30
#define memchr(s, c, n)
Definition: mkisofs.h:875
int minor
Definition: ntlm.h:31
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define TRACE(s)
Definition: solgame.cpp:4
int pipe_in
Definition: ntlm.h:28
#define debugstr_a
Definition: kernel32.h:31
int ret
GLenum GLsizei len
Definition: glext.h:6722
#define ERR(fmt,...)
Definition: debug.h:109
int micro
Definition: ntlm.h:32
static calc_node_t temp
Definition: rpn_ieee.c:38
#define major(rdev)
Definition: propsheet.cpp:879
static void newline(int)
Definition: ppl.yy.c:3768
#define minor(rdev)
Definition: propsheet.cpp:880
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

◆ cleanup_helper()

void cleanup_helper ( PNegoHelper  helper)

Definition at line 377 of file dispatcher.c.

378 {
379 
380  TRACE("Killing helper %p\n", helper);
381  if(helper == NULL)
382  return;
383 
384  HeapFree(GetProcessHeap(), 0, helper->com_buf);
385  HeapFree(GetProcessHeap(), 0, helper->session_key);
386 
387  /* closing stdin will terminate ntlm_auth */
388  close(helper->pipe_out);
389  close(helper->pipe_in);
390 
391 #ifndef __REACTOS__
392 
393 #ifdef HAVE_FORK
394  if (helper->helper_pid > 0) /* reap child */
395  {
396  pid_t wret;
397  do {
398  wret = waitpid(helper->helper_pid, NULL, 0);
399  } while (wret < 0 && errno == EINTR);
400  }
401 #endif
402 
403 #endif
404 
405  HeapFree(GetProcessHeap(), 0, helper);
406 }
pid_t helper_pid
Definition: ntlm.h:23
int pipe_out
Definition: ntlm.h:29
#define EINTR
Definition: acclib.h:80
DWORD pid_t
Definition: types.h:91
int errno
char * com_buf
Definition: ntlm.h:33
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
int pipe_in
Definition: ntlm.h:28
#define close
Definition: acwin.h:98
BYTE * session_key
Definition: ntlm.h:36
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by ntlm_AcceptSecurityContext(), ntlm_DeleteSecurityContext(), ntlm_InitializeSecurityContextW(), and SECUR32_initNTLMSP().

◆ fork_helper()

SECURITY_STATUS fork_helper ( PNegoHelper new_helper,
const char prog,
char *const  argv[] 
)

Definition at line 76 of file dispatcher.c.

78 {
79  int pipe_in[2];
80  int pipe_out[2];
81 #ifdef __REACTOS__
82  HANDLE hPipe;
84  STARTUPINFOA si;
85  char* cmdline;
86 #endif
87  int i;
88  PNegoHelper helper;
89 
90  TRACE("%s ", debugstr_a(prog));
91  for(i = 0; argv[i] != NULL; ++i)
92  {
93  TRACE("%s ", debugstr_a(argv[i]));
94  }
95  TRACE("\n");
96 
97 #ifndef __REACTOS__
98 
99 #ifdef HAVE_PIPE2
100  if (pipe2( pipe_in, O_CLOEXEC ) < 0 )
101 #endif
102  {
103  if( pipe(pipe_in) < 0 ) return SEC_E_INTERNAL_ERROR;
104  fcntl( pipe_in[0], F_SETFD, FD_CLOEXEC );
105  fcntl( pipe_in[1], F_SETFD, FD_CLOEXEC );
106  }
107 #ifdef HAVE_PIPE2
108  if (pipe2( pipe_out, O_CLOEXEC ) < 0 )
109 #endif
110  {
111  if( pipe(pipe_out) < 0 )
112  {
113  close(pipe_in[0]);
114  close(pipe_in[1]);
115  return SEC_E_INTERNAL_ERROR;
116  }
117  fcntl( pipe_out[0], F_SETFD, FD_CLOEXEC );
118  fcntl( pipe_out[1], F_SETFD, FD_CLOEXEC );
119  }
120 
121 #else
122 
123  if (_pipe(pipe_in, 0, _O_BINARY /* _O_TEXT */ | _O_NOINHERIT) < 0)
124  {
125  return SEC_E_INTERNAL_ERROR;
126  }
127 
128  if (_pipe(pipe_out, 0, _O_BINARY /* _O_TEXT */ | _O_NOINHERIT) < 0)
129  {
130  close(pipe_in[0]);
131  close(pipe_in[1]);
132  return SEC_E_INTERNAL_ERROR;
133  }
134 
135 #endif
136 
137  if (!(helper = HeapAlloc(GetProcessHeap(),0, sizeof(NegoHelper))))
138  {
139  close(pipe_in[0]);
140  close(pipe_in[1]);
141  close(pipe_out[0]);
142  close(pipe_out[1]);
144  }
145 
146 #ifndef __REACTOS__
147  helper->helper_pid = fork();
148 #else
149 
151  if (!cmdline)
152  {
153  close(pipe_in[0]);
154  close(pipe_in[1]);
155  close(pipe_out[0]);
156  close(pipe_out[1]);
157  HeapFree( GetProcessHeap(), 0, helper );
159  }
160 
161  ZeroMemory(&pi, sizeof(pi));
162  ZeroMemory(&si, sizeof(si));
163  si.cb = sizeof(si);
164 
166 
167  /* The reading side of the pipe is STDIN for this process */
168  hPipe = (HANDLE)_get_osfhandle(pipe_out[0]);
170  si.hStdInput = hPipe;
171 
172  /* The writing side of the pipe is STDOUT for this process */
173  hPipe = (HANDLE)_get_osfhandle(pipe_in[1]);
175  si.hStdOutput = hPipe;
176  si.hStdError = hPipe;
177 
179  {
180  /* We fail just afterwards */
181  helper->helper_pid = (HANDLE)-1;
182  }
183  else
184  {
185  helper->helper_pid = pi.hProcess;
186  CloseHandle(pi.hThread);
187  CloseHandle(pi.hProcess);
188  }
189 
191 
192 #endif
193 
194 #ifndef __REACTOS__
195  if(helper->helper_pid == -1)
196 #else
197  if(helper->helper_pid == (HANDLE)-1)
198 #endif
199  {
200  close(pipe_in[0]);
201  close(pipe_in[1]);
202  close(pipe_out[0]);
203  close(pipe_out[1]);
204  HeapFree( GetProcessHeap(), 0, helper );
205  return SEC_E_INTERNAL_ERROR;
206  }
207 
208 #ifndef __REACTOS__
209  if(helper->helper_pid == 0)
210  {
211  /* We're in the child now */
212  dup2(pipe_out[0], 0);
213  close(pipe_out[0]);
214  close(pipe_out[1]);
215 
216  dup2(pipe_in[1], 1);
217  close(pipe_in[0]);
218  close(pipe_in[1]);
219 
220  execvp(prog, argv);
221 
222  /* Whoops, we shouldn't get here. Big badaboom.*/
223  write(STDOUT_FILENO, "BH\n", 3);
224  _exit(1);
225  }
226  else
227 #endif
228  {
229  *new_helper = helper;
230  helper->major = helper->minor = helper->micro = -1;
231  helper->com_buf = NULL;
232  helper->com_buf_size = 0;
233  helper->com_buf_offset = 0;
234  helper->session_key = NULL;
235  helper->neg_flags = 0;
236  helper->crypt.ntlm.a4i = NULL;
237  helper->crypt.ntlm2.send_a4i = NULL;
238  helper->crypt.ntlm2.recv_a4i = NULL;
239  helper->crypt.ntlm2.send_sign_key = NULL;
240  helper->crypt.ntlm2.send_seal_key = NULL;
241  helper->crypt.ntlm2.recv_sign_key = NULL;
242  helper->crypt.ntlm2.recv_seal_key = NULL;
243  helper->pipe_in = pipe_in[0]; // Keep in(read)
244  close(pipe_in[1]); // Close in(write)
245  helper->pipe_out = pipe_out[1]; // Keep out(write)
246  close(pipe_out[0]); // Close out(read)
247  }
248 
249  return SEC_E_OK;
250 }
#define SEC_E_INTERNAL_ERROR
Definition: winerror.h:2913
int major
Definition: ntlm.h:30
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
pid_t helper_pid
Definition: ntlm.h:23
char * prog
Definition: isohybrid.c:47
int pipe_out
Definition: ntlm.h:29
#define ZeroMemory
Definition: winbase.h:1635
DWORD dwFlags
Definition: winbase.h:807
TCHAR * cmdline
Definition: stretchblt.cpp:32
#define argv
Definition: mplay32.c:18
#define CREATE_NO_WINDOW
Definition: winbase.h:195
#define write
Definition: acwin.h:97
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
#define _O_NOINHERIT
Definition: cabinet.h:45
int minor
Definition: ntlm.h:31
_CRTIMP intptr_t __cdecl _get_osfhandle(_In_ int _FileHandle)
#define SEC_E_INSUFFICIENT_MEMORY
Definition: winerror.h:2909
char * com_buf
Definition: ntlm.h:33
smooth NULL
Definition: ftsmooth.c:416
#define HANDLE_FLAG_INHERIT
Definition: winbase.h:261
#define STDOUT_FILENO
Definition: syshdrs.h:89
void _exit(int exitcode)
Definition: _exit.c:25
_Check_return_ _CRTIMP int __cdecl dup2(_In_ int _FileHandleSrc, _In_ int _FileHandleDst)
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
int com_buf_offset
Definition: ntlm.h:35
#define TRACE(s)
Definition: solgame.cpp:4
DWORD cb
Definition: winbase.h:796
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
int pipe_in
Definition: ntlm.h:28
#define debugstr_a
Definition: kernel32.h:31
#define FD_CLOEXEC
Definition: fcntl.h:102
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4742
_CRTIMP intptr_t __cdecl execvp(_In_z_ const char *_Filename, _In_z_ char *const _ArgList[])
struct _NegoHelper::@521 crypt
PVOID HANDLE
Definition: typedefs.h:71
ULONG neg_flags
Definition: ntlm.h:37
HANDLE hStdOutput
Definition: winbase.h:812
static DWORD pi
Definition: protocol.c:150
#define _O_BINARY
Definition: cabinet.h:51
#define close
Definition: acwin.h:98
#define SEC_E_OK
Definition: winerror.h:2356
BYTE * session_key
Definition: ntlm.h:36
int micro
Definition: ntlm.h:32
HANDLE hStdInput
Definition: winbase.h:811
char * flatten_cmdline(const char *prog, char *const argv[])
Definition: dispatcher.c:40
int com_buf_size
Definition: ntlm.h:34
BOOL WINAPI SetHandleInformation(IN HANDLE hObject, IN DWORD dwMask, IN DWORD dwFlags)
Definition: handle.c:78
HANDLE hStdError
Definition: winbase.h:813
#define HeapFree(x, y, z)
Definition: compat.h:394
_Check_return_ _CRTIMP int __cdecl _pipe(_Inout_updates_(2) int *_PtHandles, _In_ unsigned int _PipeSize, _In_ int _TextMode)

Referenced by ntlm_AcceptSecurityContext(), ntlm_InitializeSecurityContextW(), and SECUR32_initNTLMSP().

◆ run_helper()

SECURITY_STATUS run_helper ( PNegoHelper  helper,
char buffer,
unsigned int  max_buflen,
int buflen 
)

Definition at line 331 of file dispatcher.c.

333 {
334  int offset_len;
335  SECURITY_STATUS sec_status = SEC_E_OK;
336 
337  TRACE("In helper: sending %s\n", debugstr_a(buffer));
338 
339  /* buffer + '\n' */
340  write(helper->pipe_out, buffer, lstrlenA(buffer));
341  write(helper->pipe_out, "\n", 1);
342 
343  if((sec_status = read_line(helper, &offset_len)) != SEC_E_OK)
344  {
345  return sec_status;
346  }
347 
348  TRACE("In helper: received %s\n", debugstr_a(helper->com_buf));
349  *buflen = lstrlenA(helper->com_buf);
350 
351  if( *buflen > max_buflen)
352  {
353  ERR("Buffer size too small(%d given, %d required) dropping data!\n",
354  max_buflen, *buflen);
355  return SEC_E_BUFFER_TOO_SMALL;
356  }
357 
358  if( *buflen < 2 )
359  {
360  return SEC_E_ILLEGAL_MESSAGE;
361  }
362 
363  /* We only get ERR if the input size is too big. On a GENSEC error,
364  * ntlm_auth will return BH */
365  if(strncmp(helper->com_buf, "ERR", 3) == 0)
366  {
367  return SEC_E_INVALID_TOKEN;
368  }
369 
370  memcpy(buffer, helper->com_buf, *buflen+1);
371 
372  sec_status = preserve_unused(helper, offset_len);
373 
374  return sec_status;
375 }
int pipe_out
Definition: ntlm.h:29
GLuint buffer
Definition: glext.h:5915
#define write
Definition: acwin.h:97
char * com_buf
Definition: ntlm.h:33
#define SEC_E_ILLEGAL_MESSAGE
Definition: winerror.h:2943
static SECURITY_STATUS read_line(PNegoHelper helper, int *offset_len)
Definition: dispatcher.c:252
LONG SECURITY_STATUS
Definition: sspi.h:34
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define SEC_E_INVALID_TOKEN
Definition: winerror.h:2917
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define SEC_E_OK
Definition: winerror.h:2356
#define ERR(fmt,...)
Definition: debug.h:109
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define SEC_E_BUFFER_TOO_SMALL
Definition: winerror.h:2937
static SECURITY_STATUS preserve_unused(PNegoHelper helper, int offset_len)
Definition: dispatcher.c:312

Referenced by ntlm_AcceptSecurityContext(), and ntlm_InitializeSecurityContextW().