d23e4448e0a8266d533235e6b8080aa80024f016
[platform/upstream/krb5.git] / src / ccapi / server / win / ccs_win_pipe.c
1 /* ccapi/server/win/ccs_win_pipe.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 "assert.h"
27 #include <stdlib.h>
28 #include <malloc.h>
29
30 #include "ccs_win_pipe.h"
31 #include "cci_debugging.h"
32
33 /* Ref:
34 struct ccs_win_pipe_t {
35     char*   uuid;
36     UINT64  clientHandle;
37     }
38  */
39
40 /* ------------------------------------------------------------------------ */
41
42 struct ccs_win_pipe_t* ccs_win_pipe_new (const char* uuid, const UINT64 h) {
43
44     cc_int32                err         = ccNoError;
45     struct ccs_win_pipe_t*  out_pipe    = NULL;
46     char*                   uuidCopy    = NULL;
47
48     if (!err) {
49         if (!uuid)      {err = cci_check_error(ccErrBadParam);}
50         }
51
52     if (!err) {
53         uuidCopy = (char*)malloc(1+strlen(uuid));
54         if (!uuidCopy)  {err = cci_check_error(ccErrBadParam);}
55         strcpy(uuidCopy, uuid);
56         }
57
58     if (!err) {
59         out_pipe = (struct ccs_win_pipe_t*)malloc(sizeof(struct ccs_win_pipe_t));
60         if (!out_pipe)  {err = cci_check_error(ccErrBadParam);}
61         out_pipe->uuid          = uuidCopy;
62         out_pipe->clientHandle  = h;
63         }
64 #if 0
65     cci_debug_printf("0x%X = %s(%s, 0x%X)", out_pipe, __FUNCTION__, uuid, h);
66 #endif
67     return out_pipe;
68     }
69
70 /* ------------------------------------------------------------------------ */
71
72 cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe,
73                             const WIN_PIPE* in_pipe) {
74
75     *out_pipe =
76         ccs_win_pipe_new(
77             ccs_win_pipe_getUuid  (in_pipe),
78             ccs_win_pipe_getHandle(in_pipe) );
79
80     return (*out_pipe) ? ccNoError : ccErrBadParam;
81     }
82
83 /* ------------------------------------------------------------------------ */
84
85 cc_int32 ccs_win_pipe_release(const WIN_PIPE* in_pipe) {
86
87     cc_int32 err = ccNoError;
88
89     if (!ccs_win_pipe_valid(in_pipe))   {err = cci_check_error(ccErrBadParam);}
90
91     if (!err) {
92         if (!in_pipe->uuid) free(in_pipe->uuid);
93         if (!in_pipe)       free(in_pipe);
94         }
95
96     return err;
97     }
98
99 /* ------------------------------------------------------------------------ */
100
101 cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe) {
102
103     if (!in_pipe) {
104         cci_check_error(ccErrBadParam);
105         return FALSE;
106         }
107
108     if (!in_pipe->uuid) {
109         cci_check_error(ccErrBadParam);
110         return FALSE;
111         }
112
113     return TRUE;
114     }
115
116 /* ------------------------------------------------------------------------ */
117
118 cc_int32 ccs_win_pipe_compare    (const WIN_PIPE*   in_pipe_1,
119                                   const WIN_PIPE*   in_pipe_2,
120                                   cc_uint32         *out_equal) {
121
122     cc_int32 err    = ccNoError;
123     int      seq    = 0;
124     *out_equal      = FALSE;
125
126     if (!ccs_win_pipe_valid(in_pipe_1)) {err = cci_check_error(ccErrBadParam);}
127     if (!ccs_win_pipe_valid(in_pipe_2)) {err = cci_check_error(ccErrBadParam);}
128     if (!out_equal)                     {err = cci_check_error(ccErrBadParam);}
129
130     /* A disconnect doesn't have a tls* with it -- only the uuid.  SO only
131        compare the uuids.
132      */
133     if (!err) {
134         seq = strcmp(   ccs_win_pipe_getUuid(in_pipe_1),
135                         ccs_win_pipe_getUuid(in_pipe_2) );
136         *out_equal = (seq == 0);
137         }
138
139     return err;
140     }
141
142 /* ------------------------------------------------------------------------ */
143
144 char* ccs_win_pipe_getUuid    (const WIN_PIPE* in_pipe) {
145
146     char*   result = NULL;
147
148     if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
149     else                              {result = in_pipe->uuid;}
150
151     return result;
152     }
153
154 /* ------------------------------------------------------------------------ */
155
156 UINT64 ccs_win_pipe_getHandle  (const WIN_PIPE* in_pipe) {
157
158     UINT64 result = 0;
159
160     if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
161     else                              {result = in_pipe->clientHandle;}
162
163     return result;
164     }