xref: /freebsd/crypto/krb5/src/ccapi/server/win/ccs_request_proc.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* ccapi/server/win/ccs_request_proc.c */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * Copyright 2008 Massachusetts Institute of Technology.
4*7f2fe78bSCy Schubert  * All Rights Reserved.
5*7f2fe78bSCy Schubert  *
6*7f2fe78bSCy Schubert  * Export of this software from the United States of America may
7*7f2fe78bSCy Schubert  * require a specific license from the United States Government.
8*7f2fe78bSCy Schubert  * It is the responsibility of any person or organization contemplating
9*7f2fe78bSCy Schubert  * export to obtain such a license before exporting.
10*7f2fe78bSCy Schubert  *
11*7f2fe78bSCy Schubert  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12*7f2fe78bSCy Schubert  * distribute this software and its documentation for any purpose and
13*7f2fe78bSCy Schubert  * without fee is hereby granted, provided that the above copyright
14*7f2fe78bSCy Schubert  * notice appear in all copies and that both that copyright notice and
15*7f2fe78bSCy Schubert  * this permission notice appear in supporting documentation, and that
16*7f2fe78bSCy Schubert  * the name of M.I.T. not be used in advertising or publicity pertaining
17*7f2fe78bSCy Schubert  * to distribution of the software without specific, written prior
18*7f2fe78bSCy Schubert  * permission.  Furthermore if you modify this software you must label
19*7f2fe78bSCy Schubert  * your software as modified software and not distribute it in such a
20*7f2fe78bSCy Schubert  * fashion that it might be confused with the original M.I.T. software.
21*7f2fe78bSCy Schubert  * M.I.T. makes no representations about the suitability of
22*7f2fe78bSCy Schubert  * this software for any purpose.  It is provided "as is" without express
23*7f2fe78bSCy Schubert  * or implied warranty.
24*7f2fe78bSCy Schubert  */
25*7f2fe78bSCy Schubert 
26*7f2fe78bSCy Schubert #include <stdlib.h>
27*7f2fe78bSCy Schubert #include <stdio.h>
28*7f2fe78bSCy Schubert 
29*7f2fe78bSCy Schubert #include "ccs_request.h"    // header file generated by MIDL compiler
30*7f2fe78bSCy Schubert #include "cci_debugging.h"
31*7f2fe78bSCy Schubert #include "WorkQueue.h"
32*7f2fe78bSCy Schubert #include "win-utils.h"
33*7f2fe78bSCy Schubert #include "ccs_win_pipe.h"
34*7f2fe78bSCy Schubert 
ccs_rpc_request(const long rpcmsg,const char tspHandle[],const char * pszUUID,const long lenRequest,const char pbRequest[],const long serverStartTime,long * return_status)35*7f2fe78bSCy Schubert void ccs_rpc_request(
36*7f2fe78bSCy Schubert     const long  rpcmsg,             /* Message type */
37*7f2fe78bSCy Schubert     const char  tspHandle[],        /* Client's tspdata* */
38*7f2fe78bSCy Schubert     const char* pszUUID,            /* Where client will listen for the reply */
39*7f2fe78bSCy Schubert     const long  lenRequest,         /* Length of buffer */
40*7f2fe78bSCy Schubert     const char  pbRequest[],        /* Data buffer */
41*7f2fe78bSCy Schubert     const long  serverStartTime,    /* Which server session we're talking to */
42*7f2fe78bSCy Schubert     long*       return_status ) {   /* Return code */
43*7f2fe78bSCy Schubert 
44*7f2fe78bSCy Schubert     cc_int32        status  = 0;
45*7f2fe78bSCy Schubert     k5_ipc_stream   stream;
46*7f2fe78bSCy Schubert     UINT64*         p       = (UINT64*)(tspHandle);
47*7f2fe78bSCy Schubert     WIN_PIPE*       pipe    = NULL;
48*7f2fe78bSCy Schubert 
49*7f2fe78bSCy Schubert     status = (rpcmsg != CCMSG_REQUEST) && (rpcmsg != CCMSG_PING);
50*7f2fe78bSCy Schubert 
51*7f2fe78bSCy Schubert     if (!status) {
52*7f2fe78bSCy Schubert         status = krb5int_ipc_stream_new (&stream);  /* Create a stream for the request data */
53*7f2fe78bSCy Schubert         }
54*7f2fe78bSCy Schubert 
55*7f2fe78bSCy Schubert     if (!status) {                          /* Put the data into the stream */
56*7f2fe78bSCy Schubert         status = krb5int_ipc_stream_write (stream, pbRequest, lenRequest);
57*7f2fe78bSCy Schubert         }
58*7f2fe78bSCy Schubert 
59*7f2fe78bSCy Schubert     pipe = ccs_win_pipe_new(pszUUID, *p);
60*7f2fe78bSCy Schubert     worklist_add(rpcmsg, pipe, stream, serverStartTime);
61*7f2fe78bSCy Schubert     *return_status = status;
62*7f2fe78bSCy Schubert     }
63*7f2fe78bSCy Schubert 
64*7f2fe78bSCy Schubert 
ccs_rpc_connect(const long rpcmsg,const char tspHandle[],const char * pszUUID,long * return_status)65*7f2fe78bSCy Schubert void ccs_rpc_connect(
66*7f2fe78bSCy Schubert     const long  rpcmsg,             /* Message type */
67*7f2fe78bSCy Schubert     const char  tspHandle[],        /* Client's tspdata* */
68*7f2fe78bSCy Schubert     const char* pszUUID,            /* Data buffer */
69*7f2fe78bSCy Schubert     long*       return_status ) {   /* Return code */
70*7f2fe78bSCy Schubert 
71*7f2fe78bSCy Schubert     UINT64*     p       = (UINT64*)(tspHandle);
72*7f2fe78bSCy Schubert     WIN_PIPE*   pipe    = ccs_win_pipe_new(pszUUID, *p);
73*7f2fe78bSCy Schubert 
74*7f2fe78bSCy Schubert     worklist_add(   rpcmsg,
75*7f2fe78bSCy Schubert                     pipe,
76*7f2fe78bSCy Schubert                     NULL,               /* No payload with connect request */
77*7f2fe78bSCy Schubert                     (const time_t)0 );  /* No server session number with connect request */
78*7f2fe78bSCy Schubert     }
79*7f2fe78bSCy Schubert 
80*7f2fe78bSCy Schubert 
81*7f2fe78bSCy Schubert // 'Authentication' is client setting a value in a file and the server
82*7f2fe78bSCy Schubert //   returning that value plus one.
ccs_authenticate(const CC_CHAR * name)83*7f2fe78bSCy Schubert CC_UINT32 ccs_authenticate(const CC_CHAR* name) {
84*7f2fe78bSCy Schubert     HANDLE      hMap    = 0;
85*7f2fe78bSCy Schubert     PDWORD      pvalue  = 0;
86*7f2fe78bSCy Schubert     CC_UINT32   result  = 0;
87*7f2fe78bSCy Schubert     DWORD       status  = 0;
88*7f2fe78bSCy Schubert 
89*7f2fe78bSCy Schubert     hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, (LPSTR)name);
90*7f2fe78bSCy Schubert     status  = !hMap;
91*7f2fe78bSCy Schubert 
92*7f2fe78bSCy Schubert     if (!status) {
93*7f2fe78bSCy Schubert         pvalue = (PDWORD)MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0);
94*7f2fe78bSCy Schubert         status = !pvalue;
95*7f2fe78bSCy Schubert         }
96*7f2fe78bSCy Schubert 
97*7f2fe78bSCy Schubert     if (!status) {
98*7f2fe78bSCy Schubert         *pvalue += 1;
99*7f2fe78bSCy Schubert         result = *pvalue;
100*7f2fe78bSCy Schubert         }
101*7f2fe78bSCy Schubert 
102*7f2fe78bSCy Schubert     if (pvalue) {
103*7f2fe78bSCy Schubert         UnmapViewOfFile(pvalue);
104*7f2fe78bSCy Schubert         }
105*7f2fe78bSCy Schubert 
106*7f2fe78bSCy Schubert     if (hMap) CloseHandle(hMap);
107*7f2fe78bSCy Schubert     return result;
108*7f2fe78bSCy Schubert     }
109