rpcss_main.c 4.54 KB
Newer Older
1
/*
2
 * Copyright 2001, Ove Kåven, TransGaming Technologies Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 * Copyright 2002 Greg Turner
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *
 * ---- rpcss_main.c:
 *   Initialize and start serving requests.  Bail if rpcss already is
 *   running.
 *
 * ---- RPCSS.EXE:
 *   
 *   Wine needs a server whose role is somewhat like that
 *   of rpcss.exe in windows.  This is not a clone of
 *   windows rpcss at all.  It has been given the same name, however,
 *   to provide for the possibility that at some point in the future, 
 *   it may become interface compatible with the "real" rpcss.exe on
 *   Windows.
 *
 * ---- KNOWN BUGS / TODO:
 *
 *   o Service hooks are unimplemented (if you bother to implement
 *     these, also implement net.exe, at least for "net start" and
 *     "net stop" (should be pretty easy I guess, assuming the rest
 *     of the services API infrastructure works.
 *
39 40
 *   o There is a looming problem regarding listening on privileged
 *     ports.  We will need to be able to coexist with SAMBA, and be able
41 42 43 44 45 46
 *     to function without running winelib code as root.  This may
 *     take some doing, including significant reconceptualization of the
 *     role of rpcss.exe in wine.
 */

#include <stdio.h>
47
#include <stdarg.h>
48 49 50
#include <limits.h>
#include <assert.h>

51 52
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
53 54
#include "windef.h"
#include "winbase.h"
55
#include "winnt.h"
56
#include "irot.h"
57
#include "epm.h"
58 59 60 61 62

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(ole);

63 64
static HANDLE exit_event;

65
extern HANDLE CDECL __wine_make_process_system(void);
66

67
static BOOL RPCSS_Initialize(void)
68
{
69 70
  static unsigned short irot_protseq[] = IROT_PROTSEQ;
  static unsigned short irot_endpoint[] = IROT_ENDPOINT;
71 72
  static unsigned short epm_protseq[] = {'n','c','a','c','n','_','n','p',0};
  static unsigned short epm_endpoint[] = {'\\','p','i','p','e','\\','e','p','m','a','p','p','e','r',0};
73 74
  static unsigned short epm_protseq_lrpc[] = {'n','c','a','l','r','p','c',0};
  static unsigned short epm_endpoint_lrpc[] = {'e','p','m','a','p','p','e','r',0};
75 76
  RPC_STATUS status;

77 78
  WINE_TRACE("\n");

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  status = RpcServerRegisterIf(epm_v3_0_s_ifspec, NULL, NULL);
  if (status != RPC_S_OK)
    return status;
  status = RpcServerRegisterIf(Irot_v0_2_s_ifspec, NULL, NULL);
  if (status != RPC_S_OK)
  {
    RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
    return FALSE;
  }

  status = RpcServerUseProtseqEpW(epm_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
                                  epm_endpoint, NULL);
  if (status != RPC_S_OK)
    goto fail;

94 95 96 97 98
  status = RpcServerUseProtseqEpW(epm_protseq_lrpc, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
                                  epm_endpoint_lrpc, NULL);
  if (status != RPC_S_OK)
      goto fail;

99 100
  status = RpcServerUseProtseqEpW(irot_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
                                  irot_endpoint, NULL);
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  if (status != RPC_S_OK)
    goto fail;

  status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE);
  if (status != RPC_S_OK)
    goto fail;

  exit_event = __wine_make_process_system();

  return TRUE;

fail:
  RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
  RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, FALSE);
  return FALSE;
116 117 118 119
}

/* returns false if we discover at the last moment that we
   aren't ready to terminate */
120
static BOOL RPCSS_Shutdown(void)
121
{
122
  RpcMgmtStopServerListening(NULL);
123
  RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, TRUE);
124 125
  RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, TRUE);

126 127
  CloseHandle(exit_event);

128 129 130 131 132 133 134
  return TRUE;
}

int main( int argc, char **argv )
{
  /* 
   * We are invoked as a standard executable; we act in a
135 136
   * "lazy" manner.  We register our interfaces and endpoints, and hang around
   * until we all user processes exit, and then silently terminate.
137 138 139
   */

  if (RPCSS_Initialize()) {
140
    WaitForSingleObject(exit_event, INFINITE);
141
    RPCSS_Shutdown();
142 143 144 145
  }

  return 0;
}