Deleted Added
full compact
ctld.c (275244) ctld.c (275245)
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

--- 15 unchanged lines hidden (view full) ---

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 */
30
31#include <sys/cdefs.h>
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

--- 15 unchanged lines hidden (view full) ---

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 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/ctld.c 275244 2014-11-29 15:32:15Z trasz $");
32__FBSDID("$FreeBSD: stable/10/usr.sbin/ctld/ctld.c 275245 2014-11-29 15:34:17Z trasz $");
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/socket.h>
37#include <sys/wait.h>
38#include <netinet/in.h>
39#include <arpa/inet.h>
40#include <assert.h>

--- 476 unchanged lines hidden (view full) ---

517 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
518 if (ag->ag_name != NULL && strcmp(ag->ag_name, name) == 0)
519 return (ag);
520 }
521
522 return (NULL);
523}
524
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/socket.h>
37#include <sys/wait.h>
38#include <netinet/in.h>
39#include <arpa/inet.h>
40#include <assert.h>

--- 476 unchanged lines hidden (view full) ---

517 TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) {
518 if (ag->ag_name != NULL && strcmp(ag->ag_name, name) == 0)
519 return (ag);
520 }
521
522 return (NULL);
523}
524
525static int
526auth_group_set_type(struct auth_group *ag, int type)
527{
528
529 if (ag->ag_type == AG_TYPE_UNKNOWN) {
530 ag->ag_type = type;
531 return (0);
532 }
533
534 if (ag->ag_type == type)
535 return (0);
536
537 return (1);
538}
539
540int
525int
541auth_group_set_type_str(struct auth_group *ag, const char *str)
526auth_group_set_type(struct auth_group *ag, const char *str)
542{
527{
543 int error, type;
528 int type;
544
545 if (strcmp(str, "none") == 0) {
546 type = AG_TYPE_NO_AUTHENTICATION;
547 } else if (strcmp(str, "deny") == 0) {
548 type = AG_TYPE_DENY;
549 } else if (strcmp(str, "chap") == 0) {
550 type = AG_TYPE_CHAP;
551 } else if (strcmp(str, "chap-mutual") == 0) {
552 type = AG_TYPE_CHAP_MUTUAL;
553 } else {
554 if (ag->ag_name != NULL)
555 log_warnx("invalid auth-type \"%s\" for auth-group "
556 "\"%s\"", str, ag->ag_name);
557 else
558 log_warnx("invalid auth-type \"%s\" for target "
559 "\"%s\"", str, ag->ag_target->t_name);
560 return (1);
561 }
562
529
530 if (strcmp(str, "none") == 0) {
531 type = AG_TYPE_NO_AUTHENTICATION;
532 } else if (strcmp(str, "deny") == 0) {
533 type = AG_TYPE_DENY;
534 } else if (strcmp(str, "chap") == 0) {
535 type = AG_TYPE_CHAP;
536 } else if (strcmp(str, "chap-mutual") == 0) {
537 type = AG_TYPE_CHAP_MUTUAL;
538 } else {
539 if (ag->ag_name != NULL)
540 log_warnx("invalid auth-type \"%s\" for auth-group "
541 "\"%s\"", str, ag->ag_name);
542 else
543 log_warnx("invalid auth-type \"%s\" for target "
544 "\"%s\"", str, ag->ag_target->t_name);
545 return (1);
546 }
547
563 error = auth_group_set_type(ag, type);
564 if (error != 0) {
565 if (ag->ag_name != NULL)
548 if (ag->ag_type != AG_TYPE_UNKNOWN && ag->ag_type != type) {
549 if (ag->ag_name != NULL) {
566 log_warnx("cannot set auth-type to \"%s\" for "
567 "auth-group \"%s\"; already has a different "
568 "type", str, ag->ag_name);
550 log_warnx("cannot set auth-type to \"%s\" for "
551 "auth-group \"%s\"; already has a different "
552 "type", str, ag->ag_name);
569 else
553 } else {
570 log_warnx("cannot set auth-type to \"%s\" for target "
571 "\"%s\"; already has a different type",
572 str, ag->ag_target->t_name);
554 log_warnx("cannot set auth-type to \"%s\" for target "
555 "\"%s\"; already has a different type",
556 str, ag->ag_target->t_name);
557 }
573 return (1);
574 }
575
558 return (1);
559 }
560
576 return (error);
561 ag->ag_type = type;
562
563 return (0);
577}
578
579static struct portal *
580portal_new(struct portal_group *pg)
581{
582 struct portal *portal;
583
584 portal = calloc(1, sizeof(*portal));

--- 389 unchanged lines hidden (view full) ---

974 return;
975 gethostname(hostname, sizeof(hostname));
976
977 res = isns_do_deregister(isns, s, hostname);
978 close(s);
979 set_timeout(0, false);
980}
981
564}
565
566static struct portal *
567portal_new(struct portal_group *pg)
568{
569 struct portal *portal;
570
571 portal = calloc(1, sizeof(*portal));

--- 389 unchanged lines hidden (view full) ---

961 return;
962 gethostname(hostname, sizeof(hostname));
963
964 res = isns_do_deregister(isns, s, hostname);
965 close(s);
966 set_timeout(0, false);
967}
968
982static int
983portal_group_set_filter(struct portal_group *pg, int filter)
984{
985
986 if (pg->pg_discovery_filter == PG_FILTER_UNKNOWN) {
987 pg->pg_discovery_filter = filter;
988 return (0);
989 }
990
991 if (pg->pg_discovery_filter == filter)
992 return (0);
993
994 return (1);
995}
996
997int
969int
998portal_group_set_filter_str(struct portal_group *pg, const char *str)
970portal_group_set_filter(struct portal_group *pg, const char *str)
999{
971{
1000 int error, filter;
972 int filter;
1001
1002 if (strcmp(str, "none") == 0) {
1003 filter = PG_FILTER_NONE;
1004 } else if (strcmp(str, "portal") == 0) {
1005 filter = PG_FILTER_PORTAL;
1006 } else if (strcmp(str, "portal-name") == 0) {
1007 filter = PG_FILTER_PORTAL_NAME;
1008 } else if (strcmp(str, "portal-name-auth") == 0) {
1009 filter = PG_FILTER_PORTAL_NAME_AUTH;
1010 } else {
1011 log_warnx("invalid discovery-filter \"%s\" for portal-group "
1012 "\"%s\"; valid values are \"none\", \"portal\", "
1013 "\"portal-name\", and \"portal-name-auth\"",
1014 str, pg->pg_name);
1015 return (1);
1016 }
1017
973
974 if (strcmp(str, "none") == 0) {
975 filter = PG_FILTER_NONE;
976 } else if (strcmp(str, "portal") == 0) {
977 filter = PG_FILTER_PORTAL;
978 } else if (strcmp(str, "portal-name") == 0) {
979 filter = PG_FILTER_PORTAL_NAME;
980 } else if (strcmp(str, "portal-name-auth") == 0) {
981 filter = PG_FILTER_PORTAL_NAME_AUTH;
982 } else {
983 log_warnx("invalid discovery-filter \"%s\" for portal-group "
984 "\"%s\"; valid values are \"none\", \"portal\", "
985 "\"portal-name\", and \"portal-name-auth\"",
986 str, pg->pg_name);
987 return (1);
988 }
989
1018 error = portal_group_set_filter(pg, filter);
1019 if (error != 0) {
990 if (pg->pg_discovery_filter != PG_FILTER_UNKNOWN &&
991 pg->pg_discovery_filter != filter) {
1020 log_warnx("cannot set discovery-filter to \"%s\" for "
1021 "portal-group \"%s\"; already has a different "
1022 "value", str, pg->pg_name);
1023 return (1);
1024 }
1025
992 log_warnx("cannot set discovery-filter to \"%s\" for "
993 "portal-group \"%s\"; already has a different "
994 "value", str, pg->pg_name);
995 return (1);
996 }
997
1026 return (error);
998 pg->pg_discovery_filter = filter;
999
1000 return (0);
1027}
1028
1029static bool
1030valid_hex(const char ch)
1031{
1032 switch (ch) {
1033 case '0':
1034 case '1':

--- 1336 unchanged lines hidden ---
1001}
1002
1003static bool
1004valid_hex(const char ch)
1005{
1006 switch (ch) {
1007 case '0':
1008 case '1':

--- 1336 unchanged lines hidden ---