~smb/ubuntu/oneiric/iscsitarget/proposed

« back to all changes in this revision

Viewing changes to usr/plain.c

  • Committer: Colin Watson
  • Date: 2010-08-16 20:59:52 UTC
  • mfrom: (2.1.9 sid)
  • Revision ID: cjwatson@canonical.com-20100816205952-hyytf817ju6wk1bj
merge from Debian 1.4.20.2-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Plain file-based configuration file code.
3
 
 *
4
 
 * (C) 2005 FUJITA Tomonori <tomof@acm.org>
5
 
 * This code is licenced under the GPL.
 
2
 * plain.c - ietd plain file-based configuration
 
3
 *
 
4
 * Copyright (C) 2004-2005 FUJITA Tomonori <tomof at acm dot org>
 
5
 * Copyright (C) 2004-2010 VMware, Inc. All Rights Reserved.
 
6
 * Copyright (C) 2007-2010 Ross Walker <rswwalker at gmail dot com>
 
7
 *
 
8
 * This file is part of iSCSI Enterprise Target software.
 
9
 *
 
10
 * Released under the terms of the GNU GPL v2.0.
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or
 
13
 * modify it under the terms of the GNU General Public License as
 
14
 * published by the Free Software Foundation; either version 2 of the
 
15
 * License, or (at your option) any later version.
 
16
 *
 
17
 * This program is distributed in the hope that it will be useful, but
 
18
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
 * General Public License for more details.
 
21
 *
 
22
 * You should have received a copy of the GNU General Public License
 
23
 * along with this program; if not, write to the Free Software
 
24
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
25
 * 02110-1301 USA
6
26
 */
7
27
 
8
28
#include <ctype.h>
43
63
        char *password;
44
64
};
45
65
 
 
66
int is_addr_valid(char *addr)
 
67
{
 
68
        struct in_addr ia;
 
69
        struct in6_addr ia6;
 
70
        char tmp[NI_MAXHOST + 1], *p = tmp, *q;
 
71
 
 
72
        snprintf(tmp, sizeof(tmp), "%s", addr);
 
73
 
 
74
        if (inet_pton(AF_INET, p, &ia) == 1)
 
75
                return 1;
 
76
 
 
77
        if (*p == '[') {
 
78
                p++;
 
79
                q = p + strlen(p) - 1;
 
80
                if (*q != ']')
 
81
                        return 0;
 
82
                *q = '\0';
 
83
        }
 
84
 
 
85
        if (inet_pton(AF_INET6, p, &ia6) == 1)
 
86
                return 1;
 
87
 
 
88
        return 0;
 
89
}
 
90
 
46
91
/* this is the orignal Ardis code. */
47
92
static char *target_sep_string(char **pp)
48
93
{
476
521
 * Main configuration code
477
522
 */
478
523
 
 
524
static int __plain_target_redirect(u32 tid, char *dest, u8 type, int update)
 
525
{
 
526
        struct target *target;
 
527
        char *a = dest, *p = dest + strlen(dest);
 
528
 
 
529
        if (!tid || !dest || !type)
 
530
                return -EINVAL;
 
531
 
 
532
        if (type != ISCSI_STATUS_TGT_MOVED_TEMP &&
 
533
                        type != ISCSI_STATUS_TGT_MOVED_PERM)
 
534
                return -EINVAL;
 
535
 
 
536
        target = target_find_by_id(tid);
 
537
        if (!target) {
 
538
                log_error("can't find target: %d", tid);
 
539
                return -ENOENT;
 
540
        }
 
541
 
 
542
        while(isspace(*a))
 
543
                a++;
 
544
 
 
545
        if (strlen(a)) {
 
546
                while(isspace(*(--p)))
 
547
                        *p = '\0';
 
548
 
 
549
                if ((p = strrchr(a, ']')))
 
550
                        p = strchrnul(p, ':');
 
551
                else
 
552
                        p = strchrnul(a, ':');
 
553
 
 
554
                if (*p) {
 
555
                        *(p++) = '\0';
 
556
                        if (!atoi(p))
 
557
                                return -EINVAL;
 
558
                }
 
559
 
 
560
                if (!is_addr_valid(a))
 
561
                        return -EINVAL;
 
562
 
 
563
                log_warning("target %s %s redirected to %s:%s", target->name,
 
564
                        (type == ISCSI_STATUS_TGT_MOVED_TEMP) ? "temporarily" :
 
565
                                                                "permanently",
 
566
                                                a, strlen(p) ? p : "3260");
 
567
        } else
 
568
                log_warning("target redirection for %s cleared", target->name);
 
569
 
 
570
        target->redirect.type = type;
 
571
 
 
572
        snprintf(target->redirect.addr, sizeof(target->redirect.addr), "%s", a);
 
573
        snprintf(target->redirect.port, sizeof(target->redirect.port), "%s", p);
 
574
 
 
575
        return 0;
 
576
}
 
577
 
 
578
static int plain_target_redirect(u32 tid, char *dest, u8 type)
 
579
{
 
580
        return __plain_target_redirect(tid, dest, type, 1);
 
581
}
 
582
 
479
583
static int __plain_target_create(u32 *tid, char *name, int update)
480
584
{
481
585
        int err;
513
617
{
514
618
        int err;
515
619
 
516
 
        if ((err = ki->lunit_create(tid, lun, args)) < 0)
 
620
        err = ki->lunit_create(tid, lun, args);
 
621
        if (err < 0) {
 
622
                log_error("unable to create logical unit %u in target %u: %d",
 
623
                        lun, tid, errno);
517
624
                return err;
 
625
        }
518
626
 
519
627
        if (update)
520
628
                ;
529
637
 
530
638
static int plain_lunit_destroy(u32 tid, u32 lun)
531
639
{
532
 
        return ki->lunit_destroy(tid, lun);
 
640
        int err;
 
641
 
 
642
        err = ki->lunit_destroy(tid, lun);
 
643
        if (err < 0)
 
644
                log_error("unable to delete logical unit %u in target %u: %d",
 
645
                        lun, tid, errno);
 
646
 
 
647
        return err;
533
648
}
534
649
 
535
650
static int __plain_param_set(u32 tid, u64 sid, int type,
537
652
{
538
653
        int err;
539
654
 
540
 
        if ((err = ki->param_set(tid, sid, type, partial, param)) < 0)
 
655
        err = ki->param_set(tid, sid, type, partial, param);
 
656
        if (err < 0) {
 
657
                log_error ("unable to set parameter (%d:%u) of session %#" PRIx64 " in target %u: %d",
 
658
                        type, partial, sid, tid, errno);
541
659
                return err;
 
660
        }
542
661
 
543
662
        if (update)
544
663
                ;
735
854
        .account_list           = plain_account_list,
736
855
        .initiator_allow        = plain_initiator_allow,
737
856
        .target_allow           = plain_target_allow,
 
857
        .target_redirect        = plain_target_redirect,
738
858
};