xref: /freebsd/crypto/krb5/src/ccapi/server/win/ccs_request_proc.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
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 
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 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 
49     status = (rpcmsg != CCMSG_REQUEST) && (rpcmsg != CCMSG_PING);
50 
51     if (!status) {
52         status = krb5int_ipc_stream_new (&stream);  /* Create a stream for the request data */
53         }
54 
55     if (!status) {                          /* Put the data into the stream */
56         status = krb5int_ipc_stream_write (stream, pbRequest, lenRequest);
57         }
58 
59     pipe = ccs_win_pipe_new(pszUUID, *p);
60     worklist_add(rpcmsg, pipe, stream, serverStartTime);
61     *return_status = status;
62     }
63 
64 
ccs_rpc_connect(const long rpcmsg,const char tspHandle[],const char * pszUUID,long * return_status)65 void ccs_rpc_connect(
66     const long  rpcmsg,             /* Message type */
67     const char  tspHandle[],        /* Client's tspdata* */
68     const char* pszUUID,            /* Data buffer */
69     long*       return_status ) {   /* Return code */
70 
71     UINT64*     p       = (UINT64*)(tspHandle);
72     WIN_PIPE*   pipe    = ccs_win_pipe_new(pszUUID, *p);
73 
74     worklist_add(   rpcmsg,
75                     pipe,
76                     NULL,               /* No payload with connect request */
77                     (const time_t)0 );  /* No server session number with connect request */
78     }
79 
80 
81 // 'Authentication' is client setting a value in a file and the server
82 //   returning that value plus one.
ccs_authenticate(const CC_CHAR * name)83 CC_UINT32 ccs_authenticate(const CC_CHAR* name) {
84     HANDLE      hMap    = 0;
85     PDWORD      pvalue  = 0;
86     CC_UINT32   result  = 0;
87     DWORD       status  = 0;
88 
89     hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, (LPSTR)name);
90     status  = !hMap;
91 
92     if (!status) {
93         pvalue = (PDWORD)MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0);
94         status = !pvalue;
95         }
96 
97     if (!status) {
98         *pvalue += 1;
99         result = *pvalue;
100         }
101 
102     if (pvalue) {
103         UnmapViewOfFile(pvalue);
104         }
105 
106     if (hMap) CloseHandle(hMap);
107     return result;
108     }
109