1 /* NFSv4.1 client for Windows
2  * Copyright � 2012 The Regents of the University of Michigan
3  *
4  * Olga Kornievskaia <aglo@umich.edu>
5  * Casey Bodley <cbodley@umich.edu>
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2.1 of the License, or (at
10  * your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * without any warranty; without even the implied warranty of merchantability
14  * or fitness for a particular purpose.  See the GNU Lesser General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  */
21 
22 #ifndef _TIRPC_AUTH_GSS_H
23 #define _TIRPC_AUTH_GSS_H
24 
25 #include <rpc/clnt.h>
26 #define SECURITY_WIN32
27 #include <security.h>
28 
29 /* RPCSEC_SSPI control procedures. */
30 typedef enum {
31 	RPCSEC_SSPI_DATA = 0,
32 	RPCSEC_SSPI_INIT = 1,
33 	RPCSEC_SSPI_CONTINUE_INIT = 2,
34 	RPCSEC_SSPI_DESTROY = 3
35 } rpc_sspi_proc_t;
36 
37 /* RPCSEC_SSPI services. */
38 typedef enum {
39 	RPCSEC_SSPI_SVC_NONE = 1,
40 	RPCSEC_SSPI_SVC_INTEGRITY = 2,
41 	RPCSEC_SSPI_SVC_PRIVACY = 3
42 } rpc_sspi_svc_t;
43 
44 #define RPCSEC_SSPI_VERSION	1
45 
46 #define sspi_name_t SEC_CHAR *
47 #define sspi_qop_t uint32_t
48 
49 typedef struct _sspi_OID_desc {
50     int length;
51     void *elements;
52 } sspi_OID_desc, *sspi_OID;
53 
54 typedef struct _sspi_buffer_desc {
55     int length;
56     void *value;
57 } sspi_buffer_desc, *sspi_buffer_t;
58 
59 #define SSPI_C_NO_NAME ((sspi_name_t) NULL)
60 #define SSPI_C_NO_BUFFER ((sspi_buffer_t) NULL)
61 #define SSPI_C_NO_CONTEXT ((PCtxtHandle) NULL)
62 
63 /* RPCSEC_SSPI security triple. */
64 struct rpc_sspi_sec {
65 	sspi_OID        mech;		/* mechanism */
66 	uint32_t        qop;		/* quality of protection */
67 	rpc_sspi_svc_t	svc;		/* service */
68     CredHandle      cred;       /* cred handle */
69 	u_int		    req_flags;	/* req flags for init_sec_context */
70     TimeStamp       expiry;
71 };
72 
73 /* Credentials. */
74 struct rpc_sspi_cred {
75 	u_int		        gc_v;		/* version */
76 	rpc_sspi_proc_t	    gc_proc;	/* control procedure */
77 	u_int		        gc_seq;		/* sequence number */
78 	rpc_sspi_svc_t	    gc_svc;		/* service */
79 	sspi_buffer_desc	gc_ctx;		/* server's returned context handle */
80 };
81 
82 /* Context creation response. */
83 struct rpc_sspi_init_res {
84 	sspi_buffer_desc    gr_ctx;		/* context handle */
85 	u_int			    gr_major;	/* major status */
86 	u_int			    gr_minor;	/* minor status */
87 	u_int			    gr_win;		/* sequence window */
88 	sspi_buffer_desc    gr_token;	/* token */
89 };
90 
91 /* Prototypes. */
92 __BEGIN_DECLS
93 bool_t xdr_rpc_sspi_cred(XDR *xdrs, struct rpc_sspi_cred *p);
94 bool_t xdr_rpc_sspi_init_args(XDR *xdrs, sspi_buffer_desc *p);
95 bool_t xdr_rpc_sspi_init_res(XDR *xdrs, struct rpc_sspi_init_res *p);
96 bool_t xdr_rpc_sspi_data(XDR *xdrs, xdrproc_t xdr_func, caddr_t xdr_ptr,
97                          PCtxtHandle ctx, sspi_qop_t qop,
98                          rpc_sspi_svc_t svc, u_int seq);
99 AUTH *authsspi_create(CLIENT *, sspi_name_t, struct rpc_sspi_sec *);
100 AUTH *authsspi_create_default(CLIENT *, char *, int);
101 bool_t authsspi_service(AUTH *auth, int svc);
102 uint32_t sspi_get_mic(void *ctx, u_int qop, u_int seq,
103                       sspi_buffer_desc *bufin, sspi_buffer_desc *bufout);
104 uint32_t sspi_verify_mic(void *ctx, u_int seq, sspi_buffer_desc *bufin,
105                          sspi_buffer_desc *bufout, u_int *qop_state);
106 uint32_t sspi_wrap(void *ctx, u_int seq, sspi_buffer_desc *bufin,
107                          sspi_buffer_desc *bufout, u_int *conf_state);
108 uint32_t sspi_unwrap(void *ctx, u_int seq, sspi_buffer_desc *bufin,
109                      sspi_buffer_desc *bufout, u_int *conf_state,
110                      u_int *qop_state);
111 void sspi_release_buffer(sspi_buffer_desc *buf);
112 uint32_t sspi_import_name(sspi_buffer_desc *name_in, sspi_name_t *name_out);
113 
114 void log_debug(const char *fmt, ...);
115 void log_status(char *m, uint32_t major, uint32_t minor);
116 void log_hexdump(bool_t on, const u_char *title, const u_char *buf, int len, int offset);
117 
118 __END_DECLS
119 
120 #endif /* !_TIRPC_AUTH_GSS_H */
121