ctld.c (263719) | ctld.c (263720) |
---|---|
1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: stable/10/usr.sbin/ctld/ctld.c 263719 2014-03-25 12:00:05Z trasz $ | 29 * $FreeBSD: stable/10/usr.sbin/ctld/ctld.c 263720 2014-03-25 12:01:55Z trasz $ |
30 */ 31 32#include <sys/types.h> 33#include <sys/time.h> 34#include <sys/socket.h> 35#include <sys/wait.h> 36#include <netinet/in.h> 37#include <assert.h> --- 106 unchanged lines hidden (view full) --- 144 TAILQ_FOREACH(auth, &ag->ag_auths, a_next) { 145 if (strcmp(auth->a_user, user) == 0) 146 return (auth); 147 } 148 149 return (NULL); 150} 151 | 30 */ 31 32#include <sys/types.h> 33#include <sys/time.h> 34#include <sys/socket.h> 35#include <sys/wait.h> 36#include <netinet/in.h> 37#include <assert.h> --- 106 unchanged lines hidden (view full) --- 144 TAILQ_FOREACH(auth, &ag->ag_auths, a_next) { 145 if (strcmp(auth->a_user, user) == 0) 146 return (auth); 147 } 148 149 return (NULL); 150} 151 |
152const struct auth_name * 153auth_name_new(struct auth_group *ag, const char *name) 154{ 155 struct auth_name *an; 156 157 an = calloc(1, sizeof(*an)); 158 if (an == NULL) 159 log_err(1, "calloc"); 160 an->an_auth_group = ag; 161 an->an_initator_name = checked_strdup(name); 162 TAILQ_INSERT_TAIL(&ag->ag_names, an, an_next); 163 return (an); 164} 165 166static void 167auth_name_delete(struct auth_name *an) 168{ 169 TAILQ_REMOVE(&an->an_auth_group->ag_names, an, an_next); 170 171 free(an->an_initator_name); 172 free(an); 173} 174 175bool 176auth_name_defined(const struct auth_group *ag) 177{ 178 if (TAILQ_EMPTY(&ag->ag_names)) 179 return (false); 180 return (true); 181} 182 183const struct auth_name * 184auth_name_find(const struct auth_group *ag, const char *name) 185{ 186 const struct auth_name *auth_name; 187 188 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next) { 189 if (strcmp(auth_name->an_initator_name, name) == 0) 190 return (auth_name); 191 } 192 193 return (NULL); 194} 195 196const struct auth_portal * 197auth_portal_new(struct auth_group *ag, const char *portal) 198{ 199 struct auth_portal *ap; 200 201 ap = calloc(1, sizeof(*ap)); 202 if (ap == NULL) 203 log_err(1, "calloc"); 204 ap->ap_auth_group = ag; 205 ap->ap_initator_portal = checked_strdup(portal); 206 TAILQ_INSERT_TAIL(&ag->ag_portals, ap, ap_next); 207 return (ap); 208} 209 210static void 211auth_portal_delete(struct auth_portal *ap) 212{ 213 TAILQ_REMOVE(&ap->ap_auth_group->ag_portals, ap, ap_next); 214 215 free(ap->ap_initator_portal); 216 free(ap); 217} 218 219bool 220auth_portal_defined(const struct auth_group *ag) 221{ 222 if (TAILQ_EMPTY(&ag->ag_portals)) 223 return (false); 224 return (true); 225} 226 227const struct auth_portal * 228auth_portal_find(const struct auth_group *ag, const char *portal) 229{ 230 const struct auth_portal *auth_portal; 231 232 TAILQ_FOREACH(auth_portal, &ag->ag_portals, ap_next) { 233 if (strcmp(auth_portal->ap_initator_portal, portal) == 0) 234 return (auth_portal); 235 } 236 237 return (NULL); 238} 239 |
|
152struct auth_group * 153auth_group_new(struct conf *conf, const char *name) 154{ 155 struct auth_group *ag; 156 157 if (name != NULL) { 158 ag = auth_group_find(conf, name); 159 if (ag != NULL) { 160 log_warnx("duplicated auth-group \"%s\"", name); 161 return (NULL); 162 } 163 } 164 165 ag = calloc(1, sizeof(*ag)); 166 if (ag == NULL) 167 log_err(1, "calloc"); 168 if (name != NULL) 169 ag->ag_name = checked_strdup(name); 170 TAILQ_INIT(&ag->ag_auths); | 240struct auth_group * 241auth_group_new(struct conf *conf, const char *name) 242{ 243 struct auth_group *ag; 244 245 if (name != NULL) { 246 ag = auth_group_find(conf, name); 247 if (ag != NULL) { 248 log_warnx("duplicated auth-group \"%s\"", name); 249 return (NULL); 250 } 251 } 252 253 ag = calloc(1, sizeof(*ag)); 254 if (ag == NULL) 255 log_err(1, "calloc"); 256 if (name != NULL) 257 ag->ag_name = checked_strdup(name); 258 TAILQ_INIT(&ag->ag_auths); |
259 TAILQ_INIT(&ag->ag_names); 260 TAILQ_INIT(&ag->ag_portals); |
|
171 ag->ag_conf = conf; 172 TAILQ_INSERT_TAIL(&conf->conf_auth_groups, ag, ag_next); 173 174 return (ag); 175} 176 177void 178auth_group_delete(struct auth_group *ag) 179{ | 261 ag->ag_conf = conf; 262 TAILQ_INSERT_TAIL(&conf->conf_auth_groups, ag, ag_next); 263 264 return (ag); 265} 266 267void 268auth_group_delete(struct auth_group *ag) 269{ |
180 struct auth *auth, *tmp; | 270 struct auth *auth, *auth_tmp; 271 struct auth_name *auth_name, *auth_name_tmp; 272 struct auth_portal *auth_portal, *auth_portal_tmp; |
181 182 TAILQ_REMOVE(&ag->ag_conf->conf_auth_groups, ag, ag_next); 183 | 273 274 TAILQ_REMOVE(&ag->ag_conf->conf_auth_groups, ag, ag_next); 275 |
184 TAILQ_FOREACH_SAFE(auth, &ag->ag_auths, a_next, tmp) | 276 TAILQ_FOREACH_SAFE(auth, &ag->ag_auths, a_next, auth_tmp) |
185 auth_delete(auth); | 277 auth_delete(auth); |
278 TAILQ_FOREACH_SAFE(auth_name, &ag->ag_names, an_next, auth_name_tmp) 279 auth_name_delete(auth_name); 280 TAILQ_FOREACH_SAFE(auth_portal, &ag->ag_portals, ap_next, 281 auth_portal_tmp) 282 auth_portal_delete(auth_portal); |
|
186 free(ag->ag_name); 187 free(ag); 188} 189 190struct auth_group * 191auth_group_find(struct conf *conf, const char *name) 192{ 193 struct auth_group *ag; --- 633 unchanged lines hidden (view full) --- 827} 828 829#if 0 830static void 831conf_print(struct conf *conf) 832{ 833 struct auth_group *ag; 834 struct auth *auth; | 283 free(ag->ag_name); 284 free(ag); 285} 286 287struct auth_group * 288auth_group_find(struct conf *conf, const char *name) 289{ 290 struct auth_group *ag; --- 633 unchanged lines hidden (view full) --- 924} 925 926#if 0 927static void 928conf_print(struct conf *conf) 929{ 930 struct auth_group *ag; 931 struct auth *auth; |
932 struct auth_name *auth_name; 933 struct auth_portal *auth_portal; |
|
835 struct portal_group *pg; 836 struct portal *portal; 837 struct target *targ; 838 struct lun *lun; 839 struct lun_option *lo; 840 841 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) { 842 fprintf(stderr, "auth-group %s {\n", ag->ag_name); 843 TAILQ_FOREACH(auth, &ag->ag_auths, a_next) 844 fprintf(stderr, "\t chap-mutual %s %s %s %s\n", 845 auth->a_user, auth->a_secret, 846 auth->a_mutual_user, auth->a_mutual_secret); | 934 struct portal_group *pg; 935 struct portal *portal; 936 struct target *targ; 937 struct lun *lun; 938 struct lun_option *lo; 939 940 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) { 941 fprintf(stderr, "auth-group %s {\n", ag->ag_name); 942 TAILQ_FOREACH(auth, &ag->ag_auths, a_next) 943 fprintf(stderr, "\t chap-mutual %s %s %s %s\n", 944 auth->a_user, auth->a_secret, 945 auth->a_mutual_user, auth->a_mutual_secret); |
946 TAILQ_FOREACH(auth_name, &ag->ag_names, an_next) 947 fprintf(stderr, "\t initiator-name %s\n", 948 auth_name->an_initator_name); 949 TAILQ_FOREACH(auth_portal, &ag->ag_portals, an_next) 950 fprintf(stderr, "\t initiator-portal %s\n", 951 auth_portal->an_initator_portal); |
|
847 fprintf(stderr, "}\n"); 848 } 849 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) { 850 fprintf(stderr, "portal-group %s {\n", pg->pg_name); 851 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) 852 fprintf(stderr, "\t listen %s\n", portal->p_listen); 853 fprintf(stderr, "}\n"); 854 } --- 871 unchanged lines hidden --- | 952 fprintf(stderr, "}\n"); 953 } 954 TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) { 955 fprintf(stderr, "portal-group %s {\n", pg->pg_name); 956 TAILQ_FOREACH(portal, &pg->pg_portals, p_next) 957 fprintf(stderr, "\t listen %s\n", portal->p_listen); 958 fprintf(stderr, "}\n"); 959 } --- 871 unchanged lines hidden --- |