ReactOS  0.4.13-dev-698-g77671f0
authgss_prot.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/auth_gss.h>
#include <rpc/rpc.h>
#include <gssapi/gssapi.h>
Include dependency graph for authgss_prot.c:

Go to the source code of this file.

Functions

bool_t xdr_rpc_gss_cred (XDR *xdrs, struct rpc_gss_cred *p)
 
bool_t xdr_rpc_gss_init_args (XDR *xdrs, gss_buffer_desc *p)
 
bool_t xdr_rpc_gss_init_res (XDR *xdrs, struct rpc_gss_init_res *p)
 
bool_t xdr_rpc_gss_wrap_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, gss_ctx_id_t ctx, gss_qop_t qop, rpc_gss_svc_t svc, u_int seq)
 
bool_t xdr_rpc_gss_unwrap_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, gss_ctx_id_t ctx, gss_qop_t qop, rpc_gss_svc_t svc, u_int seq)
 
bool_t xdr_rpc_gss_data (XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, gss_ctx_id_t ctx, gss_qop_t qop, rpc_gss_svc_t svc, u_int seq)
 
void log_debug (const char *fmt,...)
 
void log_status (char *m, OM_uint32 maj_stat, OM_uint32 min_stat)
 
void log_hexdump (const u_char *buf, int len, int offset)
 

Function Documentation

◆ log_debug()

void log_debug ( const char fmt,
  ... 
)

◆ log_hexdump()

void log_hexdump ( const u_char buf,
int  len,
int  offset 
)

Definition at line 350 of file authgss_prot.c.

351 {
352 }

◆ log_status()

◆ xdr_rpc_gss_cred()

bool_t xdr_rpc_gss_cred ( XDR xdrs,
struct rpc_gss_cred p 
)

Definition at line 48 of file authgss_prot.c.

49 {
50  bool_t xdr_stat;
51 
52  xdr_stat = (xdr_u_int(xdrs, &p->gc_v) &&
53  xdr_enum(xdrs, (enum_t *)&p->gc_proc) &&
54  xdr_u_int(xdrs, &p->gc_seq) &&
55  xdr_enum(xdrs, (enum_t *)&p->gc_svc) &&
56  xdr_bytes(xdrs, (char **)&p->gc_ctx.value,
57  (u_int *)&p->gc_ctx.length, MAX_AUTH_BYTES));
58 
59  log_debug("xdr_rpc_gss_cred: %s %s "
60  "(v %d, proc %d, seq %d, svc %d, ctx %p:%d)",
61  (xdrs->x_op == XDR_ENCODE) ? "encode" : "decode",
62  (xdr_stat == TRUE) ? "success" : "failure",
63  p->gc_v, p->gc_proc, p->gc_seq, p->gc_svc,
64  p->gc_ctx.value, p->gc_ctx.length);
65 
66  return (xdr_stat);
67 }
#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
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
void log_debug(const char *fmt,...)
Definition: authgss_prot.c:340
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 _svcauth_gss(), and authgss_marshal().

◆ xdr_rpc_gss_data()

bool_t xdr_rpc_gss_data ( XDR xdrs,
xdrproc_t  xdr_func,
caddr_t  xdr_ptr,
gss_ctx_id_t  ctx,
gss_qop_t  qop,
rpc_gss_svc_t  svc,
u_int  seq 
)

Definition at line 251 of file authgss_prot.c.

254 {
255  switch (xdrs->x_op) {
256 
257  case XDR_ENCODE:
258  return (xdr_rpc_gss_wrap_data(xdrs, xdr_func, xdr_ptr,
259  ctx, qop, svc, seq));
260  case XDR_DECODE:
261  return (xdr_rpc_gss_unwrap_data(xdrs, xdr_func, xdr_ptr,
262  ctx, qop,svc, seq));
263  case XDR_FREE:
264  return (TRUE);
265  }
266  return (FALSE);
267 }
#define TRUE
Definition: types.h:120
bool_t xdr_rpc_gss_wrap_data(XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, gss_ctx_id_t ctx, gss_qop_t qop, rpc_gss_svc_t svc, u_int seq)
Definition: authgss_prot.c:110
enum xdr_op x_op
Definition: xdr.h:104
Definition: xdr.h:85
bool_t xdr_rpc_gss_unwrap_data(XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr, gss_ctx_id_t ctx, gss_qop_t qop, rpc_gss_svc_t svc, u_int seq)
Definition: authgss_prot.c:172
Definition: xdr.h:87
Definition: xdr.h:86

Referenced by authgss_unwrap(), authgss_wrap(), svcauth_gss_unwrap(), and svcauth_gss_wrap().

◆ xdr_rpc_gss_init_args()

bool_t xdr_rpc_gss_init_args ( XDR xdrs,
gss_buffer_desc *  p 
)

Definition at line 70 of file authgss_prot.c.

71 {
72  bool_t xdr_stat;
73 
74  xdr_stat = xdr_bytes(xdrs, (char **)&p->value,
75  (u_int *)&p->length, MAX_NETOBJ_SZ);
76 
77  log_debug("xdr_rpc_gss_init_args: %s %s (token %p:%d)",
78  (xdrs->x_op == XDR_ENCODE) ? "encode" : "decode",
79  (xdr_stat == TRUE) ? "success" : "failure",
80  p->value, p->length);
81 
82  return (xdr_stat);
83 }
#define TRUE
Definition: types.h:120
int32_t bool_t
Definition: types.h:101
enum xdr_op x_op
Definition: xdr.h:104
void log_debug(const char *fmt,...)
Definition: authgss_prot.c:340
#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 authgss_refresh(), and svcauth_gss_accept_sec_context().

◆ xdr_rpc_gss_init_res()

bool_t xdr_rpc_gss_init_res ( XDR xdrs,
struct rpc_gss_init_res p 
)

Definition at line 86 of file authgss_prot.c.

87 {
88  bool_t xdr_stat;
89 
90  xdr_stat = (xdr_bytes(xdrs, (char **)&p->gr_ctx.value,
91  (u_int *)&p->gr_ctx.length, MAX_NETOBJ_SZ) &&
92  xdr_u_int(xdrs, &p->gr_major) &&
93  xdr_u_int(xdrs, &p->gr_minor) &&
94  xdr_u_int(xdrs, &p->gr_win) &&
95  xdr_bytes(xdrs, (char **)&p->gr_token.value,
96  (u_int *)&p->gr_token.length, MAX_NETOBJ_SZ));
97 
98  log_debug("xdr_rpc_gss_init_res %s %s "
99  "(ctx %p:%d, maj %d, min %d, win %d, token %p:%d)",
100  (xdrs->x_op == XDR_ENCODE) ? "encode" : "decode",
101  (xdr_stat == TRUE) ? "success" : "failure",
102  p->gr_ctx.value, p->gr_ctx.length,
103  p->gr_major, p->gr_minor, p->gr_win,
104  p->gr_token.value, p->gr_token.length);
105 
106  return (xdr_stat);
107 }
#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
enum xdr_op x_op
Definition: xdr.h:104
void log_debug(const char *fmt,...)
Definition: authgss_prot.c:340
#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 _svcauth_gss(), and authgss_refresh().

◆ xdr_rpc_gss_unwrap_data()

bool_t xdr_rpc_gss_unwrap_data ( XDR xdrs,
xdrproc_t  xdr_func,
caddr_t  xdr_ptr,
gss_ctx_id_t  ctx,
gss_qop_t  qop,
rpc_gss_svc_t  svc,
u_int  seq 
)

Definition at line 172 of file authgss_prot.c.

175 {
176  XDR tmpxdrs;
177  gss_buffer_desc databuf, wrapbuf;
178  OM_uint32 maj_stat, min_stat;
179  u_int seq_num, qop_state;
180  int conf_state;
181  bool_t xdr_stat;
182 
183  if (xdr_func == (xdrproc_t)xdr_void || xdr_ptr == NULL)
184  return (TRUE);
185 
186  memset(&databuf, 0, sizeof(databuf));
187  memset(&wrapbuf, 0, sizeof(wrapbuf));
188 
189  if (svc == RPCSEC_GSS_SVC_INTEGRITY) {
190  /* Decode databody_integ. */
191  if (!xdr_bytes(xdrs, (char **)&databuf.value, (u_int *)&databuf.length,
192  MAX_NETOBJ_SZ)) {
193  log_debug("xdr decode databody_integ failed");
194  return (FALSE);
195  }
196  /* Decode checksum. */
197  if (!xdr_bytes(xdrs, (char **)&wrapbuf.value, (u_int *)&wrapbuf.length,
198  MAX_NETOBJ_SZ)) {
199  gss_release_buffer(&min_stat, &databuf);
200  log_debug("xdr decode checksum failed");
201  return (FALSE);
202  }
203  /* Verify checksum and QOP. */
204  maj_stat = gss_verify_mic(&min_stat, ctx, &databuf,
205  &wrapbuf, &qop_state);
206  gss_release_buffer(&min_stat, &wrapbuf);
207 
208  if (maj_stat != GSS_S_COMPLETE || qop_state != qop) {
209  gss_release_buffer(&min_stat, &databuf);
210  log_status("gss_verify_mic", maj_stat, min_stat);
211  return (FALSE);
212  }
213  }
214  else if (svc == RPCSEC_GSS_SVC_PRIVACY) {
215  /* Decode databody_priv. */
216  if (!xdr_bytes(xdrs, (char **)&wrapbuf.value, (u_int *)&wrapbuf.length,
217  MAX_NETOBJ_SZ)) {
218  log_debug("xdr decode databody_priv failed");
219  return (FALSE);
220  }
221  /* Decrypt databody. */
222  maj_stat = gss_unwrap(&min_stat, ctx, &wrapbuf, &databuf,
223  &conf_state, &qop_state);
224 
225  gss_release_buffer(&min_stat, &wrapbuf);
226 
227  /* Verify encryption and QOP. */
228  if (maj_stat != GSS_S_COMPLETE || qop_state != qop ||
229  conf_state != TRUE) {
230  gss_release_buffer(&min_stat, &databuf);
231  log_status("gss_unwrap", maj_stat, min_stat);
232  return (FALSE);
233  }
234  }
235  /* Decode rpc_gss_data_t (sequence number + arguments). */
236  xdrmem_create(&tmpxdrs, databuf.value, databuf.length, XDR_DECODE);
237  xdr_stat = (xdr_u_int(&tmpxdrs, &seq_num) &&
238  (*xdr_func)(&tmpxdrs, xdr_ptr));
239  XDR_DESTROY(&tmpxdrs);
240  gss_release_buffer(&min_stat, &databuf);
241 
242  /* Verify sequence number. */
243  if (xdr_stat == TRUE && seq_num != seq) {
244  log_debug("wrong sequence number in databody");
245  return (FALSE);
246  }
247  return (xdr_stat);
248 }
#define TRUE
Definition: types.h:120
int32_t bool_t
Definition: types.h:101
Definition: xdr.h:103
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
void log_status(char *m, OM_uint32 maj_stat, OM_uint32 min_stat)
Definition: authgss_prot.c:345
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: authgss_prot.c:340
#define MAX_NETOBJ_SZ
Definition: xdr.h:331
bool_t xdr_void(void)
Definition: xdr.c:92
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
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_gss_data().

◆ xdr_rpc_gss_wrap_data()

bool_t xdr_rpc_gss_wrap_data ( XDR xdrs,
xdrproc_t  xdr_func,
caddr_t  xdr_ptr,
gss_ctx_id_t  ctx,
gss_qop_t  qop,
rpc_gss_svc_t  svc,
u_int  seq 
)

Definition at line 110 of file authgss_prot.c.

113 {
114  gss_buffer_desc databuf, wrapbuf;
115  OM_uint32 maj_stat, min_stat;
116  int start, end, conf_state;
117  bool_t xdr_stat;
118 
119  /* Skip databody length. */
120  start = XDR_GETPOS(xdrs);
121  XDR_SETPOS(xdrs, start + 4);
122 
123  /* Marshal rpc_gss_data_t (sequence number + arguments). */
124  if (!xdr_u_int(xdrs, &seq) || !(*xdr_func)(xdrs, xdr_ptr))
125  return (FALSE);
126  end = XDR_GETPOS(xdrs);
127 
128  /* Set databuf to marshalled rpc_gss_data_t. */
129  databuf.length = end - start - 4;
130  XDR_SETPOS(xdrs, start + 4);
131  databuf.value = XDR_INLINE(xdrs, databuf.length);
132 
133  xdr_stat = FALSE;
134 
135  if (svc == RPCSEC_GSS_SVC_INTEGRITY) {
136  /* Marshal databody_integ length. */
137  XDR_SETPOS(xdrs, start);
138  if (!xdr_u_int(xdrs, (u_int *)&databuf.length))
139  return (FALSE);
140 
141  /* Checksum rpc_gss_data_t. */
142  maj_stat = gss_get_mic(&min_stat, ctx, qop,
143  &databuf, &wrapbuf);
144  if (maj_stat != GSS_S_COMPLETE) {
145  log_debug("gss_get_mic failed");
146  return (FALSE);
147  }
148  /* Marshal checksum. */
149  XDR_SETPOS(xdrs, end);
150  xdr_stat = xdr_bytes(xdrs, (char **)&wrapbuf.value,
151  (u_int *)&wrapbuf.length, MAX_NETOBJ_SZ);
152  gss_release_buffer(&min_stat, &wrapbuf);
153  }
154  else if (svc == RPCSEC_GSS_SVC_PRIVACY) {
155  /* Encrypt rpc_gss_data_t. */
156  maj_stat = gss_wrap(&min_stat, ctx, TRUE, qop, &databuf,
157  &conf_state, &wrapbuf);
158  if (maj_stat != GSS_S_COMPLETE) {
159  log_status("gss_wrap", maj_stat, min_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, MAX_NETOBJ_SZ);
166  gss_release_buffer(&min_stat, &wrapbuf);
167  }
168  return (xdr_stat);
169 }
#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
void log_status(char *m, OM_uint32 maj_stat, OM_uint32 min_stat)
Definition: authgss_prot.c:345
bool_t xdr_u_int(XDR *xdrs, u_int *up)
Definition: xdr.c:133
void log_debug(const char *fmt,...)
Definition: authgss_prot.c:340
#define MAX_NETOBJ_SZ
Definition: xdr.h:331
#define XDR_INLINE(xdrs, len)
Definition: xdr.h:209
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
UINT32 u_int
Definition: types.h:82
GLuint start
Definition: gl.h:1545
bool_t xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize)
Definition: xdr.c:536

Referenced by xdr_rpc_gss_data().