MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mbsasl.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbutil/mbsasl.h,v 1.15 2017/01/12 14:44:05 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #ifndef mbsasl_h
33 #define mbsasl_h
34 
35 #ifdef HAVE_SASL2
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40 
41 /* used for negotiation buffers; should be enough for every known mechanism */
42 #define MBDYN_SASL_BUFSIZE 1024
43 
44 #define MBDYN_SASL_SERVICE "mbdyn"
45 #define MBDYN_SASL_CONFFILE "mbdyn"
46 
47 struct mbdyn_sasl_t {
48  int use_sasl;
49 #define MBDYN_SASL_NONE 0
50 #define MBDYN_SASL_SERVER 1
51 #define MBDYN_SASL_CLIENT 2
52  unsigned sasl_flags;
53 #define MBDYN_SASL_FLAG_NONE 0x0000
54 #define MBDYN_SASL_FLAG_CRITICAL 0x0001
55 #define MBDYN_SASL_FLAG_USERAUTHZ 0x0002
56 #define MBDYN_SASL_FLAG_INTERACT 0x0004
57  unsigned long sasl_usleep; /* 0: forever */
58 
59  const char *sasl_mech; /* preferred; NULL -> all available */
60  const char *sasl_user; /* if NULL, prompt */
61  const char *sasl_cred; /* if NULL, prompt */
62  const char *sasl_realm; /* if NULL, prompt? */
63  const char *sasl_authz; /* if NULL, prompt? */
64 
65  const char *sasl_hostname; /* if NULL? */
66  const char *sasl_local_ip; /* NULL is legal */
67  const char *sasl_remote_ip;/* NULL is legal */
68 };
69 
70 #define MBDYN_SASL_INIT \
71  { MBDYN_SASL_NONE, MBDYN_SASL_FLAG_NONE, 0L, \
72  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
73 
74 /* init client data; urtnet_sasl is filled by mbdyn_sasl_parse_args() */
75 extern int
76 mbdyn_sasl_client_init(struct mbdyn_sasl_t *urtnet_sasl);
77 
78 /* init server data; urtnet_sasl is filled by mbdyn_sasl_parse_args() */
79 extern int
80 mbdyn_sasl_server_init(struct mbdyn_sasl_t *urtnet_sasl);
81 
82 /* init data; server/client is decided by urtnet_sasl;
83  * urtnet_sasl is filled by mbdyn_sasl_parse_args() */
84 extern int
85 mbdyn_sasl_init(struct mbdyn_sasl_t *urtnet_sasl);
86 
87 /* cleanup sasl session */
88 extern int
89 mbdyn_sasl_fini(void);
90 
91 /* perform client auth on sock; urtnet_sasl is filled
92  * by mbdyn_sasl_parse_args() and client must be init'ed
93  * by mbdyn_sasl_client_init() */
94 extern int
95 mbdyn_sasl_client_auth(int sock, struct sockaddr *bindaddr,
96  struct mbdyn_sasl_t *urtnet_sasl);
97 
98 /* perform server auth on sock; urtnet_sasl is filled
99  * by mbdyn_sasl_parse_args() and server must be init'ed
100  * by mbdyn_sasl_server_init() */
101 extern int
102 mbdyn_sasl_server_auth(int sock, struct sockaddr *bindaddr,
103  struct mbdyn_sasl_t *urtnet_sasl);
104 
105 /* perform auth on sock; urtnet_sasl is filled
106  * by mbdyn_sasl_parse_args() and server/client must be init'ed
107  * by mbdyn_sasl_init() */
108 extern int
109 mbdyn_sasl_auth(int sock, struct sockaddr *bindaddr,
110  struct mbdyn_sasl_t *urtnet_sasl);
111 
112 /* validates data; server/client is decided by urtnet_sasl;
113  * urtnet_sasl is filled by mbdyn_sasl_parse_args() */
114 extern int
115 mbdyn_sasl_validate(struct mbdyn_sasl_t *urtnet_sasl);
116 
117 #define MBDYN_SASL_OPTIONS "a:f:h:i:l:m:r:s:u:w:"
118 
119 /* parses one arg in "opt" based on value in "val";
120  * use MBDYN_SASL_OPTIONS in getopt for direct parsing of options,
121  * or use "x:" (x arbitrary option) and then feed
122  * mbdyn_sasl_parse_args() with opt = optarg[0] and val = &optarg[2]
123  * after checking that optarg[1] == '=' */
124 extern int
125 mbdyn_sasl_parse_args(int opt, const char *val,
126  struct mbdyn_sasl_t *urtnet_sasl);
127 
128 /* negotiates the entire set of sockets available and alredy bound,
129  * but still in blocking mode ... */
130 extern int
131 mbdyn_sasl_negotiate(struct mbdyn_sasl_t *urtnet_sasl);
132 
133 extern sasl_log_t *log_server_f;
134 extern sasl_log_t *log_client_f;
135 extern sasl_getsimple_t *get_user_f;
136 extern sasl_getsimple_t *get_authname_f;
137 extern sasl_getsecret_t *get_secret_f;
138 extern sasl_getrealm_t *get_realm_f;
139 
140 #ifdef __cplusplus
141 }
142 #endif /* __cplusplus */
143 
144 #endif /* HAVE_SASL2 */
145 
146 #endif /* mbsasl_h */