ReactOS  0.4.14-dev-604-gcfdd483
authsspi_prot.c File Reference
#include <wintirpc.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/auth_sspi.h>
#include <rpc/rpc.h>
#include <security.h>
Include dependency graph for authsspi_prot.c:

Go to the source code of this file.

Functions

bool_t xdr_rpc_sspi_cred (XDR *xdrs, struct rpc_sspi_cred *p)
 
bool_t xdr_rpc_sspi_init_args (XDR *xdrs, sspi_buffer_desc *p)
 
bool_t xdr_rpc_sspi_init_res (XDR *xdrs, struct rpc_sspi_init_res *p)
 
bool_t xdr_rpc_sspi_wrap_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, PCtxtHandle ctx, sspi_qop_t qop, rpc_sspi_svc_t svc, u_int seq)
 
bool_t xdr_rpc_sspi_unwrap_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, PCtxtHandle ctx, sspi_qop_t qop, rpc_sspi_svc_t svc, u_int seq)
 
bool_t xdr_rpc_sspi_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, PCtxtHandle ctx, sspi_qop_t qop, rpc_sspi_svc_t svc, u_int seq)
 

Function Documentation

◆ xdr_rpc_sspi_cred()

bool_t xdr_rpc_sspi_cred ( XDR xdrs,
struct rpc_sspi_cred p 
)

Definition at line 34 of file authsspi_prot.c.

35 {
36  bool_t xdr_stat;
37 
38  xdr_stat = (xdr_u_int(xdrs, &p->gc_v) &&
39  xdr_enum(xdrs, (enum_t *)&p->gc_proc) &&
40  xdr_u_int(xdrs, &p->gc_seq) &&
41  xdr_enum(xdrs, (enum_t *)&p->gc_svc) &&
42  xdr_bytes(xdrs, (char **)&p->gc_ctx.value,
43  (u_int *)&p->gc_ctx.length, MAX_AUTH_BYTES));
44 
45  log_debug("xdr_rpc_gss_cred: %s %s "
46  "(v %d, proc %d, seq %d, svc %d, ctx %p:%d)",
47  (xdrs->x_op == XDR_ENCODE) ? "encode" : "decode",
48  (xdr_stat == TRUE) ? "success" : "failure",
49  p->gc_v, p->gc_proc, p->gc_seq, p->gc_svc,
50  p->gc_ctx.value, p->gc_ctx.length);
51 
52  return (xdr_stat);
53 }
#define MAX_AUTH_BYTES
Definition: auth.h:77
#define TRUE
Definition: types.h:120
int32_t bool_t
Definition: types.h:101
bool_t xdr_u_int(XDR *xdrs, u_int *up)
Definition: xdr.c:133
void log_debug(const char *fmt,...)
Definition: auth_sspi.c:977
bool_t xdr_enum(XDR *xdrs, enum_t *ep)
Definition: xdr.c:458
enum xdr_op x_op
Definition: xdr.h:104
int32_t enum_t
Definition: types.h:102
Definition: xdr.h:85
UINT32 u_int
Definition: types.h:82
bool_t xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
Definition: xdr.c:536
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by authsspi_marshal().

◆ xdr_rpc_sspi_data()

bool_t xdr_rpc_sspi_data ( XDR xdrs,
xdrproc_t  xdr_func,
caddr_t  xdr_ptr,
PCtxtHandle  ctx,
sspi_qop_t  qop,
rpc_sspi_svc_t  svc,
u_int  seq 
)

Definition at line 288 of file authsspi_prot.c.

291 {
292  switch (xdrs->x_op) {
293 
294  case XDR_ENCODE:
295  return (xdr_rpc_sspi_wrap_data(xdrs, xdr_func, xdr_ptr,
296  ctx, qop, svc, seq));
297  case XDR_DECODE:
298  return (xdr_rpc_sspi_unwrap_data(xdrs, xdr_func, xdr_ptr,
299  ctx, qop, svc, seq));
300  case XDR_FREE:
301  return (TRUE);
302  }
303  return (FALSE);
304 }
#define TRUE
Definition: types.h:120
bool_t xdr_rpc_sspi_wrap_data(XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, PCtxtHandle ctx, sspi_qop_t qop, rpc_sspi_svc_t svc, u_int seq)
Definition: authsspi_prot.c:96
bool_t xdr_rpc_sspi_unwrap_data(XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, PCtxtHandle ctx, sspi_qop_t qop, rpc_sspi_svc_t svc, u_int seq)
enum xdr_op x_op
Definition: xdr.h:104
Definition: xdr.h:85
Definition: xdr.h:87
Definition: xdr.h:86

Referenced by authsspi_unwrap(), and authsspi_wrap().

◆ xdr_rpc_sspi_init_args()

bool_t xdr_rpc_sspi_init_args ( XDR xdrs,
sspi_buffer_desc p 
)

Definition at line 56 of file authsspi_prot.c.

57 {
58  bool_t xdr_stat;
59 
60  xdr_stat = xdr_bytes(xdrs, (char **)&p->value,
61  (u_int *)&p->length, (u_int)(-1));
62 
63  log_debug("xdr_rpc_gss_init_args: %s %s (token %p:%d)",
64  (xdrs->x_op == XDR_ENCODE) ? "encode" : "decode",
65  (xdr_stat == TRUE) ? "success" : "failure",
66  p->value, p->length);
67 
68  return (xdr_stat);
69 }
#define TRUE
Definition: types.h:120
int32_t bool_t
Definition: types.h:101
void log_debug(const char *fmt,...)
Definition: auth_sspi.c:977
enum xdr_op x_op
Definition: xdr.h:104
Definition: xdr.h:85
UINT32 u_int
Definition: types.h:82
bool_t xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
Definition: xdr.c:536
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by authsspi_refresh().

◆ xdr_rpc_sspi_init_res()

bool_t xdr_rpc_sspi_init_res ( XDR xdrs,
struct rpc_sspi_init_res p 
)

Definition at line 72 of file authsspi_prot.c.

73 {
74  bool_t xdr_stat;
75 
76  xdr_stat = (xdr_bytes(xdrs, (char **)&p->gr_ctx.value,
77  (u_int *)&p->gr_ctx.length, MAX_NETOBJ_SZ) &&
78  xdr_u_int(xdrs, &p->gr_major) &&
79  xdr_u_int(xdrs, &p->gr_minor) &&
80  xdr_u_int(xdrs, &p->gr_win) &&
81  xdr_bytes(xdrs, (char **)&p->gr_token.value,
82  (u_int *)&p->gr_token.length, (u_int)(-1)));
83 
84  log_debug("xdr_rpc_gss_init_res %s %s "
85  "(ctx %p:%d, maj %d, min %d, win %d, token %p:%d)",
86  (xdrs->x_op == XDR_ENCODE) ? "encode" : "decode",
87  (xdr_stat == TRUE) ? "success" : "failure",
88  p->gr_ctx.value, p->gr_ctx.length,
89  p->gr_major, p->gr_minor, p->gr_win,
90  p->gr_token.value, p->gr_token.length);
91 
92  return (xdr_stat);
93 }
#define TRUE
Definition: types.h:120
int32_t bool_t
Definition: types.h:101
bool_t xdr_u_int(XDR *xdrs, u_int *up)
Definition: xdr.c:133
void log_debug(const char *fmt,...)
Definition: auth_sspi.c:977
enum xdr_op x_op
Definition: xdr.h:104
#define MAX_NETOBJ_SZ
Definition: xdr.h:331
Definition: xdr.h:85
UINT32 u_int
Definition: types.h:82
bool_t xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
Definition: xdr.c:536
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by authsspi_refresh().

◆ xdr_rpc_sspi_unwrap_data()

bool_t xdr_rpc_sspi_unwrap_data ( XDR xdrs,
xdrproc_t  xdr_func,
caddr_t  xdr_ptr,
PCtxtHandle  ctx,
sspi_qop_t  qop,
rpc_sspi_svc_t  svc,
u_int  seq 
)

Definition at line 176 of file authsspi_prot.c.

179 {
180  XDR tmpxdrs;
181  sspi_buffer_desc databuf, wrapbuf;
182  uint32_t maj_stat;
183  u_int seq_num, qop_state;
184  int conf_state;
185  bool_t xdr_stat;
186 
187  log_debug("in xdr_rpc_sspi_unwrap_data()");
188 
189  if (xdr_func == (xdrproc_t)xdr_void || xdr_ptr == NULL)
190  return (TRUE);
191 
192  memset(&databuf, 0, sizeof(databuf));
193  memset(&wrapbuf, 0, sizeof(wrapbuf));
194 
195  if (svc == RPCSEC_SSPI_SVC_INTEGRITY) {
196  /* Decode databody_integ. */
197  if (!xdr_bytes(xdrs, (char **)&databuf.value, (u_int *)&databuf.length,
198  (u_int)-1)) {
199  log_debug("xdr_rpc_sspi_unwrap_data: xdr decode databody_integ failed");
200  return (FALSE);
201  }
202  /* Decode checksum. */
203  if (!xdr_bytes(xdrs, (char **)&wrapbuf.value, (u_int *)&wrapbuf.length,
204  MAX_NETOBJ_SZ)) {
205 #if 0
206  gss_release_buffer(&min_stat, &databuf);
207 #else
208  sspi_release_buffer(&databuf);
209 #endif
210  log_debug("xdr_rpc_sspi_unwrap_data: xdr decode checksum failed");
211  return (FALSE);
212  }
213  /* Verify checksum and QOP. */
214 #if 0
215  maj_stat = gss_verify_mic(&min_stat, ctx, &databuf,
216  &wrapbuf, &qop_state);
217 #else
218  maj_stat = sspi_verify_mic(ctx, seq, &databuf, &wrapbuf, &qop_state);
219 #endif
220 #if 0
221  gss_release_buffer(&min_stat, &wrapbuf);
222 #else
223  sspi_release_buffer(&wrapbuf);
224 #endif
225 
226  if (maj_stat != SEC_E_OK) {
227 #if 0
228  gss_release_buffer(&min_stat, &databuf);
229 #else
230  sspi_release_buffer(&databuf);
231 #endif
232  log_debug("xdr_rpc_sspi_unwrap_data: sspi_verify_mic "
233  "failed with %x", maj_stat);
234  return (FALSE);
235  }
236  }
237  else if (svc == RPCSEC_SSPI_SVC_PRIVACY) {
238  /* Decode databody_priv. */
239  if (!xdr_bytes(xdrs, (char **)&wrapbuf.value, (u_int *)&wrapbuf.length,
240  (u_int)-1)) {
241  log_debug("xdr_rpc_sspi_unwrap_data: xdr decode databody_priv failed");
242  return (FALSE);
243  }
244  /* Decrypt databody. */
245 #if 0
246  maj_stat = gss_unwrap(&min_stat, ctx, &wrapbuf, &databuf,
247  &conf_state, &qop_state);
248 #else
249  maj_stat = sspi_unwrap(ctx, seq, &wrapbuf, &databuf, &conf_state, &qop_state);
250 #endif
251 #if 0
252  gss_release_buffer(&min_stat, &wrapbuf);
253 #else
254  sspi_release_buffer(&wrapbuf);
255 #endif
256  /* Verify encryption and QOP. */
257  if (maj_stat != SEC_E_OK) {
258 #if 0
259  gss_release_buffer(&min_stat, &databuf);
260 #else
261  sspi_release_buffer(&databuf);
262 #endif
263  log_debug("xdr_rpc_sspi_unwrap_data: sspi_unwrap failed with %x", maj_stat);
264  return (FALSE);
265  }
266  }
267  /* Decode rpc_gss_data_t (sequence number + arguments). */
268  xdrmem_create(&tmpxdrs, databuf.value, databuf.length, XDR_DECODE);
269  xdr_stat = (xdr_u_int(&tmpxdrs, &seq_num) &&
270  (*xdr_func)(&tmpxdrs, xdr_ptr));
271  XDR_DESTROY(&tmpxdrs);
272 #if 0
273  gss_release_buffer(&min_stat, &databuf);
274 #else
275  sspi_release_buffer(&databuf);
276 #endif
277  /* Verify sequence number. */
278  if (xdr_stat == TRUE && seq_num != seq) {
279  log_debug("wrong sequence number in databody received %d expected %d",
280  seq_num, seq);
281  return (FALSE);
282  }
283 
284  return (xdr_stat);
285 }
#define TRUE
Definition: types.h:120
int32_t bool_t
Definition: types.h:101
uint32_t sspi_verify_mic(PCtxtHandle ctx, u_int seq, sspi_buffer_desc *bufin, sspi_buffer_desc *bufout, u_int *qop_state)
Definition: auth_sspi.c:699
Definition: xdr.h:103
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
uint32_t sspi_unwrap(PCtxtHandle ctx, u_int seq, sspi_buffer_desc *bufin, sspi_buffer_desc *bufout, u_int *conf_state, u_int *qop_state)
Definition: auth_sspi.c:810
smooth NULL
Definition: ftsmooth.c:416
bool_t xdr_u_int(XDR *xdrs, u_int *up)
Definition: xdr.c:133
void log_debug(const char *fmt,...)
Definition: auth_sspi.c:977
#define MAX_NETOBJ_SZ
Definition: xdr.h:331
#define SEC_E_OK
Definition: winerror.h:2356
bool_t xdr_void(void)
Definition: xdr.c:92
void sspi_release_buffer(sspi_buffer_desc *buf)
Definition: auth_sspi.c:727
UINT32 u_int
Definition: types.h:82
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
UINT32 uint32_t
Definition: types.h:75
Definition: xdr.h:86
bool_t xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
Definition: xdr.c:536
#define memset(x, y, z)
Definition: compat.h:39
#define XDR_DESTROY(xdrs)
Definition: xdr.h:214

Referenced by xdr_rpc_sspi_data().

◆ xdr_rpc_sspi_wrap_data()

bool_t xdr_rpc_sspi_wrap_data ( XDR xdrs,
xdrproc_t  xdr_func,
caddr_t  xdr_ptr,
PCtxtHandle  ctx,
sspi_qop_t  qop,
rpc_sspi_svc_t  svc,
u_int  seq 
)

Definition at line 96 of file authsspi_prot.c.

99 {
100  sspi_buffer_desc databuf, wrapbuf;
101  uint32_t maj_stat;
102  int start, end, conf_state;
103  bool_t xdr_stat;
104 
105  log_debug("in xdr_rpc_sspi_wrap_data()");
106 
107  /* Skip databody length. */
108  start = XDR_GETPOS(xdrs);
109  XDR_SETPOS(xdrs, start + 4);
110 
111  /* Marshal rpc_gss_data_t (sequence number + arguments). */
112  if (!xdr_u_int(xdrs, &seq) || !(*xdr_func)(xdrs, xdr_ptr))
113  return (FALSE);
114  end = XDR_GETPOS(xdrs);
115 
116  /* Set databuf to marshalled rpc_gss_data_t. */
117  databuf.length = end - start - 4;
118  XDR_SETPOS(xdrs, start + 4);
119  databuf.value = XDR_INLINE(xdrs, databuf.length);
120 
121  xdr_stat = FALSE;
122 
123  if (svc == RPCSEC_SSPI_SVC_INTEGRITY) {
124  /* Marshal databody_integ length. */
125  XDR_SETPOS(xdrs, start);
126  if (!xdr_u_int(xdrs, (u_int *)&databuf.length))
127  return (FALSE);
128 
129  /* Checksum rpc_gss_data_t. */
130 #if 0
131  maj_stat = gss_get_mic(&min_stat, ctx, qop,
132  &databuf, &wrapbuf);
133 #else
134  maj_stat = sspi_get_mic(ctx, 0, seq, &databuf, &wrapbuf);
135 #endif
136  if (maj_stat != SEC_E_OK) {
137  log_debug("xdr_rpc_sspi_wrap_data: sspi_get_mic failed with %x", maj_stat);
138  return (FALSE);
139  }
140  /* Marshal checksum. */
141  XDR_SETPOS(xdrs, end);
142  xdr_stat = xdr_bytes(xdrs, (char **)&wrapbuf.value,
143  (u_int *)&wrapbuf.length, (u_int)-1);
144 #if 0
145  gss_release_buffer(&min_stat, &wrapbuf);
146 #else
147  sspi_release_buffer(&wrapbuf);
148 #endif
149  }
150  else if (svc == RPCSEC_SSPI_SVC_PRIVACY) {
151  /* Encrypt rpc_gss_data_t. */
152 #if 0
153  maj_stat = gss_wrap(&min_stat, ctx, TRUE, qop, &databuf,
154  &conf_state, &wrapbuf);
155 #else
156  maj_stat = sspi_wrap(ctx, 0, &databuf, &wrapbuf, &conf_state);
157 #endif
158  if (maj_stat != SEC_E_OK) {
159  log_debug("xdr_rpc_sspi_wrap_data: sspi_wrap failed with %x", maj_stat);
160  return (FALSE);
161  }
162  /* Marshal databody_priv. */
163  XDR_SETPOS(xdrs, start);
164  xdr_stat = xdr_bytes(xdrs, (char **)&wrapbuf.value,
165  (u_int *)&wrapbuf.length, (u_int)-1);
166 #if 0
167  gss_release_buffer(&min_stat, &wrapbuf);
168 #else
169  sspi_release_buffer(&wrapbuf);
170 #endif
171  }
172  return (xdr_stat);
173 }
#define TRUE
Definition: types.h:120
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
int32_t bool_t
Definition: types.h:101
GLuint GLuint end
Definition: gl.h:1545
uint32_t sspi_get_mic(PCtxtHandle ctx, u_int qop, u_int seq, sspi_buffer_desc *bufin, sspi_buffer_desc *bufout)
Definition: auth_sspi.c:659
bool_t xdr_u_int(XDR *xdrs, u_int *up)
Definition: xdr.c:133
void log_debug(const char *fmt,...)
Definition: auth_sspi.c:977
uint32_t sspi_wrap(PCtxtHandle ctx, u_int seq, sspi_buffer_desc *bufin, sspi_buffer_desc *bufout, u_int *conf_state)
Definition: auth_sspi.c:750
#define XDR_INLINE(xdrs, len)
Definition: xdr.h:209
#define SEC_E_OK
Definition: winerror.h:2356
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
void sspi_release_buffer(sspi_buffer_desc *buf)
Definition: auth_sspi.c:727
UINT32 u_int
Definition: types.h:82
GLuint start
Definition: gl.h:1545
UINT32 uint32_t
Definition: types.h:75
bool_t xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
Definition: xdr.c:536

Referenced by xdr_rpc_sspi_data().