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