AFS

 view release on metacpan or  search on metacpan

src/AFS.xs  view on Meta::CPAN


    safe_hv_store(stats, "cheader_lock", 12, newSViv(ka->cheader_lock), 0);
    safe_hv_store(stats, "keycache_lock", 13, newSViv(ka->keycache_lock), 0);
    safe_hv_store(stats, "kcVersion", 9, newSViv(ka->kcVersion), 0);
    safe_hv_store(stats, "kcSize", 6, newSViv(ka->kcSize), 0);

    safe_hv_store(stats, "reserved1", 9, newSViv(ka->reserved1), 0);
    safe_hv_store(stats, "reserved2", 9, newSViv(ka->reserved2), 0);
    safe_hv_store(stats, "reserved3", 9, newSViv(ka->reserved3), 0);
    safe_hv_store(stats, "reserved4", 9, newSViv(ka->reserved4), 0);

    if (ka->kcUsed > KADEBUGKCINFOSIZE) {
        safe_hv_store(stats, "actual_kcUsed", 13, newSViv(ka->kcUsed), 0);
        ka->kcUsed = KADEBUGKCINFOSIZE;
    }

    safe_hv_store(stats, "kcUsed", 6, newSViv(ka->kcUsed), 0);

    for (i = 0; i < ka->kcUsed; i++) {
        sprintf(buff, "kcInfo_used%d", i);
        safe_hv_store(stats, buff, strlen(buff), newSViv(ka->kcInfo[i].used), 0);

        sprintf(buff, "kcInfo_kvno%d", i);
        safe_hv_store(stats, buff, strlen(buff), newSViv(ka->kcInfo[i].kvno), 0);

        sprintf(buff, "kcInfo_primary%d", i);
        safe_hv_store(stats, buff, strlen(buff),
                 newSViv((unsigned char) ka->kcInfo[i].primary), 0);

        sprintf(buff, "kcInfo_keycksum%d", i);
        safe_hv_store(stats, buff, strlen(buff),
                 newSViv((unsigned char) ka->kcInfo[i].keycksum), 0);

        sprintf(buff, "kcInfo_principal%d", i);
        safe_hv_store(stats, buff, strlen(buff),
                 newSVpv(ka->kcInfo[i].principal, strlen(ka->kcInfo[i].principal)), 0);
    }
    /*               1234567890123456789012345 */
    return 1;
}
/* end of helper functions for KAS class: */



/************************ Start of XS stuff **************************/
/* PROTOTYPES: DISABLE added by leg@andrew, 10/7/96 */

MODULE = AFS    PACKAGE = AFS   PREFIX = fs_
VERSIONCHECK: DISABLE
PROTOTYPES: DISABLE

void
fs_pioctl(path,setpath,op,in,setin,setout,follow)
        char *  path
        int32   setpath
        int32   op
        SV *    in
        int32   setin
        int32   setout
        int32   follow
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];
        STRLEN insize;

        if (!setpath)
            path = NULL;
        if (setout) {
            space[0] = '\0';
            vi.out_size = MAXSIZE;
            vi.out = space;
        }
        else {
            vi.out_size = 0;
            vi.out = 0;
        }

        if (setin) {
            vi.in = (char *) SvPV(ST(2), insize);
            vi.in_size = insize;
        }
        else {
            vi.in = 0;
            vi.in_size = 0;
        }

        code = pioctl(path, op, &vi, follow);
        SETCODE(code);
        if (code == 0 && setout) {
            EXTEND(sp, 1);
            printf("out_size = %d\n", vi.out_size);
            PUSHs(sv_2mortal(newSVpv(vi.out, vi.out_size)));
        }
    }

void
fs_getvolstats(dir,follow=1)
        char *  dir
        int32   follow
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];
        HV *stats;

        vi.out_size = MAXSIZE;
        vi.in_size = 0;
        vi.out = space;
        code = pioctl(dir, VIOCGETVOLSTAT, &vi, follow);
        SETCODE(code);
        if (code == 0) {
            stats = newHV();
            if (parse_volstat(stats, space)) {
                EXTEND(sp, 1);
                PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
            }
            else {
                hv_undef(stats);
            }
        }
    }

void
fs_whereis(dir,ip=0,follow=1)
        char *  dir
        int32   ip
        int32   follow
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];

        vi.out_size = MAXSIZE;
        vi.in_size = 0;
        vi.out = space;
        code = pioctl(dir, VIOCWHEREIS, &vi, follow);
        SETCODE(code);
        if (code == 0) {
            struct in_addr *hosts = (struct in_addr *) space;
            struct hostent *ht;
            int i;
            char *h;
            for (i = 0; i < MAXHOSTS; i++) {
                if (hosts[i].s_addr == 0)
                    break;
                if (ip == 0) {
                    ht = gethostbyaddr((const char *) &hosts[i], sizeof(struct in_addr), AF_INET);
                    if (ht == NULL)
                        h = (char *) inet_ntoa(hosts[i]);
                    else
                        h = ht->h_name;
                }
                else {
                    h = (char *) inet_ntoa(hosts[i]);
                }
                XPUSHs(sv_2mortal(newSVpv(h, strlen(h))));
            }

        }
    }

void
fs_checkservers(fast,cell=0,ip=0)
        int32   fast
        char *  cell
        int32   ip
    PPCODE:
    {
        struct chservinfo checkserv;
        struct ViceIoctl vi;
        int32 code, *num;
        char space[MAXSIZE];

        checkserv.magic = 0x12345678;
        checkserv.tflags = 2;
        if (fast)
            checkserv.tflags |= 0x1;
        if (cell) {
            checkserv.tflags &= ~2;
            strcpy(checkserv.tbuffer, cell);
            checkserv.tsize = strlen(cell);
        }
        checkserv.tinterval = -1;

        vi.out_size = MAXSIZE;
        vi.in_size = sizeof(checkserv);
        vi.in = (char *) &checkserv;
        vi.out = space;

        code = pioctl(0, VIOCCKSERV, &vi, 1);
        num = (int32 *) space;
        SETCODE(code);
        if (code == 0 && *num > 0) {
            struct in_addr *hosts = (struct in_addr *) (space + sizeof(int32));
            struct hostent *ht;
            int i;
            char *h;
            for (i = 0; i < MAXHOSTS; i++) {
                if (hosts[i].s_addr == 0)
                    break;
                if (ip == 0) {
                    ht = gethostbyaddr((const char *) &hosts[i], sizeof(struct in_addr), AF_INET);
                    if (ht == NULL)
                        h = (char *) inet_ntoa(hosts[i]);
                    else
                        h = ht->h_name;
                }
                else {
                    h = (char *) inet_ntoa(hosts[i]);
                }
                XPUSHs(sv_2mortal(newSVpv(h, strlen(h))));
            }

        }
    }

void
fs_getcell(in_index,ip=0)
        int32   in_index
        int32   ip
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code, max = OMAXHOSTS;
        int32 *lp;
        char space[MAXSIZE];

        lp = (int32 *) space;
        *lp++ = in_index;
        *lp = 0x12345678;
        vi.in_size = sizeof(int32) * 2;
        vi.in = (char *) space;
        vi.out_size = MAXSIZE;
        vi.out = space;
        code = pioctl(NULL, VIOCGETCELL, &vi, 1);
        SETCODE(code);
        if (code == 0) {
            struct in_addr *hosts = (struct in_addr *) space;
            /* int32 *magic = (int32 *) space; */
            struct hostent *ht;
            int i;
            char *h;
            /*if (*magic == 0x12345678) { */
            max = MAXHOSTS;
            /*            hosts++; */
            /*    } */
            h = (char *) hosts + max * sizeof(int32);
            XPUSHs(sv_2mortal(newSVpv(h, strlen(h))));
            for (i = 0; i < max; i++) {
                if (hosts[i].s_addr == 0)
                    break;
                if (ip == 0) {
                    ht = gethostbyaddr((const char *) &hosts[i], sizeof(struct in_addr), AF_INET);
                    if (ht == NULL)
                        h = (char *) inet_ntoa(hosts[i]);
                    else
                        h = ht->h_name;
                }
                else {
                    h = (char *) inet_ntoa(hosts[i]);
                }
                XPUSHs(sv_2mortal(newSVpv(h, strlen(h))));
            }

        }
    }

void
fs__get_server_version(port,hostName="localhost",verbose=0)
        short port
        char *hostName
        int32 verbose
    CODE:
    {
#if defined(AFS_3_4)
        not_here("AFS::Utils::get_server_version");
#else
        struct sockaddr_in taddr;
        struct in_addr hostAddr;
        struct hostent *th;
        int32 host;

src/AFS.xs  view on Meta::CPAN

    OUTPUT:
        RETVAL

int32
fs_flushcb(path,follow=1)
        char *  path
        int32   follow
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];

        vi.in_size = 0;
        vi.out_size = MAXSIZE;
        vi.out = (caddr_t) space;
        code = pioctl(path, VIOCFLUSHCB, &vi, follow);
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
fs_setquota(path,newquota,follow=1)
        char *  path
        int32   newquota
        int32   follow
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];
        struct VolumeStatus *status;
        char *input;

        vi.in_size = sizeof(*status) + 3;
        vi.in = space;
        vi.out_size = MAXSIZE;
        vi.out = space;
        status = (VolumeStatus *) space;
        status->MinQuota = -1;
        status->MaxQuota = newquota;

        input = (char *) status + sizeof(*status);
        *(input++) = '\0';              /* never set name: this call doesn't change vldb */
        *(input++) = '\0';              /* offmsg  */
        *(input++) = '\0';              /* motd  */

        code = pioctl(path, VIOCSETVOLSTAT, &vi, follow);
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

void
fs_getquota(path,follow=1)
        char *  path
        int32   follow
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];
        struct VolumeStatus *status;

        vi.out_size = MAXSIZE;
        vi.in_size = 0;
        vi.in = 0;
        vi.out = space;

        code = pioctl(path, VIOCGETVOLSTAT, &vi, follow);
        SETCODE(code);
        if (code == 0) {
            status = (VolumeStatus *)space;
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newSViv(status->MaxQuota)));
        }
    }

int32
fs_mkmount(mountp,volume,rw=0,cell=0)
        char *  mountp
        char *  volume
        int32   rw
        char *  cell
    CODE:
    {
        char buffer[1024];
        char parent[1024];
        int32 code = 0;

        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        if (strlen(mountp) > (sizeof(parent) - 1))
            code = EINVAL;
        else {
            char *p;
            strcpy(parent, mountp);
            p = strrchr(parent, '/');
            if (p)
                *p = 0;
            else
                strcpy(parent, ".");
            if (!isafs(parent))
                code = EINVAL;
        }

        if (code == 0) {
            sprintf(buffer, "%c%s%s%s.",
                    rw ? '%' : '#', cell ? cell : "", cell ? ":" : "", volume);
            code = symlink(buffer, mountp);
        }
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
fs_checkvolumes()
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;

        vi.in_size = 0;
        vi.out_size = 0;
        code = pioctl(NULL, VIOCCKBACK, &vi, 0);
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
fs_checkconn()
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;
        int32 status;

        vi.in_size = 0;
        vi.out_size = sizeof(status);
        vi.out = (caddr_t) & status;
        code = pioctl(NULL, VIOCCKCONN, &vi, 0);
        SETCODE(code);
        RETVAL = (status == 0);
    }
    OUTPUT:
        RETVAL

int32
fs_getcacheparms()
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code;
        int32 stats[16];

        vi.in_size = 0;
        vi.in = 0;
        vi.out_size = sizeof(stats);
        vi.out = (char *) stats;
        code = pioctl(NULL, VIOCGETCACHEPARMS, &vi, 0);

        SETCODE(code);
        if (code == 0) {
            EXTEND(sp, 2);
            PUSHs(sv_2mortal(newSViv(stats[0])));
            PUSHs(sv_2mortal(newSViv(stats[1])));
        }
    }

int32
fs_setcachesize(size)
        int32   size
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;

        vi.in_size = sizeof(size);;
        vi.in = (char *) &size;
        vi.out_size = 0;
        vi.out = 0;
        code = pioctl(NULL, VIOCSETCACHESIZE, &vi, 0);
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
fs_unlog()
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;

        vi.in_size = 0;
        vi.out_size = 0;
        code = pioctl(NULL, VIOCUNLOG, &vi, 0);
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
fs_getfid(path,follow=1)
        char *  path
        int32   follow
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code;
        struct VenusFid vf;

        vi.in_size = 0;
        vi.out_size = sizeof(vf);
        vi.out = (char *) &vf;
        code = pioctl(path, VIOCGETFID, &vi, follow);
        SETCODE(code);
        if (code == 0) {
            EXTEND(sp, 4);
            PUSHs(sv_2mortal(newSViv(vf.Cell)));
            PUSHs(sv_2mortal(newSViv(vf.Fid.Volume)));
            PUSHs(sv_2mortal(newSViv(vf.Fid.Vnode)));
            PUSHs(sv_2mortal(newSViv(vf.Fid.Unique)));
        }
    }

int32
fs_isafs(path,follow=1)
        char *  path
        int32   follow
    CODE:
    {
        int32 code;
        RETVAL = isafs(path, follow);
        if (!RETVAL)
            code = errno;
        else
            code = 0;
        SETCODE(code);
    }
    OUTPUT:
        RETVAL

int32
fs_cm_access(path,perm="read",follow=1)
        char *  path
        char *  perm
        int32   follow
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;
        int32 rights;

        code = canonical_parse_rights(perm, &rights);
        if (code == 0) {
            code = vi.in_size = sizeof(rights);
            vi.in = (char *) &rights;
            vi.out_size = 0;
            vi.out = 0;
            code = pioctl(path, VIOCACCESS, &vi, follow);
        }
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
fs_ascii2rights(perm)
        char *  perm
    CODE:
    {
        int32 code, rights = -1;

        code = canonical_parse_rights(perm, &rights);
        SETCODE(code);

        if (code != 0)
            rights = -1;
        RETVAL = rights;
    }
    OUTPUT:
        RETVAL

void
fs_rights2ascii(perm)
       int32   perm
    CODE:
    {
        char *p;
        p = format_rights(perm);

        SETCODE(0);

        ST(0) = sv_newmortal();
        sv_setpv(ST(0), p);
    }

void
fs_crights(perm)
        char *  perm
    CODE:
    {
        int32 code;
        int32 rights;

        code = canonical_parse_rights(perm, &rights);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setpv(ST(0), format_rights(rights));
        }
    }

void
fs_getcellstatus(cell=0)
        char *  cell
    PPCODE:
    {
        struct ViceIoctl vi;
        struct afsconf_cell info;
        int32 code, flags;

        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        code = internal_GetCellInfo(cell, 0, &info);
        if (code != 0) {
            XSRETURN_UNDEF;
        }
        else {
            vi.in_size = strlen(info.name) + 1;
            vi.in = info.name;
            vi.out_size = sizeof(flags);
            vi.out = (char *) &flags;
            code = pioctl(0, VIOC_GETCELLSTATUS, &vi, 0);
            SETCODE(code);
            if (code == 0) {
                EXTEND(sp, 1);
                PUSHs(sv_2mortal(newSViv((flags & 0x2) == 0)));
                XSRETURN(1);
            }
            else {
                XSRETURN_UNDEF;
            }
        }
    }

int32
fs_setcellstatus(setuid_allowed,cell=0)
        int32   setuid_allowed
        char *  cell
    PPCODE:
    {
        struct ViceIoctl vi;
        struct afsconf_cell info;
        int32 code;
        struct set_status {
            int32 status;
            int32 reserved;
            char cell[MAXCELLCHARS];
        } set;

        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        code = internal_GetCellInfo(cell, 0, &info);
        if (code != 0) {
            XSRETURN_UNDEF;
        }
        else {
            set.reserved = 0;
            strcpy(set.cell, info.name);
            if (setuid_allowed)
                set.status = 0;
            else
                set.status = 0x2;
            vi.in_size = sizeof(set);
            vi.in = (char *) &set;
            vi.out_size = 0;
            vi.out = (char *) 0;
            code = pioctl(0, VIOC_SETCELLSTATUS, &vi, 0);
            SETCODE(code);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newSViv(code == 0)));
        }
    }

void
fs_wscell()
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];

        vi.in_size = 0;
        vi.out_size = MAXSIZE;
        vi.out = (caddr_t) space;
        code = pioctl(NULL, VIOC_GET_WS_CELL, &vi, 0);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setpv(ST(0), space);
        }
    }

void
fs__getacl(dir,follow=1)
        char *  dir
        int32   follow
    PPCODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];
        HV *ph, *nh;
        vi.out_size = MAXSIZE;
        vi.in_size = 0;
        vi.out = space;
        code = pioctl(dir, VIOCGETAL, &vi, follow);
        SETCODE(code);

        if (code == 0) {
            ph = newHV();
            nh = newHV();

            if (parse_acl(space, ph, nh)) {
                AV *acl;
                acl = newAV();
                av_store(acl, 0, newRV_noinc((SV *) ph));
                av_store(acl, 1, newRV_noinc((SV *) nh));
                EXTEND(sp, 1);
                PUSHs(sv_bless(sv_2mortal(newRV_noinc((SV *) acl)), gv_stashpv("AFS::ACL", 1)));
            }
            else {
                hv_undef(ph);
                hv_undef(nh);
            }
        }
    }

int32
fs_setacl(dir,acl,follow=1)
        char *  dir
        SV *    acl
        int32   follow
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];
        char acls[MAXSIZE], *p;
        HV *ph, *nh;
        AV *object;
        SV **sv;
        HE *he;
        int plen, nlen;
        int32 rights;
        char *name, *perm;

        if (sv_isa(acl, "AFS::ACL") && SvROK(acl)
            && (SvTYPE(SvRV(acl)) == SVt_PVAV)
            ) {
            object = (AV *) SvRV(acl);
        }
        else {
            croak("acl is not of type AFS::ACL");
        }

        ph = nh = NULL;
        sv = av_fetch(object, 0, 0);

src/AFS.xs  view on Meta::CPAN

        }

        plen = nlen = 0;

        p = acls;
        *p = 0;
        code = 0;

        if (ph) {
            hv_iterinit(ph);

            while ((code == 0) && (he = hv_iternext(ph))) {
                I32 len;
                name = hv_iterkey(he, &len);
                perm = SvPV(hv_iterval(ph, he), PL_na);
                code = canonical_parse_rights(perm, &rights);
                if (code == 0 && rights && !name_is_numeric(name)) {
                    sprintf(p, "%s\t%d\n", name, rights);
                    p += strlen(p);
                    plen++;
                }
            }
        }

        if (code == 0 && nh) {
            hv_iterinit(nh);
            while ((code == 0) && (he = hv_iternext(nh))) {
                I32 len;
                name = hv_iterkey(he, &len);
                perm = SvPV(hv_iterval(nh, he), PL_na);
                code = canonical_parse_rights(perm, &rights);
                if (code == 0 && rights && !name_is_numeric(name)) {
                    sprintf(p, "%s\t%d\n", name, rights);
                    p += strlen(p);
                    nlen++;
                }
            }
        }

        if (code == 0) {
            sprintf(space, "%d\n%d\n%s", plen, nlen, acls);
            vi.in_size = strlen(space) + 1;
            vi.in = space;
            vi.out_size = 0;
            vi.out = 0;
            code = pioctl(dir, VIOCSETAL, &vi, follow);
        }
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL


MODULE = AFS            PACKAGE = AFS::KTC_PRINCIPAL    PREFIX = ktcp_

AFS::KTC_PRINCIPAL
ktcp__new(class,name,...)
        char *  class
        char *  name
    PPCODE:
    {
        struct ktc_principal *p;
        int32 code;

        if (items != 2 && items != 4)
            croak("Usage: AFS::KTC_PRINCIPAL->new(USER.INST@CELL) or AFS::KTC_PRINCIPAL->new(USER, INST, CELL)");

        p = (struct ktc_principal *) safemalloc(sizeof(struct ktc_principal));
        p->name[0] = '\0';
        p->instance[0] = '\0';
        p->cell[0] = '\0';

        if (items == 2) {
            code = ka_ParseLoginName(name, p->name, p->instance, p->cell);
        }
        else {
            STRLEN nlen, ilen, clen;
            char *i = (char *) SvPV(ST(2), ilen);
            char *c = (char *) SvPV(ST(3), clen);
            nlen = strlen(name);
            if (nlen > MAXKTCNAMELEN - 1 || ilen > MAXKTCNAMELEN - 1 || clen > MAXKTCREALMLEN - 1)
                code = KABADNAME;
            else {
                strcpy(p->name, name);
                strcpy(p->instance, i);
                strcpy(p->cell, c);
                code = 0;
            }
        }

        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setref_pv(ST(0), "AFS::KTC_PRINCIPAL", (void *) p);
        }
        else {
            safefree(p);
        }

        XSRETURN(1);
    }

void
ktcp_set(p,name,...)
        AFS::KTC_PRINCIPAL      p
        char *  name
    PPCODE:
    {
        int32 code;

        if (items != 2 && items != 4)
            croak("Usage: set($user.$inst@$cell) or set($user,$inst,$cell)");

        if (items == 2) {
            code = ka_ParseLoginName(name, p->name, p->instance, p->cell);
        }
        else {
            STRLEN nlen, ilen, clen;
            char *i = (char *) SvPV(ST(2), ilen);
            char *c = (char *) SvPV(ST(3), clen);
            nlen = strlen(name);
            if (nlen > MAXKTCNAMELEN - 1 || ilen > MAXKTCNAMELEN - 1 || clen > MAXKTCREALMLEN - 1)
                code = KABADNAME;
            else {
                strcpy(p->name, name);
                strcpy(p->instance, i);
                strcpy(p->cell, c);
                code = 0;
            }
        }

        SETCODE(code);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));
    }

int32 
ktcp_DESTROY(p)
        AFS::KTC_PRINCIPAL      p
    CODE:
    {
        safefree(p);
        # SETCODE(0);   this spoils the ERROR code
        RETVAL = 1;
    }
    OUTPUT:
        RETVAL

void
ktcp_name(p,name=0)
        AFS::KTC_PRINCIPAL      p
        char *  name
    PPCODE:
    {
        int32 code = 0;

        if (name != 0) {
            int nlen = strlen(name);
            if (nlen > MAXKTCNAMELEN - 1)
                code = KABADNAME;
            else
                strcpy(p->name, name);
            SETCODE(code);
        }
        if (code == 0) {
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newSVpv(p->name, strlen(p->name))));
        }
    }

void
ktcp_instance(p,instance=0)
        AFS::KTC_PRINCIPAL      p
        char *  instance
    PPCODE:
    {
        int32 code = 0;

        if (instance != 0) {
            int ilen = strlen(instance);
            if (ilen > MAXKTCNAMELEN - 1)
                code = KABADNAME;
            else
                strcpy(p->instance, instance);
            SETCODE(code);
        }

        if (code == 0) {
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newSVpv(p->instance, strlen(p->instance))));
        }
    }

void
ktcp_cell(p,cell=0)
        AFS::KTC_PRINCIPAL      p
        char *  cell
    PPCODE:
    {
        int32 code = 0;

        if (cell != 0) {
            int clen = strlen(cell);
            if (clen > MAXKTCREALMLEN - 1)
                code = KABADNAME;
            else
                strcpy(p->cell, cell);
            SETCODE(code);
        }
        if (code == 0) {
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newSVpv(p->cell, strlen(p->cell))));
        }
    }

void
ktcp_principal(p)
        AFS::KTC_PRINCIPAL      p
    PPCODE:
    {
        int32 code = 0;

        char buffer[MAXKTCNAMELEN + MAXKTCNAMELEN + MAXKTCREALMLEN + 3];
        sprintf(buffer, "%s%s%s%s%s", p->name,
                p->instance[0] ? "." : "", p->instance, p->cell[0] ? "@" : "", p->cell);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSVpv(buffer, strlen(buffer))));
        SETCODE(code);
    }


MODULE = AFS            PACKAGE = AFS::KTC_TOKEN        PREFIX = ktct_

int32
ktct_DESTROY(t)
        AFS::KTC_TOKEN  t
    CODE:
    {
        if (t && t != &the_null_token) safefree(t);
        # SETCODE(0);   this spoils the ERROR code
        RETVAL = 1;
    }
    OUTPUT:
        RETVAL

int32
ktct_startTime(t)
        AFS::KTC_TOKEN  t
    PPCODE:
    {
        EXTEND(sp,1);
        PUSHs(sv_2mortal(newSViv(t->startTime)));
    }

int32
ktct_endTime(t)
        AFS::KTC_TOKEN  t
    PPCODE:
    {
        EXTEND(sp,1);
        PUSHs(sv_2mortal(newSViv(t->endTime)));
    }

int32
ktct_kvno(t)
        AFS::KTC_TOKEN  t
    PPCODE:
    {
        EXTEND(sp,1);
        PUSHs(sv_2mortal(newSViv(t->kvno)));
    }

int32
ktct_ticketLen(t)
        AFS::KTC_TOKEN  t
    PPCODE:
    {
        EXTEND(sp,1);
        PUSHs(sv_2mortal(newSViv(t->ticketLen)));
    }

void
ktct_ticket(t)
        AFS::KTC_TOKEN  t
    PPCODE:
    {
        EXTEND(sp,1);
        PUSHs(sv_2mortal(newSVpv(t->ticket,t->ticketLen)));
    }

void
ktct_sessionKey(t)
        AFS::KTC_TOKEN  t
    PPCODE:
    {
        struct ktc_encryptionKey *key;
        SV *sv;
        key = (struct ktc_encryptionKey *) safemalloc(sizeof(*key));

        *key = t->sessionKey;
        sv = sv_newmortal();
        EXTEND(sp, 1);
        sv_setref_pv(sv, "AFS::KTC_EKEY", (void *) key);
        PUSHs(sv);
    }

void
ktct_string(t)
        AFS::KTC_TOKEN  t
    PPCODE:
    {
        EXTEND(sp,1);
        PUSHs(sv_2mortal(newSVpv((char*)t,sizeof(*t))));
    }


MODULE = AFS            PACKAGE = AFS::KTC_EKEY         PREFIX = ktck_

int32
ktck_DESTROY(k)
        AFS::KTC_EKEY   k
    CODE:
    {
        safefree(k);
        # SETCODE(0);   this spoils the ERROR code
        RETVAL = 1;
    }
    OUTPUT:
        RETVAL

void
ktck_string(k)
        AFS::KTC_EKEY   k
    PPCODE:
    {
        EXTEND(sp,1);
        PUSHs(sv_2mortal(newSVpv((char*)k,sizeof(*k))));
    }


MODULE = AFS     PACKAGE = AFS::VOS       PREFIX = vos_

AFS::VOS
vos_new(class=0, verb=Nullsv, timeout=Nullsv, noauth=Nullsv, localauth=Nullsv, tcell=NULL, crypt=Nullsv)
        char * class
        SV *   verb
        SV *   timeout
        SV *   noauth
        SV *   localauth
        char * tcell
        SV *   crypt
    PREINIT:
        int32 code;
        extern int verbose;
        int itimeout, inoauth, ilocalauth, icrypt;

    PPCODE:
    {
        if (!verb) {
            verb = newSViv(0);
        }
        if (!timeout) {
            timeout = newSViv(90);
        }
        if (!noauth) {
            noauth = newSViv(0);
        }
        if (!localauth) {
            localauth = newSViv(0);
        }
        if (!crypt) {
            crypt = newSViv(0);
        }
        if (tcell && (tcell[0] == '\0' || tcell[0] == '0'))
            tcell = NULL;
        if ((verb) && (!SvIOKp(verb))) {
            char buffer[256];
            sprintf(buffer, "Flag \"verb\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        verbose = SvIV(verb);

        if ((timeout) && (!SvIOKp(timeout))) {
            char buffer[256];
            sprintf(buffer, "Flag \"timeout\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        itimeout = SvIV(timeout);

        if ((noauth) && (!SvIOKp(noauth))) {
            char buffer[256];
            sprintf(buffer, "Flag \"noauth\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        inoauth = SvIV(noauth);

        if ((localauth) && (!SvIOKp(localauth))) {
            char buffer[256];
            sprintf(buffer, "Flag \"localauth\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        ilocalauth = SvIV(localauth);

        if ((crypt) && (!SvIOKp(crypt))) {
            char buffer[256];
            sprintf(buffer, "Flag \"crypt\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        icrypt = SvIV(crypt);

                /* Initialize the ubik_client connection */
        rx_SetRxDeadTime(itimeout);      /* timeout seconds inactivity before declared dead */

src/AFS.xs  view on Meta::CPAN

        if ((!SvIOKp(clone))) {
            char buffer[256];
            sprintf(buffer, "Flag \"clone\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            iclone = SvIV(clone);
        if (iclone) {
            /* printf("vos_dump DEBUG-2-1 clone = %d omitdirs = %d \n", clone, omitdirs); */
            code = UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
                                       DumpFunction, filename, omitdirs);
        } else {
            /* printf("vos_dump DEBUG-2-2 clone = %d omitdirs = %d \n", clone, omitdirs); */
            code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
                                 filename, omitdirs);
        }
        /* printf("vos_dump DEBUG-3 code = %d \n", code); */
        if ((code == RXGEN_OPCODE) && (omitdirs)) {
            omitdirs = 0;
            goto retry_dump;
        }
#else
        /* printf("vos_dump DEBUG-4 \n"); */
        code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, filename);
        /* printf("vos_dump DEBUG-5 code = %d \n", code); */
#endif
        if (code) {
            PrintDiagnostics("dump", code);
            SETCODE(code);
            goto done;
        }

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

void
vos_partinfo(cstruct, server, partname=NULL)
        AFS::VOS cstruct
        char *server
        char *partname
    PREINIT:
        afs_int32 apart;
        afs_int32 aserver, code;
        char pname[10];
#ifdef OpenAFS_1_4_64
        struct diskPartition64 partition;
#else
        struct diskPartition partition;
#endif
        struct partList dummyPartList;
        int i, cnt;
        HV *partlist = (HV*)sv_2mortal((SV*)newHV());
    PPCODE:
    {
        apart = -1;
        aserver = GetServer(server);
        if (aserver == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }
        if (partname && (strlen(partname) != 0)) {
            apart = volutil_GetPartitionID(partname);
            if (apart < 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", partname);
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            dummyPartList.partId[0] = apart;
            dummyPartList.partFlags[0] = PARTVALID;
            cnt = 1;
        }
        if (apart != -1) {
            if (!IsPartValid(apart, aserver, &code)) {  /*check for validity of the partition */
                char buffer[256];
                if (code)
                    set_errbuff(buffer, code);
                else
                    sprintf(buffer, "AFS::VOS: partition %s does not exist on the server\n",
                            partname);
                VSETCODE(code ? code : -1, buffer);
                XSRETURN_UNDEF;
            }
        }
        else {
            code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
            if (code) {
                PrintDiagnostics("listpart", code);
                SETCODE(code);
                XSRETURN_UNDEF;
            }
        }

        for (i = 0; i < cnt; i++) {
            if (dummyPartList.partFlags[i] & PARTVALID) {
                HV *part = (HV *) sv_2mortal((SV *) newHV());
                MapPartIdIntoName(dummyPartList.partId[i], pname);
#ifdef OpenAFS_1_4_64
                code = UV_PartitionInfo64(aserver, pname, &partition);
#else
                code = UV_PartitionInfo(aserver, pname, &partition);
#endif
                if (code) {
                    char buffer[256];
                    sprintf(buffer, "Could not get information on partition %s\n", pname);
                    VSETCODE(code, buffer);
                    XSRETURN_UNDEF;
                }
                safe_hv_store(part, "free", 4, newSViv(partition.free), 0);
                safe_hv_store(part, "minFree", 7, newSViv(partition.minFree), 0);

                safe_hv_store(partlist, pname, strlen(pname), newRV_inc((SV *) (part)), 0);
            }
        }

        SETCODE(0);
        ST(0) = sv_2mortal(newRV_inc((SV *) partlist));
        XSRETURN(1);
    }

void
vos_listvol(cstruct, server, partname=NULL, fast=Nullsv, extended=Nullsv)
        AFS::VOS cstruct
        char *server
        char *partname
        SV *  fast
        SV *  extended
  PREINIT:
        afs_int32 apart = -1, aserver, code = 0;
        volintInfo *pntr = (volintInfo *)0;
        afs_int32 count;
        int i;
        volintXInfo *xInfoP = (volintXInfo *)0; /*Ptr to current/orig extended vol info*/
        int wantExtendedInfo=0;                 /*Do we want extended vol info?*/

        char pname[10];
        struct partList dummyPartList;
        int all, cnt, ifast=0;

        HV *vollist = (HV*)sv_2mortal((SV*)newHV());
    PPCODE:
    {
        if (!fast)
            fast = newSViv(0);
        if (!extended)
            extended = newSViv(0);

        if ((!SvIOKp(fast))) {
            char buffer[256];
            sprintf(buffer, "Flag \"fast\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        else
            ifast = SvIV(fast);              /* -fast */
        if ((!SvIOKp(extended))) {
            char buffer[256];
            sprintf(buffer, "Flag \"extended\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        else
            wantExtendedInfo = SvIV(extended);   /* -extended */
        if (ifast && wantExtendedInfo) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS:  FAST and EXTENDED flags are mutually exclusive\n");
            VSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }

        /* printf ("vos_listvol DEBUG-1 pntr %p \n", pntr); */
        /* printf ("vos_listvol DEBUG-1 xInfoP %p \n", xInfoP); */
        if (ifast)
            all = 0;
        else
            all = 1;

        if (partname && (strlen(partname) != 0)) {
            apart = volutil_GetPartitionID(partname);
            if (apart < 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", partname);
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            dummyPartList.partId[0] = apart;
            dummyPartList.partFlags[0] = PARTVALID;
            cnt = 1;
        }

        aserver = GetServer(server);
        if (aserver == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }

        if (apart != -1) {
            if (!IsPartValid(apart, aserver, &code)) {  /*check for validity of the partition */
                char buffer[256];

src/AFS.xs  view on Meta::CPAN

            sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", parti);
            VSETCODE(ENOENT, buffer);
            goto done;
        }

        volid = vsu_GetVolumeID(id, cstruct, &err);     /* -id */
        if (!volid) {
            char buffer[256];
            if (err)
                set_errbuff(buffer, err);
            else
                sprintf(buffer, "Unknown volume ID or name '%s'\n", servername);
            VSETCODE(err ? err : -1, buffer);
            goto done;
        }

        code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ , 0 /*sleep */ );
        if (code) {
            char buffer[256];
            sprintf(buffer, "Failed to set volume. Code = %d\n", code);
            VSETCODE(code, buffer);
            goto done;
        }
        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

void
vos__backupsys(cstruct, seenprefix=Nullsv, servername=NULL, partition=NULL, exclude=Nullsv, seenxprefix=Nullsv, noaction=Nullsv)
        AFS::VOS cstruct
        SV *  seenprefix
        char *servername
        char *partition
        SV *  exclude
        SV *  seenxprefix
        SV *  noaction
    PREINIT:
        int32 apart=0, avolid;
        int32 aserver=0, code, aserver1, apart1;
        int32 vcode, iexclude=0, inoaction=0;
        struct VldbListByAttributes attributes;
        nbulkentries arrayEntries;
        register struct nvldbentry *vllist;
        int32 nentries;
        int j, i, len, verbose = 1;
        afs_int32 totalBack=0;
        afs_int32 totalFail=0;
        int previdx=-1, error, same;
        char *ccode, *itp;
        int match = 0;
        STRLEN prfxlength=0;
        SV *regex;
        AV *av;
        AV *av1 = (AV*)sv_2mortal((SV*)newAV());
        AV *av2 = (AV*)sv_2mortal((SV*)newAV());
    PPCODE:
    {
        /* printf("vos-backupsys DEBUG-1 server %s part %s exclude %d noaction %d \n", servername, partition, (int)SvIV(exclude), (int)SvIV(noaction)); */
        if (!exclude)
            exclude = newSViv(0);
        if (!noaction)
            noaction = newSViv(0);
        if ((!SvIOKp(exclude))) {
            char buffer[256];
            sprintf(buffer, "Flag \"exclude\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        else
            iexclude = SvIV(exclude);         /* -exclude */
        /* printf("vos-backupsys DEBUG-2: iexclude = %d \n", iexclude); */
        if ((!SvIOKp(noaction))) {
            char buffer[256];
            sprintf(buffer, "Flag \"noaction\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        else
            inoaction = SvIV(noaction);       /* -noaction */

        Zero(&attributes, 1, VldbListByAttributes);
        attributes.Mask = 0;
        /* printf("vos-backupsys DEBUG-3\n"); */

        if (servername && (strlen(servername) != 0)) {  /* -server */
            /* printf("vos-backupsys DEBUG-4\n"); */
            aserver = GetServer(servername);
            if (aserver == 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            attributes.server = ntohl(aserver);
            attributes.Mask |= VLLIST_SERVER;
        }
        else {
            servername = NULL;
        }

        /* printf("vos-backupsys DEBUG-5\n"); */
        if (partition && (strlen(partition) != 0)) {    /* -partition */
            /* printf("vos-backupsys DEBUG-6\n"); */
            apart = volutil_GetPartitionID(partition);
            if (apart < 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", partition);
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            attributes.partition = apart;
            attributes.Mask |= VLLIST_PARTITION;
        }
        else {
            partition = NULL;
        }

src/AFS.xs  view on Meta::CPAN

            }
            /* printf("vos-backupsys DEBUG-19\n"); */
            if (aserver) {
                same = VLDB_IsSameAddrs(aserver, aserver1, &error);
                if (error) {
                    av_push(av2, newSVpv(vllist->name, strlen(vllist->name)));
                    fprintf(stderr,
                            "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
                            aserver, error);
                    totalFail++;
                    continue;
                }
            }
            /* printf("vos-backupsys DEBUG-20\n"); */
            if ((aserver && !same) || (apart && (apart != apart1))) {
                if (verbose) {
                    fprintf(STDOUT,
                            "Omitting to backup %s since the RW is in a different location\n",
                            vllist->name);
                }
                continue;
            }
            if (verbose) {
                time_t now = time(0);
                fprintf(STDOUT, "Creating backup volume for %s on %s", vllist->name, ctime(&now));
                fflush(STDOUT);
            }

            /* printf("vos-backupsys DEBUG-21\n"); */
            code = UV_BackupVolume(aserver1, apart1, avolid);
            if (code) {
                av_push(av2, newSVpv(vllist->name, strlen(vllist->name)));
                fprintf(STDOUT, "Could not backup %s\n", vllist->name);
                totalFail++;
            }
            else {
                av_push(av1, newSVpv(vllist->name, strlen(vllist->name)));
                totalBack++;
            }
        }                               /* process each vldb entry */

        /* printf("vos-backupsys DEBUG-22: Succ %d   Fail %d\n", totalBack, totalFail); */
        if (arrayEntries.nbulkentries_val)
            free(arrayEntries.nbulkentries_val);

        SETCODE(0);
        XPUSHs(sv_2mortal(newRV_inc((SV *) (av1))));
        XPUSHs(sv_2mortal(newRV_inc((SV *) (av2))));
        XSRETURN(2);
    }

void
vos_listpart(cstruct, server)
        AFS::VOS cstruct
        char *server
    PREINIT:
        int32 aserver, code;
        struct partList dummyPartList;
        int i, total, cnt;
        char pname[10];
    PPCODE:
    {
        aserver = GetServer(server);
        if (aserver == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }
        code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
        if (code) {
            PrintDiagnostics("listpart", code);
            XSRETURN_UNDEF;
        }
        total = 0;
        for (i = 0; i < cnt; i++) {
            if (dummyPartList.partFlags[i] & PARTVALID) {
                Zero(pname, 10, char);
                MapPartIdIntoName(dummyPartList.partId[i], pname);
                XPUSHs(sv_2mortal(newSVpv(pname, strlen(pname))));
                total++;
            }
        }

        SETCODE(0);
        XSRETURN(total);
    }

void
vos_listvolume(cstruct, name)
        AFS::VOS cstruct
        char *name
    PREINIT:
        struct nvldbentry entry;
        afs_int32 vcode = 0;
        volintInfo *pntr = (volintInfo *)0;
        afs_int32 volid;
        afs_int32 code, err;
        int voltype, foundserv = 0, foundentry = 0;
        afs_int32 aserver, apart;
        char apartName[10];
        int previdx = -1;
        HV *volinfo = (HV*)sv_2mortal((SV*)newHV());
    PPCODE:
    {
        volid = vsu_GetVolumeID(name, cstruct, &err);   /* -id */
        if (volid == 0) {
            char buffer[256];
            if (err)
                set_errbuff(buffer, err);
            else
                sprintf(buffer, "Unknown volume ID or name '%s'\n", name);
            VSETCODE(err ? err : -1, buffer);
            XSRETURN_UNDEF;
        }
        vcode = VLDB_GetEntryByID(volid, -1, &entry);
        if (vcode) {
            char buffer[256];
            sprintf(buffer, "Could not fetch the entry for volume number %u from VLDB \n", volid);
            VSETCODE(vcode, buffer);
            XSRETURN_UNDEF;
        }
        MapHostToNetwork(&entry);
        if (entry.volumeId[RWVOL] == volid)
            voltype = RWVOL;
        else if (entry.volumeId[BACKVOL] == volid)
            voltype = BACKVOL;
        else                            /* (entry.volumeId[ROVOL] == volid) */
            voltype = ROVOL;

        do {                            /* do {...} while (voltype == ROVOL) */
            /* Get the entry for the volume. If its a RW vol, get the RW entry.
             * It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
             * If its a RO vol, get the next RO entry.
             */
            GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), &aserver, &apart,
                             &previdx);
            if (previdx == -1) {        /* searched all entries */
                if (!foundentry) {
                    char buffer[256];
                    sprintf(buffer, "Volume %s does not exist in VLDB\n\n", name);
                    VSETCODE(ENOENT, buffer);
                    XSRETURN_UNDEF;
                }
                break;
            }
            foundentry = 1;

            /* Get information about the volume from the server */
            code = UV_ListOneVolume(aserver, apart, volid, &pntr);

            if (code) {
                char buffer[256];
                if (code == ENODEV) {
                    if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
                        /* The VLDB says there is no backup volume and its not on disk */
                        sprintf(buffer, "Volume %s does not exist\n", name);
                    }
                    else {
                        sprintf(buffer,
                                "Volume does not exist on server %s as indicated by the VLDB\n",
                                hostutil_GetNameByINet(aserver));
                    }
                }
                else {
                    sprintf(buffer, "examine");
                }
                if (pntr)
                    free(pntr);
                VSETCODE(code, buffer);
                XSRETURN_UNDEF;
            }
            else {
                foundserv = 1;
                MapPartIdIntoName(apart, apartName);
                /* safe_hv_store(volinfo, "name", 4, newSVpv(name, strlen((char *) name)), 0); */
                safe_hv_store(volinfo, "partition", 9, newSVpv(apartName, strlen((char *) apartName)), 0);
                VolumeStats(volinfo, pntr, &entry, aserver, apart, voltype);

                if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
                    /* The VLDB says there is no backup volume yet we found one on disk */
                    char buffer[256];
                    sprintf(buffer, "Volume %s does not exist in VLDB\n", name);
                    if (pntr)
                        free(pntr);
                    VSETCODE(ENOENT, buffer);
                    XSRETURN_UNDEF;
                }
            }

            if (pntr)
                free(pntr);
        } while (voltype == ROVOL);

        SETCODE(0);
        ST(0) = sv_2mortal(newRV_inc((SV *) volinfo));
        XSRETURN(1);
    }


MODULE = AFS     PACKAGE = AFS::VLDB       PREFIX = vldb_

AFS::VLDB
vldb_new(class=0, verb=0, timeout=90, noauth=0, localauth=0, tcell=NULL, crypt=0)
        char *  class
        int     verb
        int     timeout
        int     noauth
        int     localauth
        char *  tcell
        int     crypt
    PREINIT:
        int32 code = -1;
        extern int verbose;
    PPCODE:
    {
        if (tcell && (tcell[0] == '\0' || tcell[0] == '0'))
            tcell = NULL;

                /* Initialize the ubik_client connection */
        rx_SetRxDeadTime(timeout);      /* timeout seconds inactivity before declared dead */
        cstruct = (struct ubik_client *) 0;
        verbose = verb;
        if (crypt)                      /* -crypt specified */
            vsu_SetCrypt(1);
        code = internal_vsu_ClientInit((noauth != 0),
                                       AFSDIR_CLIENT_ETC_DIRPATH, tcell, localauth,
                                       &cstruct, UV_SetSecurity);
        if (code == 0) {
            ST(0) = sv_newmortal();
            sv_setref_pv(ST(0), "AFS::VLDB", (void *) cstruct);
            XSRETURN(1);
        }
        else
            XSRETURN_UNDEF;
    }

int32
vldb__DESTROY(self)
        AFS::VLDB self
    PREINIT:
        int32 code = 0;
    CODE:
    {
        code = ubik_ClientDestroy(self);
                /* printf("DEBUG-23 %d \n", code); */
        SETCODE(code);
                /* printf("DEBUG-24 \n"); */
        RETVAL = (code == 0);
                /* printf("DEBUG-25 \n"); */
    }
    OUTPUT:
        RETVAL

int32
vldb_addsite(cstruct, server, partition, id, roid=NULL, valid=0)
       AFS::VLDB cstruct
       char *server
       char *partition
       char *id
       char *roid
       int  valid
    PREINIT:
       int32 code = 1;
    CODE:
    {
        afs_int32 avolid, aserver, apart, err, arovolid=0;
        char avolname[VOLSER_MAXVOLNAME + 1];
        if (roid && (roid[0] == '\0' || roid[0] == '0'))
            roid = NULL;
        RETVAL = 0;
        /* printf("vldb_addsite DEBUG-1 server %s part %s Vol/Id %s RO-Vol/ID %s ValID %d \n", server, partition, id, roid, valid); */
#ifdef OpenAFS_1_4
        vsu_ExtractName(avolname, id);
#else

src/AFS.xs  view on Meta::CPAN

            char buffer[256];
            sprintf(buffer, "AFS::VLDB: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            goto done;
        }
        /* printf("DEBUG-3\n"); */
        apart = volutil_GetPartitionID(partition);
        if (apart < 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: could not interpret partition name '%s'\n", partition);
            VSETCODE(-1, buffer);
            /* printf("DEBUG-3.1\n"); */
            goto done;
        }
        /* printf("DEBUG-4\n"); */
        if (!IsPartValid(apart, aserver, &code)) {      /*check for validity of the partition */
            char buffer[256];
            if (code)
                set_errbuff(buffer, code);
            else
                sprintf(buffer, "AFS::VLDB: partition %s does not exist on the server\n", server);
            VSETCODE(code ? code : -1, buffer);
            goto done;
        }
        /* printf("DEBUG-5\n"); */
        code = UV_ChangeLocation(aserver, apart, avolid);
        if (code) {
            VSETCODE(code, "changeloc");
            goto done;
        }
        SETCODE(0);
        RETVAL = 1;

        done:
        ;
#else
        not_here("AFS::VLDB::changeloc");
#endif
    }
    OUTPUT:
        RETVAL

void
vldb__listvldb(cstruct, name=NULL, servername=NULL, parti=NULL, lock=0)
        AFS::VLDB cstruct
        char *name
        char *servername
        char *parti
        int lock
    PREINIT:
        afs_int32 apart;
        afs_int32 aserver, code;
        afs_int32 vcode;
        struct VldbListByAttributes attributes;
        nbulkentries arrayEntries;
        struct nvldbentry *vllist;
        afs_int32 centries, nentries = 0;
        int j;
        afs_int32 thisindex, nextindex;
        HV *status, *stats;
    PPCODE:
    {
        status = (HV *) sv_2mortal((SV *) newHV());
        if (name && strlen(name) == 0)
            name = NULL;
        if (servername && strlen(servername) == 0)
            servername = NULL;
        if (parti && strlen(parti) == 0)
            parti = NULL;

        /* printf("DEBUG-0 name %s, server %s, part %s lock %d \n", name, servername, parti,  */

        aserver = 0;
        apart = 0;

        attributes.Mask = 0;
        /* printf("DEBUG-1 \n"); */

            /* If the volume name is given, Use VolumeInfoCmd to look it up
             * and not ListAttributes.
             */
        if (name) {
          /* printf("DEBUG-2 \n"); */
            if (lock) {
                char buffer[256];
                /*     printf("DEBUG-3 \n"); */
                sprintf(buffer,
                        "AFS::VLDB: illegal use of '-locked' switch, need to specify server and/or partition\n");
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            /* printf("DEBUG-4 \n"); */
            stats = (HV *) sv_2mortal((SV *) newHV());
            code = VolumeInfoCmd(stats, name);
            if (code) {
                char buffer[256];
                set_errbuff(buffer, code);
                VSETCODE(code, buffer);
                XSRETURN_UNDEF;
            }
            /* printf("DEBUG-5 \n"); */
            safe_hv_store(status, name, strlen(name), newRV_inc((SV *) (stats)), 0);
            goto finish;
        }

            /* Server specified */
        /* printf("DEBUG-6 \n"); */
        if (servername) {
            /* printf("DEBUG-7 \n"); */
            aserver = GetServer(servername);
            if (aserver == 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VLDB: server '%s' not found in host table\n", servername);
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            attributes.server = ntohl(aserver);
            attributes.Mask |= VLLIST_SERVER;
        }

            /* Partition specified */

src/AFS.xs  view on Meta::CPAN

            /* Zero(&arrayEntries, sizeof(arrayEntries), nbulkentries);  ??? nog ???  */
            Zero(&arrayEntries, 1, nbulkentries);
            /* printf("DEBUG-14 \n"); */
            centries = 0;
            nextindex = -1;

            vcode = VLDB_ListAttributesN2(&attributes, 0, thisindex,
                                          &centries, &arrayEntries, &nextindex);
            /* printf("DEBUG-15 \n"); */
            if (vcode == RXGEN_OPCODE) {
                /* Vlserver not running with ListAttributesN2. Fall back */
                vcode = VLDB_ListAttributes(&attributes, &centries, &arrayEntries);
                nextindex = -1;
            }
            /* printf("DEBUG-16 \n"); */
            if (vcode) {
                char buffer[256];
                sprintf(buffer, "Could not access the VLDB for attributes\n");
                VSETCODE(vcode, buffer);
                XSRETURN_UNDEF;
            }
            nentries += centries;

            /* We don't sort, so just print the entries now */
            /* printf("DEBUG-17 \n"); */
            for (j = 0; j < centries; j++) {    /* process each entry */
                /* printf("DEBUG-18 \n"); */
                vllist = &arrayEntries.nbulkentries_val[j];
                MapHostToNetwork(vllist);
                stats = newHV();
                myEnumerateEntry(stats, vllist);
                safe_hv_store(status, vllist->name, strlen(vllist->name), newRV_inc((SV *) (stats)),
                         0);
            }
            if (arrayEntries.nbulkentries_val)
                free(arrayEntries.nbulkentries_val);
        }

        finish:
        /* printf("DEBUG-19 \n"); */
        SETCODE(0);
        ST(0) = sv_2mortal(newRV_inc((SV *) status));
        XSRETURN(1);
    }

void
vldb_listaddrs(cstruct, host=NULL, uuid=NULL, noresolve=0, printuuid=0)
        AFS::VLDB cstruct
        char *host
        char *uuid
        int noresolve
        int printuuid
    PREINIT:
        afs_int32 vcode;
        afs_int32 i, j;
        afs_int32            nentries;
        bulkaddrs            m_addrs;
        ListAddrByAttributes m_attrs;
        afsUUID              m_uuid, askuuid;
        afs_int32            m_unique, m_nentries;
    PPCODE:
    {
        Zero(&m_attrs, 1, ListAddrByAttributes);
        m_attrs.Mask = VLADDR_INDEX;

        Zero(&m_addrs, 1, bulkaddrs);
        Zero(&askuuid, 1, afsUUID);
#ifdef OpenAFS
        if (uuid && strlen(uuid) != 0) {
            /* -uuid */
            afsUUID_from_string(uuid, &askuuid);
            m_attrs.Mask = VLADDR_UUID;
            m_attrs.uuid = askuuid;
        }
        else
#endif
            uuid = NULL;

        if (host && strlen(host) != 0) {
            /* -host */
            struct hostent *he;
            afs_int32 saddr;
            he = (struct hostent *) hostutil_GetHostByName(host);
            if (he == (struct hostent *) 0) {
                char buffer[256];
                sprintf(buffer, "Can't get host info for '%s'\n", host);
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            /*memcpy(&saddr, he->h_addr, 4); */
            /* Copy(he->h_addr, &saddr, sizeof(afs_int32), afs_int32); */
            Copy(he->h_addr, &saddr, he->h_length, char);
            m_attrs.Mask = VLADDR_IPADDR;
            m_attrs.ipaddr = ntohl(saddr);
        }
        else
            host = NULL;

        m_addrs.bulkaddrs_val = 0;
        m_addrs.bulkaddrs_len = 0;

        vcode = ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &m_unique, &nentries, &m_addrs);
        if (vcode) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: could not list the server addresses\n");
            VSETCODE(vcode, buffer);
            XSRETURN_UNDEF;
        }

        m_nentries = 0;
        m_addrs.bulkaddrs_val = 0;
        m_addrs.bulkaddrs_len = 0;
        i = 1;
        j = 0;
        while (1) {
            HV *addr = (HV *) sv_2mortal((SV *) newHV());
            m_attrs.index = i;

            vcode = ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
                                  &m_unique, &m_nentries, &m_addrs);
            if (vcode == VL_NOENT) {
                i++;
                nentries++;
                continue;
            }

            if (vcode == VL_INDEXERANGE) {
                vcode = 0;
                break;
            }

            if (vcode) {
                char buffer[256];
                sprintf(buffer, "AFS::VLDB: could not list the server addresses\n");
                VSETCODE(vcode, buffer);
                XSRETURN_UNDEF;
            }

            myprint_addrs(addr, &m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
            XPUSHs(sv_2mortal(newRV_inc((SV *) (addr))));
            i++;
            j++;

            if (host || uuid || (i > nentries))
                break;
        }

        SETCODE(vcode);
        XSRETURN(j);
    }

void
vldb__delentry(cstruct, volume=NULL, prfx=NULL, server=NULL, partition=NULL, noexecute=0)
        AFS::VLDB cstruct
        SV* volume
        char *prfx
        char *server
        char *partition
        int noexecute
    PREINIT:
        afs_int32 apart;
        afs_int32 avolid;
        afs_int32 vcode = 0;
        struct VldbListByAttributes attributes;
        nbulkentries arrayEntries;
        register struct nvldbentry *vllist;
        SV *vol;
        char *itp;
        afs_int32 nentries;
        int j;
        char prefix[VOLSER_MAXVOLNAME+1];
        int seenprefix=0;
        STRLEN volumelength=0;
        afs_int32 totalBack=0, totalFail=0, err;
        AV *av;
    PPCODE:
    {
        if (prfx && strlen(prfx) == 0)
            prfx = NULL;
        if (partition && strlen(partition) == 0)
            partition = NULL;
        if (server && strlen(server) == 0)
            server = NULL;

        if (volume && (volumelength = sv_len(volume)) == 0)
            volume = NULL;

        if (volume && (! (SvTYPE(SvRV(volume)) == SVt_PVAV))) {
            VSETCODE(-1, "AFS::VLDB: VOLUME not array reference");
            XSRETURN_UNDEF;
        }

        if (volume) {                       /* -id */
            int len;
            if (prfx || server || partition) {
                VSETCODE(-1, "You cannot use SERVER, PARTITION, or PREFIX with the VOLUME argument");
                XSRETURN_UNDEF;
            }
            av = (AV *) SvRV(volume);
            len = av_len(av);
            if (len != -1) {
                for (j = 0; j <= len; j++) {
                    vol = *av_fetch(av, j, 0);
                    itp = SvPV_nolen(vol);
                    if (itp) {
                        avolid = vsu_GetVolumeID(itp, cstruct, &err);
                        if (avolid == 0) {
                            char buffer[256];
                            if (err)
                                set_errbuff(buffer, err);
                            else
                                sprintf(buffer, "AFS::VLDB: can't find volume '%s'\n", itp);
                            VSETCODE(err ? err : -1, buffer);
                            continue;
                        }
                        if (noexecute) {        /* -noexecute */
                            fprintf(STDOUT, "Would have deleted VLDB entry for %s \n", itp);
                            fflush(STDOUT);
                            continue;
                        }
                        vcode = ubik_Call(VL_DeleteEntry, cstruct, 0, avolid, RWVOL);
                        if (vcode) {
                            char buffer[256];
                            sprintf(buffer, "Could not delete entry for volume %s\n"
                                    "You must specify a RW volume name or ID "
                                    "(the entire VLDB entry will be deleted)\n", itp);
                            VSETCODE(vcode, buffer);
                            totalFail++;
                            continue;
                        }
                        totalBack++;
                    }
                }                       /* for */
            }                           /* len */
            EXTEND(sp, 2);
            PUSHs(sv_2mortal(newSViv(totalBack)));

src/AFS.xs  view on Meta::CPAN

    {
        RETVAL = 0;
        tserver = GetServer(servername);
        if (!tserver) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: host '%s' not found in host table\n", servername);
            VSETCODE(-1, buffer);
            goto done;
        }
        if (parti && (strlen(parti) != 0)) {
            pname = volutil_GetPartitionID(parti);
            if (pname < 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VLDB: could not interpret partition name '%s'\n", parti);
                VSETCODE(-1, buffer);
                goto done;
            }
            if (!IsPartValid(pname, tserver, &code)) {  /*check for validity of the partition */
                char buffer[256];
                if (code)
                    set_errbuff(buffer, code);
                else
                    sprintf(buffer, "AFS::VLDB: partition %s does not exist on the server\n",
                            parti);
                VSETCODE(code ? code : -1, buffer);
                goto done;
            }
            flags = 1;
        }

        code = UV_SyncServer(tserver, pname, flags, 0 /*unused */ );
        if (code) {
            PrintDiagnostics("syncserv", code);
            SETCODE(code);
            goto done;
        }

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL


MODULE = AFS            PACKAGE = AFS::BOS      PREFIX = bos_

AFS::BOS
bos_new(class=0, servname, noauth=0, localauth=0, cell=0, aencrypt=1)
        char *  class
        char *servname
        int noauth
        int localauth
        char *cell
        int aencrypt
    PREINIT:
        int32 code = -1;
        AFS__BOS server;
    PPCODE:
    {
        /* printf("bos new DEBUG-1 \n"); */
        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        /* printf("bos new call internal_new DEBUG-2 \n"); */
        server = internal_bos_new(&code, servname, localauth, noauth, aencrypt, cell);
            /* SETCODE(code); */
        /* printf("bos new return internal_new DEBUG-3 \n"); */

        if (code == 0) {
            ST(0) = sv_newmortal();
            sv_setref_pv(ST(0), "AFS::BOS", (void *) server);
            XSRETURN(1);
        }
        else
            XSRETURN_UNDEF;
    }

int32
bos__DESTROY(self)
        AFS::BOS self
    CODE:
    {
        rx_DestroyConnection(self);
        /* printf("bos DEBUG rx_Destroy\n"); */
        RETVAL = 1;
    }
    OUTPUT:
        RETVAL

void
bos__status(self, lng=0, object=NULL)
        AFS::BOS self
        int lng
        SV* object
    PREINIT:
        int i;
        afs_int32 code = 0;
        char ibuffer[BOZO_BSSIZE];
        char *tp;
        int int32p;
        HV *status, *stats;
    PPCODE:
    {
        int32p = (lng != 0 ? 2 : 0);
        status = (HV *) sv_2mortal((SV *) newHV());

        if (object && (! (SvTYPE(SvRV(object)) == SVt_PVAV))) {
            BSETCODE(-1, "AFS::BOS: SERVER not an array reference\n");
            XSRETURN_UNDEF;
            goto done;
        }

        if (object && (SvTYPE(SvRV(object)) == SVt_PVAV)) {
            AV *av;
            SV *sv;
            char *instance;
            STRLEN namelen;
            int i, len;
            int firstTime = 1;

            av = (AV *) SvRV(object);
            len = av_len(av);
            if (len != -1) {
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                        stats = (HV *) sv_2mortal((SV *) newHV());
                        instance = (char *) safemalloc(BOZO_BSSIZE);
                        instance = SvPV(sv, namelen);
                        code = DoStat(stats, instance, self, int32p, firstTime);
                        if (code) {
                            XSRETURN_UNDEF;
                            goto done;
                        }
                        safe_hv_store(status, instance, strlen(instance), newRV_inc((SV *) (stats)),
                                 0);
                        firstTime = 0;
                    }
                }
            }
        }
        else {
            for (i = 0;; i++) {
                /* for each instance */
                tp = ibuffer;
                code = BOZO_EnumerateInstance(self, i, &tp);
                if (code == BZDOM) {
                    code = 0;
                    break;
                }
                if (code) {
                    char buffer[256];
                    sprintf(buffer, "AFS::BOS: failed to contact host's bosserver (%s).\n",
                            em(code));
                    BSETCODE(code, buffer);
                    break;
                }
                stats = (HV *) sv_2mortal((SV *) newHV());
                code = DoStat(stats, ibuffer, self, int32p, (i == 0));
                if (code) {
                    XSRETURN_UNDEF;
                    goto done;

src/AFS.xs  view on Meta::CPAN

        }
        if (!newbinary) {
            newbinary = newSViv(0);
        }
        if (!SvIOKp(newbinary)) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: Flag \"newbinary\" should be numeric.\n");
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }
        igeneral = SvIV(general);
        inewbinary = SvIV(newbinary);
        if (igeneral) {
            count++;
            type = 1;
        }
        if (inewbinary) {
            count++;
            type = 2;
        }
        if (count > 1) {
            char buffer[80];
            sprintf(buffer, "AFS::BOS: can't specify more than one restart time at a time\n");
            BSETCODE(-1, buffer);
            goto done;
        }
        if (count == 0)
            type = 1;                   /* by default set general restart time */

        if (code = ktime_ParsePeriodic(time, &restartTime)) {
            char buffer[240];
            sprintf(buffer, "AFS::BOS: failed to parse '%s' as periodic restart time(%s)\n",
                    time, em(code));
            BSETCODE(code, buffer);
            goto done;
        }

        code = BOZO_SetRestartTime(self, type, &restartTime);
        if (code) {
            char buffer[240];
            sprintf(buffer, "AFS::BOS: failed to set restart time at server (%s)\n", em(code));
            BSETCODE(code, buffer);
            goto done;
        }
        code = 0;
        SETCODE(code);

        done:
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

void
bos_getrestart(self)
        AFS::BOS self
    PREINIT:
        int32 code = 0;
        struct ktime generalTime, newBinaryTime;
        char messageBuffer[256];
    PPCODE:
    {
        code = BOZO_GetRestartTime(self, 1, &generalTime);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to retrieve restart information (%s)\n", em(code));
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
        }
        code = BOZO_GetRestartTime(self, 2, &newBinaryTime);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to retrieve restart information (%s)\n", em(code));
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
        }

        code = ktime_DisplayString(&generalTime, messageBuffer);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to decode restart time (%s)\n", em(code));
            BSETCODE(code, buffer);
            strcpy(messageBuffer, "");
        }
        XPUSHs(sv_2mortal(newSVpv(messageBuffer, strlen(messageBuffer))));

        code = ktime_DisplayString(&newBinaryTime, messageBuffer);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to decode restart time (%s)\n", em(code));
            BSETCODE(code, buffer);
            strcpy(messageBuffer, "");
        }
        XPUSHs(sv_2mortal(newSVpv(messageBuffer, strlen(messageBuffer))));

        XSRETURN(2);
    }

void
bos_listusers(self)
        AFS::BOS self
    PREINIT:
        int i;
        int32 code = 0;
        char tbuffer[256];
        char *tp;
    PPCODE:
    {
        for (i = 0;; i++) {
            tp = tbuffer;
            code = BOZO_ListSUsers(self, i, &tp);
            if (code)
                break;
            XPUSHs(sv_2mortal(newSVpv(tbuffer, strlen(tbuffer))));
        }

        if (code != 1) {
            /* a real error code, instead of scanned past end */
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to retrieve super-user list (%s)\n", em(code));
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
        }
        else {
            SETCODE(0);
            XSRETURN(i);
        }
    }

void
bos_listhosts(self)
        AFS::BOS self
    PREINIT:
        int32 i, code = 0;
        char tbuffer[256];
        char *tp;
        AV *av = (AV*)sv_2mortal((SV*)newAV());
    PPCODE:
    {
        tp = tbuffer;
        code = BOZO_GetCellName(self, &tp);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to get cell name (%s)\n", em(code));
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
        }
            /* printf("Cell name is %s\n", tbuffer); */
        XPUSHs(sv_2mortal(newSVpv(tbuffer, strlen(tbuffer))));

        for (i = 0;; i++) {
            code = BOZO_GetCellHost(self, i, &tp);
            if (code == BZDOM)
                break;
            if (code != 0) {
                char buffer[256];
                sprintf(buffer, "AFS::BOS: failed to get cell host %d (%s)\n", i, em(code));
                BSETCODE(code, buffer);
                XSRETURN_UNDEF;
            }
            /* printf("    Host %d is %s\n", i+1, tbuffer); */
            av_push(av, newSVpv(tbuffer, strlen(tbuffer)));
        }

        XPUSHs(sv_2mortal(newRV_inc((SV *) (av))));

        SETCODE(0);
        XSRETURN(2);
    }

int32
bos_delete(self, object)
        AFS::BOS self
        SV* object
    PREINIT:
        int32 code = 0, len, i;
        AV *av; SV *sv;
        char *name;
        STRLEN namelen;
    CODE:
    {
/*         printf("DEBUG-bos-delete-1 \n");  */
        if (!SvROK(object)) {
/*         printf("DEBUG-bos-delete-2 \n"); */
            name = (char *) SvPV_nolen(object);
            code = BOZO_DeleteBnode(self, name);
            if (code) {
                char buffer[256];
/*         printf("DEBUG-bos-delete-3 %d \n", code); */
                if (code == BZBUSY)
                    sprintf(buffer, "AFS::BOS: can't delete running instance '%s'\n", name);
                else
                    sprintf(buffer, "AFS::BOS: failed to delete instance '%s' (%s)\n", name,
                            em(code));
                BSETCODE(code, buffer);
/*         printf("DEBUG-bos-delete-4 %s \n", buffer); */
                goto done;
            }
        }
        else if (SvTYPE(SvRV(object)) == SVt_PVAV) {
/*         printf("DEBUG-bos-delete-5 \n"); */
            av = (AV *) SvRV(object);
            len = av_len(av);
            if (len != -1) {
/*         printf("DEBUG-bos-delete-6 \n"); */
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                        name = (char *) safemalloc(BOZO_BSSIZE);
                        name = SvPV(sv, namelen);
/*         printf("DEBUG-bos-delete-7 %s\n", name); */
                        code = BOZO_DeleteBnode(self, name);
/*         printf("DEBUG-bos-delete-8 %d \n", code); */
                        if (code) {
                            char buffer[256];
                            if (code == BZBUSY)
                                sprintf(buffer, "AFS::BOS: can't delete running instance '%s'\n",
                                        name);
                            else
                                sprintf(buffer, "AFS::BOS: failed to delete instance '%s' (%s)\n",
                                        name, em(code));
                            BSETCODE(code, buffer);
                            goto done;
                        }
                    }
                }                       /* for loop */
            }
        }
        SETCODE(0);
/*         printf("DEBUG-bos-delete-9 \n"); */

        done:
        RETVAL = (code == 0);
/*         printf("DEBUG-bos-delete-10 \n"); */
/*         if (name) */
/*             Safefree(name); */
/*         printf("DEBUG-bos-delete-11 \n"); */
    }
    OUTPUT:
        RETVAL

void
bos_getlog(self, file)
        AFS::BOS self
        char* file
    PREINIT:
        register struct rx_call *tcall;
        int32 code = 0;
        char buf, c[255];
        int error, num = 0, i = 0;
    PPCODE:
    {
        tcall = rx_NewCall(self);
        code = StartBOZO_GetLog(tcall, file);
        if (code) {
            char buffer[256];
            rx_EndCall(tcall, code);
            sprintf(buffer, "AFS::BOS error %d (while reading log)\n", code);
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
        }

            /* copy data */
        error = 0;
        while (1) {
            code = rx_Read(tcall, &buf, 1);
            if (code != 1) {
                error = EIO;
                break;
            }
            if (buf == 0)
                break;                  /* the end delimeter */
            /* putchar(buf); */
            c[i++] = buf;
            if (buf == '\n') {
                XPUSHs(sv_2mortal(newSVpv(c, i)));
                i = 0;
                num++;
            }
        }

        code = rx_EndCall(tcall, error);
        #if (tcall)
        #    Safefree(tcall);
            /* fall through into cleanup code */
        XSRETURN(num);
    }

int32
bos__start(self, object=NULL)
        AFS::BOS self
        SV * object
    PREINIT:
        int32 code = 0;
    CODE:
    {
        if (object && (! (SvTYPE(SvRV(object)) == SVt_PVAV))) {
            code = -1;
            BSETCODE(code, "AFS::BOS: SERVER not an array reference\n");
            goto done;
        }

        if (object && (SvTYPE(SvRV(object)) == SVt_PVAV)) {
            AV *av;
            SV *sv;
            char *instance;
            STRLEN namelen;
            int i, len;

            av = (AV *) SvRV(object);
            len = av_len(av);

src/AFS.xs  view on Meta::CPAN

            }
        }
        else {
            code = BOZO_ShutdownAll(self);
            if (code) {
                char buffer[256];
                sprintf(buffer, "AFS::BOS: failed to shutdown servers (%s)\n", em(code));
                BSETCODE(code, buffer);
                goto done;
            }
        }

        if (wait) {
            code = BOZO_WaitAll(self);
            if (code) {
                char buffer[256];
                sprintf(buffer, "AFS::BOS: can't wait for processes to shutdown (%s)\n",
                        em(code));
                BSETCODE(code, buffer);
                goto done;
            }
        }
        SETCODE(code);
        done:
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
bos_setcellname(self, name)
        AFS::BOS self
        char *name
    PREINIT:
        int32 code = 0;   
    CODE:
    {
        not_here("AFS::BOS::setcellname");

        code = BOZO_SetCellName(self, name);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to set cell (%s)\n", em(code));
            BSETCODE(code, buffer);
        }
    }
    OUTPUT:
        RETVAL

void
bos_listkeys(self, showkey=0)
        AFS::BOS self
        int showkey
    PREINIT:
        afs_int32 i, kvno, code = 0;
        struct ktc_encryptionKey tkey;
        struct bozo_keyInfo keyInfo;
        int everWorked = 0;
        char index[5];
        HV *list = (HV*)sv_2mortal((SV*)newHV());
    PPCODE:
    {
        for (i = 0;; i++) {
            HV *key = (HV *) sv_2mortal((SV *) newHV());
            code = BOZO_ListKeys(self, i, &kvno, &tkey, &keyInfo);
            if (code)
                break;
            everWorked = 1;
            /* first check if key is returned */
            if ((!ka_KeyIsZero((char *) &tkey, sizeof(tkey))) && showkey) {
                /* ka_PrintBytes ((char *)&tkey, sizeof(tkey)); */
                safe_hv_store(key, "key", 3, newSVpv((char *) &tkey, sizeof(tkey)), 0);
            }
            else {
                if (keyInfo.keyCheckSum == 0) { /* shouldn't happen */
                    /* printf ("key version is %d\n", kvno); */
                }
                else {
                    safe_hv_store(key, "keyCheckSum", 11, newSVuv(keyInfo.keyCheckSum), 0);
                }
            }
            sprintf(index, "%d", kvno);
            safe_hv_store(list, index, strlen(index), newRV_inc((SV *) (key)), 0);
        }                               /* for loop */

        if (everWorked) {
            /* fprintf(stderr, "Keys last changed on %d.\n", keyInfo.mod_sec); */
            EXTEND(sp, 2);
            PUSHs(sv_2mortal(newSViv(keyInfo.mod_sec)));
            PUSHs(newRV_inc((SV *) (list)));
        }
        if (code != BZDOM) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: %s error encountered while listing keys\n", em(code));
            BSETCODE(code, buffer);
        }
        else {
            code = 0;
        }

        if (everWorked) {
            XSRETURN(2);
        }
        else {
            XSRETURN_EMPTY;
            hv_undef(list);
        }
    }

int32
bos_getrestricted(self)
        AFS::BOS self
    CODE:
    {
#ifdef BOS_RESTRICTED_MODE
        int32 val, code;
        RETVAL = 0;
        code = BOZO_GetRestrictedMode(self, &val);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to get restricted mode (%s)\n", em(code));

src/AFS.xs  view on Meta::CPAN

            confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
            code = internal_vsu_ClientInit( /* noauth */ 1, confdir, tmpname,
                                  /* server auth */ 0, &cstruct, (int (*)()) 0);
            if (code == 0) {
                newID = vsu_GetVolumeID(volume, cstruct, &err);
                if (newID == 0) {
                    char buffer[256];
                    sprintf(buffer, "AFS::BOS: can't interpret %s as volume name or ID\n",
                            volume);
                    BSETCODE(-1, buffer);
                    goto done;
                }
                sprintf(tname, "%u", newID);
            }
            else {
                char buffer[256];
                sprintf(buffer,
                        "AFS::BOS: can't initialize volume system client (code %d), trying anyway.\n",
                        code);
                BSETCODE(code, buffer);
                strncpy(tname, volume, sizeof(tname));
            }
            if (volutil_GetPartitionID(partition) < 0) {
                /* can't parse volume ID, so complain before shutting down
                 * file server.
                 */
                char buffer[256];
                sprintf(buffer, "AFS::BOS: can't interpret %s as partition ID.\n", partition);
                BSETCODE(-1, buffer);
                goto done;
            }
            /* fprintf(stderr, "Starting salvage of volume %d on partition %s.\n",
               newID, partition); */
            rc = DoSalvage(self, partition, tname, outName, showlog, parallel, tmpDir, orphans);
            if (rc) {
                code = rc;
                goto done;
            }
        }

        code = 0;
        SETCODE(code);

        done:
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL


MODULE = AFS            PACKAGE = AFS::PTS      PREFIX = pts_

AFS::PTS
pts__new(class=0, sec=1, cell=0)
        char *  class
        int32   sec
        char *  cell
    PREINIT:
        int32 code = -1;
        AFS__PTS server;
    PPCODE:
    {
        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        server = internal_pts_new(&code, sec, cell);
        # SETCODE(code);  wird tiefer gesetzt...

        if (code == 0) {
            ST(0) = sv_newmortal();
            sv_setref_pv(ST(0), "AFS::PTS", (void *) server);
            XSRETURN(1);
        }
        else
            XSRETURN_UNDEF;
    }

int32
pts__DESTROY(server)
        AFS::PTS server
    CODE:
    {
        int32 code;
        /* printf("pts DEBUG ubik_ClientDestroy\n"); */
        code = ubik_ClientDestroy(server);
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL  

void
pts_id(server,object,anon=1)
        AFS::PTS server
        SV *    object
        int32   anon
    PPCODE:
    {
        if (!SvROK(object)) {
            int32 code, id;
            char *name;
            name = (char *) SvPV(object, PL_na);
            code = internal_pr_id(server, name, &id, anon);
            ST(0) = sv_newmortal();
            SETCODE(code);
            if (code == 0)
                sv_setiv(ST(0), id);
            XSRETURN(1);
        }
        else if (SvTYPE(SvRV(object)) == SVt_PVAV) {
            int32 code, id;
            int i, len;
            AV *av;
            SV *sv;
            char *name;
            STRLEN namelen;
            namelist lnames;
            idlist lids;

            av = (AV *) SvRV(object);
            len = av_len(av);
            if (len != -1) {
                lnames.namelist_len = len + 1;
                lnames.namelist_val = (prname *) safemalloc(PR_MAXNAMELEN * (len + 1));
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                        name = SvPV(sv, namelen);
                        strncpy(lnames.namelist_val[i], name, PR_MAXNAMELEN);
                    }
                }
                lids.idlist_len = 0;
                lids.idlist_val = 0;

                code = ubik_Call(PR_NameToID, server, 0, &lnames, &lids);
                SETCODE(code);
                if (code == 0 && lids.idlist_val) {
                    EXTEND(sp, lids.idlist_len);
                    for (i = 0; i < lids.idlist_len; i++) {
                        id = lids.idlist_val[i];
                        if (id == ANONYMOUSID && !anon) {
                            PUSHs(sv_newmortal());
                        }
                        else {
                            PUSHs(sv_2mortal(newSViv(id)));
                        }
                    }
                    if (lids.idlist_val)
                        free(lids.idlist_val);
                }
                if (lnames.namelist_val)
                    safefree(lnames.namelist_val);
                PUTBACK;
                return;
            }
        }
        else if (SvTYPE(SvRV(object)) == SVt_PVHV) {

src/AFS.xs  view on Meta::CPAN


            hv = (HV *) SvRV(object);
            len = 0;

            hv_iterinit(hv);
            while (hv_iternext(hv))
                len++;
            if (len != 0) {
                lnames.namelist_len = len;
                lnames.namelist_val = (prname *) safemalloc(PR_MAXNAMELEN * len);
                hv_iterinit(hv);
                i = 0;
                while ((he = hv_iternext(hv))) {
                    key = hv_iterkey(he, &keylen);
                    strncpy(lnames.namelist_val[i], key, PR_MAXNAMELEN);
                    i++;
                }
                lids.idlist_len = 0;
                lids.idlist_val = 0;

                code = ubik_Call(PR_NameToID, server, 0, &lnames, &lids);
                SETCODE(code);
                if (code == 0 && lids.idlist_val) {
                    hv_iterinit(hv);
                    i = 0;
                    while ((he = hv_iternext(hv))) {
                        key = hv_iterkey(he, &keylen);
                        id = lids.idlist_val[i];
                        if (id == ANONYMOUSID && !anon) {
                            safe_hv_store(hv, key, keylen, newSVsv(&PL_sv_undef), 0);
                        }
                        else {
                            safe_hv_store(hv, key, keylen, newSViv(id), 0);
                        }
                        i++;
                    }
                    if (lids.idlist_val)
                        free(lids.idlist_val);
                }
                if (lnames.namelist_val)
                    safefree(lnames.namelist_val);
            }
            if (code == 0) {
                ST(0) = sv_2mortal(newRV_inc((SV *) hv));
            }
            else {
                ST(0) = sv_newmortal();
            }

            XSRETURN(1);
        }
        else {
            croak("object is not a scaler, ARRAY reference, or HASH reference");
        }
    }

void
pts_PR_NameToID(server,object)
        AFS::PTS server
        SV *    object
    PPCODE:
    {
        int32 code, id;
        int i, len;
        AV *av;
        SV *sv;
        char *name;
        STRLEN namelen;
        namelist lnames;
        idlist lids;

        if (!SvROK(object) || SvTYPE(SvRV(object)) != SVt_PVAV) {
            croak("object is not an ARRAY reference");
        }

        av = (AV *) SvRV(object);
        len = av_len(av);
        if (len != -1) {
            lnames.namelist_len = len + 1;
            lnames.namelist_val = (prname *) safemalloc(PR_MAXNAMELEN * (len + 1));
            for (i = 0; i <= len; i++) {
                sv = *av_fetch(av, i, 0);
                if (sv) {
                    name = SvPV(sv, namelen);
                    strncpy(lnames.namelist_val[i], name, PR_MAXNAMELEN);
                }
            }
            lids.idlist_len = 0;
            lids.idlist_val = 0;

            code = ubik_Call(PR_NameToID, server, 0, &lnames, &lids);
            SETCODE(code);
            if (code == 0 && lids.idlist_val) {
                EXTEND(sp, lids.idlist_len);
                for (i = 0; i < lids.idlist_len; i++) {
                    id = lids.idlist_val[i];
                    PUSHs(sv_2mortal(newSViv(id)));
                }
                if (lids.idlist_val)
                    free(lids.idlist_val);
            }
            if (lnames.namelist_val)
                safefree(lnames.namelist_val);
            PUTBACK;
            return;
        }
    }

void
pts_name(server,object,anon=1)
        AFS::PTS server
        SV *    object
        int32   anon
    PPCODE:
    {
        if (!SvROK(object)) {
            int32 code, id;
            char name[PR_MAXNAMELEN];
            id = SvIV(object);
            code = internal_pr_name(server, id, name);
            SETCODE(code);
            ST(0) = sv_newmortal();
            if (code == 0) {
                if (!anon && check_name_for_id(name, id)) {
                    /* return undef */
                }
                else {
                    sv_setpv(ST(0), name);
                }
            }
            XSRETURN(1);
        }
        else if (SvTYPE(SvRV(object)) == SVt_PVAV) {
            int32 code;
            int i, len;
            AV *av;
            SV *sv;
            char *name;
            namelist lnames;
            idlist lids;

            av = (AV *) SvRV(object);
            len = av_len(av);
            if (len != -1) {
                lids.idlist_len = len + 1;
                lids.idlist_val = (int32 *) safemalloc(sizeof(int32) * (len + 1));
                lnames.namelist_len = 0;
                lnames.namelist_val = 0;
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                        lids.idlist_val[i] = SvIV(sv);
                    }
                }
                code = ubik_Call(PR_IDToName, server, 0, &lids, &lnames);
                SETCODE(code);
                if (code == 0 && lnames.namelist_val) {
                    EXTEND(sp, lnames.namelist_len);
                    for (i = 0; i < lnames.namelist_len; i++) {
                        name = lnames.namelist_val[i];
                        if (!anon && check_name_for_id(name, lids.idlist_val[i])) {
                            PUSHs(sv_newmortal());
                        }
                        else {
                            PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
                        }
                    }
                    if (lnames.namelist_val)
                        free(lnames.namelist_val);
                }
                if (lids.idlist_val)
                    safefree(lids.idlist_val);
                PUTBACK;
                return;

src/AFS.xs  view on Meta::CPAN

            len = 0;

            hv_iterinit(hv);
            while (hv_iternext(hv))
                len++;
            if (len != 0) {
                lids.idlist_len = len;
                lids.idlist_val = (int32 *) safemalloc(sizeof(int32) * len);
                lnames.namelist_len = 0;
                lnames.namelist_val = 0;

                hv_iterinit(hv);
                i = 0;
                sv = sv_newmortal();
                while ((he = hv_iternext(hv))) {
                    key = hv_iterkey(he, &keylen);
                    sv_setpvn(sv, key, keylen);
                    lids.idlist_val[i] = SvIV(sv);
                    i++;
                }

                code = ubik_Call(PR_IDToName, server, 0, &lids, &lnames);
                SETCODE(code);
                if (code == 0 && lnames.namelist_val) {
                    hv_iterinit(hv);
                    i = 0;
                    while ((he = hv_iternext(hv))) {
                        key = hv_iterkey(he, &keylen);
                        name = lnames.namelist_val[i];
                        if (!anon && check_name_for_id(name, lids.idlist_val[i])) {
                            safe_hv_store(hv, key, keylen, newSVsv(&PL_sv_undef), 0);
                        }
                        else {
                            safe_hv_store(hv, key, keylen, newSVpv(name, strlen(name)), 0);
                        }
                        i++;
                    }
                    if (lnames.namelist_val)
                        free(lnames.namelist_val);
                }
                if (lids.idlist_val)
                    safefree(lids.idlist_val);
            }
            if (code == 0) {
                ST(0) = sv_2mortal(newRV_inc((SV *) hv));
            }
            else {
                ST(0) = sv_newmortal();
            }
            XSRETURN(1);
        }
        else {
            croak("object is not a scaler, ARRAY reference, or HASH reference");
        }
    }

void
pts_PR_IDToName(server,object)
        AFS::PTS server
        SV *    object
    PPCODE:
    {
        int32 code;
        int i, len;
        AV *av;
        SV *sv;
        char *name;
        namelist lnames;
        idlist lids;

        if (!SvROK(object) || SvTYPE(SvRV(object)) != SVt_PVAV) {
            croak("object is not an ARRAY reference");
        }

        av = (AV *) SvRV(object);
        len = av_len(av);
        if (len != -1) {
            lids.idlist_len = len + 1;
            lids.idlist_val = (int32 *) safemalloc(sizeof(int32) * (len + 1));
            lnames.namelist_len = 0;
            lnames.namelist_val = 0;
            for (i = 0; i <= len; i++) {
                sv = *av_fetch(av, i, 0);
                if (sv) {
                    lids.idlist_val[i] = SvIV(sv);
                }
            }
            code = ubik_Call(PR_IDToName, server, 0, &lids, &lnames);
            SETCODE(code);
            if (code == 0 && lnames.namelist_val) {
                EXTEND(sp, lnames.namelist_len);
                for (i = 0; i < lnames.namelist_len; i++) {
                    name = lnames.namelist_val[i];
                    PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
                }
                if (lnames.namelist_val)
                    free(lnames.namelist_val);
            }
            if (lids.idlist_val)
                safefree(lids.idlist_val);
            PUTBACK;
            return;
        }
    }

void
pts_members(server,name,convertids=1,over=0)
        AFS::PTS server
        char *  name
        int32   convertids
        int32   over
    PPCODE:
    {
        int32 code, wentover, id;
        int i;
        prlist list;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0) {
            list.prlist_val = 0;
            list.prlist_len = 0;
            code = ubik_Call(PR_ListElements, server, 0, id, &list, &wentover);
            if (items == 4)
                sv_setiv(ST(3), (IV) wentover);
            if (code == 0) {
                if (convertids) {
                    namelist lnames;
                    lnames.namelist_len = 0;
                    lnames.namelist_val = 0;
                    code = ubik_Call(PR_IDToName, server, 0, &list, &lnames);
                    if (code == 0 && lnames.namelist_val) {
                        EXTEND(sp, lnames.namelist_len);
                        for (i = 0; i < lnames.namelist_len; i++) {
                            name = lnames.namelist_val[i];
                            PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
                        }
                        if (lnames.namelist_val)
                            free(lnames.namelist_val);
                    }
                }
                else {
                    EXTEND(sp, list.prlist_len);
                    for (i = 0; i < list.prlist_len; i++) {
                        PUSHs(sv_2mortal(newSViv(list.prlist_val[i])));
                    }
                }
            }
            if (list.prlist_val)
                free(list.prlist_val);
        }
        else {
            if (items == 4)
                sv_setiv(ST(3), (IV) 0);
        }

        SETCODE(code);
     }

void
pts_PR_ListElements(server,id,over)
        AFS::PTS server
        int32   id
        int32   over
    PPCODE:
    {
        int32 code, wentover;
        int i;
        prlist list;

        list.prlist_val = 0;
        list.prlist_len = 0;
        code = ubik_Call(PR_ListElements, server, 0, id, &list, &wentover);
        sv_setiv(ST(2), (IV) wentover);
        if (code == 0) {
            EXTEND(sp, list.prlist_len);
            for (i = 0; i < list.prlist_len; i++) {
                PUSHs(sv_2mortal(newSViv(list.prlist_val[i])));
            }
        }
        if (list.prlist_val)
            free(list.prlist_val);
        SETCODE(code);
     }

void
pts_getcps(server,name,convertids=1,over=0)
        AFS::PTS server
        char *  name
        int32   convertids
        int32   over
    PPCODE:
    {
        int32 code, wentover, id;
        int i;
        prlist list;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0) {
            list.prlist_val = 0;
            list.prlist_len = 0;
            code = ubik_Call(PR_GetCPS, server, 0, id, &list, &wentover);
            if (items == 4)
                sv_setiv(ST(3), (IV) wentover);
            if (code == 0) {
                if (convertids) {
                    namelist lnames;
                    lnames.namelist_len = 0;
                    lnames.namelist_val = 0;
                    code = ubik_Call(PR_IDToName, server, 0, &list, &lnames);
                    if (code == 0 && lnames.namelist_val) {
                        EXTEND(sp, lnames.namelist_len);
                        for (i = 0; i < lnames.namelist_len; i++) {
                            name = lnames.namelist_val[i];
                            PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
                        }
                        if (lnames.namelist_val)
                            free(lnames.namelist_val);
                    }
                }
                else {
                    EXTEND(sp, list.prlist_len);
                    for (i = 0; i < list.prlist_len; i++) {
                        PUSHs(sv_2mortal(newSViv(list.prlist_val[i])));
                    }
                }
            }
            if (list.prlist_val)
                free(list.prlist_val);
        }
        else {
            if (items == 4)
                sv_setiv(ST(3), (IV) 0);
        }

        SETCODE(code);
     }

void
pts_PR_GetCPS(server,id,over)
        AFS::PTS server
        int32   id
        int32   over
    PPCODE:
    {
        int32 code, wentover;
        int i;
        prlist list;

        list.prlist_val = 0;
        list.prlist_len = 0;
        code = ubik_Call(PR_GetCPS, server, 0, id, &list, &wentover);
        sv_setiv(ST(2), (IV) wentover);
        if (code == 0) {
            EXTEND(sp, list.prlist_len);
            for (i = 0; i < list.prlist_len; i++) {
                PUSHs(sv_2mortal(newSViv(list.prlist_val[i])));
            }
        }
        if (list.prlist_val)
            free(list.prlist_val);
        SETCODE(code);
     }

void
pts_owned(server,name,convertids=1,over=0)
        AFS::PTS server
        char *  name
        int32   convertids
        int32   over
    PPCODE:
    {
        int32 code, wentover, id;
        int i;
        prlist list;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0) {
            list.prlist_val = 0;
            list.prlist_len = 0;
            code = ubik_Call(PR_ListOwned, server, 0, id, &list, &wentover);
            if (items == 4)
                sv_setiv(ST(3), (IV) wentover);
            if (code == 0) {
                if (convertids) {
                    namelist lnames;
                    lnames.namelist_len = 0;
                    lnames.namelist_val = 0;
                    code = ubik_Call(PR_IDToName, server, 0, &list, &lnames);
                    if (code == 0 && lnames.namelist_val) {
                        EXTEND(sp, lnames.namelist_len);
                        for (i = 0; i < lnames.namelist_len; i++) {
                            name = lnames.namelist_val[i];
                            PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
                        }
                        if (lnames.namelist_val)
                            free(lnames.namelist_val);
                    }
                }
                else {
                    EXTEND(sp, list.prlist_len);
                    for (i = 0; i < list.prlist_len; i++) {
                        PUSHs(sv_2mortal(newSViv(list.prlist_val[i])));
                    }
                }
            }
            if (list.prlist_val)
                free(list.prlist_val);
        }
        else {
            if (items == 4)
                sv_setiv(ST(3), (IV) 0);
        }

        SETCODE(code);
     }

void
pts_PR_ListOwned(server,id,over)
        AFS::PTS server
        int32   id
        int32   over
    PPCODE:
    {
        int32 code, wentover;
        int i;
        prlist list;

        list.prlist_val = 0;
        list.prlist_len = 0;
        code = ubik_Call(PR_ListOwned, server, 0, id, &list, &wentover);
        sv_setiv(ST(2), (IV) wentover);
        if (code == 0) {
            EXTEND(sp, list.prlist_len);
            for (i = 0; i < list.prlist_len; i++) {
                PUSHs(sv_2mortal(newSViv(list.prlist_val[i])));
            }
        }
        if (list.prlist_val)
            free(list.prlist_val);
        SETCODE(code);
    }

void
pts_createuser(server,name,id=0)
        AFS::PTS server
        char *  name
        int32   id
    CODE:
    {
        int32 code;

        if (id) {
            code = ubik_Call(PR_INewEntry, server, 0, name, id, 0);
        }
        else {
            code = ubik_Call(PR_NewEntry, server, 0, name, PRUSER, 0, &id);
        }

        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setiv(ST(0), id);
        }
    }

void
pts_PR_NewEntry(server,name,flag,oid)
        AFS::PTS server
        char *  name
        int32   flag
        int32   oid
    CODE:
    {
        int32 code, id;

        code = ubik_Call(PR_NewEntry, server, 0, name, flag, oid, &id);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setiv(ST(0), id);
        }
    }

void
pts_PR_INewEntry(server,name,id,oid)
        AFS::PTS server
        char *  name
        int32   id
        int32   oid
    CODE:
    {
        int32 code;

        code = ubik_Call(PR_INewEntry, server, 0, name, id, oid);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setiv(ST(0), id);
        }
    }

void
pts_creategroup(server,name,owner=0,id=0)
        AFS::PTS server
        char *  name
        char *  owner
        int32   id
    CODE:
    {
        int32 code = 0;
        int32 oid = 0;

        if (owner && strcmp(owner, "0") && strcmp(owner, "")) {
            code = internal_pr_id(server, owner, &oid, 0);
        }
        if (code == 0) {
            if (id)
                code = ubik_Call(PR_INewEntry, server, 0, name, id, oid);
            else
                code = ubik_Call(PR_NewEntry, server, 0, name, PRGRP, oid, &id);
        }
        SETCODE(code);

        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setiv(ST(0), id);
        }
    }

void
pts_listentry(server,name,lookupids=1,convertflags=1)
        AFS::PTS server
        char *  name
        int32   lookupids
        int32   convertflags
    PPCODE:
    {
        int32 code;
        int32 id;
        struct prcheckentry entry;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = ubik_Call(PR_ListEntry, server, 0, id, &entry);

        SETCODE(code);

        if (code == 0) {
            HV *stats;
            stats = newHV();
            parse_prcheckentry(server, stats, &entry, lookupids, convertflags);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
        }
    }

void
pts_PR_ListEntry(server,id)
        AFS::PTS server
        int32   id
    PPCODE:
    {
        int32 code;
        struct prcheckentry entry;

        code = ubik_Call(PR_ListEntry, server, 0, id, &entry);

        SETCODE(code);

        if (code == 0) {
            HV *stats;
            stats = newHV();
            parse_prcheckentry(server, stats, &entry, 0, 0);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
        }
    }

void
pts_dumpentry(server,pos,lookupids=1,convertflags=1)
        AFS::PTS server
        int32   pos
        int32   lookupids
        int32   convertflags
    PPCODE:
    {
        int32 code;
        struct prdebugentry entry;

        code = ubik_Call(PR_DumpEntry, server, 0, pos, &entry);

        SETCODE(code);

        if (code == 0) {
            HV *stats;
            stats = newHV();
            parse_prdebugentry(server, stats, &entry, lookupids, convertflags);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
        }
    }

void
pts_PR_DumpEntry(server,pos)
        AFS::PTS server
        int32   pos
    PPCODE:
    {
        int32 code;
        struct prdebugentry entry;

        code = ubik_Call(PR_DumpEntry, server, 0, pos, &entry);

        SETCODE(code);

        if (code == 0) {
            HV *stats;
            stats = newHV();
            parse_prdebugentry(server, stats, &entry, 0, 0);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
        }
    }

void
pts_rename(server,name,newname)
        AFS::PTS server
        char *  name
        char *  newname
    PPCODE:
    {
        int32 code;
        int32 id;

        code = internal_pr_id(server, name, &id, 0);

        if (code == 0)
            code = ubik_Call(PR_ChangeEntry, server, 0, id, newname, 0, 0);

        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
pts_chown(server,name,owner)
        AFS::PTS server
        char *  name
        char *  owner
    PPCODE:
    {
        int32 code;
        int32 id, oid;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = internal_pr_id(server, owner, &oid, 0);
        if (code == 0)
            code = ubik_Call(PR_ChangeEntry, server, 0, id, "", oid, 0);
        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
pts_chid(server,name,newid)
        AFS::PTS server
        char *  name
        int32   newid
    PPCODE:
    {
        int32 code;
        int32 id;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = ubik_Call(PR_ChangeEntry, server, 0, id, "", 0, newid);
        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
pts_PR_ChangeEntry(server,id,name,oid,newid)
        AFS::PTS server
        int32   id
        char *  name
        int32   oid
        int32   newid
    PPCODE:
    {
        int32 code;

        if (name && !*name)
            name = NULL;

        code = ubik_Call(PR_ChangeEntry, server, 0, id, name, oid, newid);

        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
pts_adduser(server,name,group)
        AFS::PTS server
        char *  name
        char *  group
    PPCODE:
    {
        int32 code, id, gid;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = internal_pr_id(server, group, &gid, 0);
        if (code == 0)
            code = ubik_Call(PR_AddToGroup, server, 0, id, gid);
        SETCODE(code);

        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_PR_AddToGroup(server,uid,gid)
        AFS::PTS server
        int32   uid
        int32   gid
    PPCODE:
    {
        int32 code;
        code = ubik_Call(PR_AddToGroup, server, 0, uid, gid);
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_removeuser(server,name,group)
        AFS::PTS server
        char *  name
        char *  group
    PPCODE:
    {
        int32 code, id, gid;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = internal_pr_id(server, group, &gid, 0);
        if (code == 0)
            code = ubik_Call(PR_RemoveFromGroup, server, 0, id, gid);
        SETCODE(code);

        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_PR_RemoveFromGroup(server,uid,gid)
        AFS::PTS server
        int     uid
        int     gid
    PPCODE:
    {
        int32 code;

        code = ubik_Call(PR_RemoveFromGroup, server, 0, uid, gid);
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_delete(server,name)
        AFS::PTS server
        char *  name
    PPCODE:
    {
        int32 code, id;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = ubik_Call(PR_Delete, server, 0, id);
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_PR_Delete(server,id)
        AFS::PTS server
        int32   id
    PPCODE:
    {
        int32 code;

        code = ubik_Call(PR_Delete, server, 0, id);
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_whereisit(server,name)
        AFS::PTS server
        char *  name
    PPCODE:
    {
        int32 code, id, pos;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = ubik_Call(PR_WhereIsIt, server, 0, id, &pos);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0)
            sv_setiv(ST(0), pos);
        XSRETURN(1);
    }

void
pts_PR_WhereIsIt(server,id)
        AFS::PTS server
        int32   id
    PPCODE:
    {
        int32 code,pos;

        code = ubik_Call(PR_WhereIsIt, server, 0, id, &pos);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0)
            sv_setiv(ST(0), pos);
        XSRETURN(1);
    }

void
pts_listmax(server)
        AFS::PTS server
    PPCODE:
    {
        int32 code, uid, gid;

        code = ubik_Call(PR_ListMax, server, 0, &uid, &gid);
        SETCODE(code);
        if (code == 0) {
            EXTEND(sp, 2);
            PUSHs(sv_2mortal(newSViv(uid)));
            PUSHs(sv_2mortal(newSViv(gid)));
        }
    }

void
pts_PR_ListMax(server)
        AFS::PTS server
    PPCODE:
    {
        int32 code, uid, gid;

        code = ubik_Call(PR_ListMax, server, 0, &uid, &gid);
        SETCODE(code);
        if (code == 0) {
            EXTEND(sp, 2);
            PUSHs(sv_2mortal(newSViv(uid)));
            PUSHs(sv_2mortal(newSViv(gid)));
        }
    }

void
pts_setmax(server,id,isgroup=0)
        AFS::PTS server
        int32   id
        int32   isgroup
    PPCODE:
    {
        int32 code, flag;

        flag = 0;
        if (isgroup)
            flag |= PRGRP;
        code = ubik_Call(PR_SetMax, server, 0, id, flag);
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_PR_SetMax(server,id,gflag)
        AFS::PTS server
        int32   id
        int32   gflag
    PPCODE:
    {
        int32 code;

        code = ubik_Call(PR_SetMax, server, 0, id, gflag);
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_setgroupquota(server,name,ngroups)
        AFS::PTS server
        char *  name
        int32   ngroups
    PPCODE:
    {
        int32 code, id, mask;

        code = internal_pr_id(server, name, &id, 0);

        if (code == 0) {
            mask = PR_SF_NGROUPS;
            code = ubik_Call(PR_SetFieldsEntry, server, 0, id, mask, 0, ngroups, 0, 0, 0);
        }
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_PR_SetFieldsEntry(server,id,mask,flags,ngroups,nusers,spare1,spare2)
        AFS::PTS server
        int32   id
        int32   mask
        int32   flags
        int32   ngroups
        int32   nusers
        int32   spare1
        int32   spare2
    PPCODE:
    {
        int32 code;

        code = ubik_Call(PR_SetFieldsEntry, server, 0,
                         id, mask, flags, ngroups, nusers, spare1, spare2);
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_setaccess(server,name,access)
        AFS::PTS server
        char *  name
        char *  access
    PPCODE:
    {
        int32 code, id, flags, mask;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = parse_pts_setfields(access, &flags);
        if (code == 0) {
            mask = PR_SF_ALLBITS;
            code = ubik_Call(PR_SetFieldsEntry, server, 0, id, mask, flags, 0, 0, 0, 0);
        }
        SETCODE(code);
        ST(0) = sv_newmortal();
        sv_setiv(ST(0), (code == 0));
        XSRETURN(1);
    }

void
pts_ismember(server,name,group)
        AFS::PTS server
        char *  name
        char *  group
    PPCODE:
    {
        int32 code, id, gid, flag;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = internal_pr_id(server, group, &gid, 0);
        if (code == 0)
            code = ubik_Call(PR_IsAMemberOf, server, 0, id, gid, &flag);
        SETCODE(code);

        ST(0) = sv_newmortal();
        if (code == 0)
            sv_setiv(ST(0), (flag != 0));
        XSRETURN(1);
    }

void
pts_PR_IsAMemberOf(server,uid,gid)
        AFS::PTS server
        int32   uid
        int32   gid
    PPCODE:
    {
        int32 code, flag;

        code = ubik_Call(PR_IsAMemberOf, server, 0, uid, gid, &flag);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0)
            sv_setiv(ST(0), (flag != 0));
        XSRETURN(1);
    }


MODULE = AFS            PACKAGE = AFS::KAS      PREFIX = kas_

int32
kas__DESTROY(server)
        AFS::KAS server
    CODE:
    {
        int32 code;
        code = ubik_ClientDestroy(server);
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL  

void
kas_KAM_GetEntry(server,user,inst)
        AFS::KAS        server
        char *  user
        char *  inst
    PPCODE:
    {
        int32 code;
        struct kaentryinfo entry;

        code = ubik_Call(KAM_GetEntry, server, 0, user, inst, KAMAJORVERSION, &entry);
        SETCODE(code);
        if (code == 0) {
            HV *stats = newHV();
            if (parse_kaentryinfo(stats, &entry)) {
                EXTEND(sp, 1);
                PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
            }
            else {
                hv_undef(stats);
            }
        }
    }

void
kas_KAM_Debug(server,version)
        AFS::KAS        server
        int32   version
    PPCODE:
    {
        int32 code;
        struct ka_debugInfo entry;

        code = ubik_Call(KAM_Debug, server, 0, version, 0, &entry);
        SETCODE(code);
        if (code == 0) {
            HV *stats = newHV();
            if (parse_ka_debugInfo(stats, &entry)) {
                EXTEND(sp, 1);
                PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
            }
            else {
                hv_undef(stats);
            }
        }
    }

void
kas_KAM_GetStats(server,version)
        AFS::KAS        server
        int32   version
    PPCODE:
    {
        int32 code;
        int32 admin_accounts;
        struct kasstats kas;
        struct kadstats kad;

        code = ubik_Call(KAM_GetStats, server, 0, version, &admin_accounts, &kas, &kad);
        SETCODE(code);
        if (code == 0) {
            HV *stats = newHV();
            HV *dstats = newHV();
            if (parse_ka_getstats(stats, dstats, &kas, &kad)) {
                EXTEND(sp, 3);
                PUSHs(sv_2mortal(newSViv(admin_accounts)));
                PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
                PUSHs(sv_2mortal(newRV_noinc((SV *) dstats)));
            }
            else {
                hv_undef(stats);
                hv_undef(dstats);
            }
        }
    }

void
kas_KAM_GetRandomKey(server)
        AFS::KAS        server
    PPCODE:
    {
        int32 code;
        struct ktc_encryptionKey *key;

        key = (struct ktc_encryptionKey *) safemalloc(sizeof(*key));

        code = ubik_Call(KAM_GetRandomKey, server, 0, key);

        SETCODE(code);
        if (code == 0) {
            SV *st = sv_newmortal();
            sv_setref_pv(st, "AFS::KTC_EKEY", (void *) key);
            PUSHs(st);
        }
        else {
            safefree(key);
        }
    }

void
kas_KAM_CreateUser(server,user,inst,key)
        AFS::KAS        server
        char *  user
        char *  inst
        AFS::KTC_EKEY   key
    PPCODE:
    {
        int32 code;

        code = ubik_Call(KAM_CreateUser, server, 0, user, inst, *key);

        SETCODE(code);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));
    }

void
kas_KAM_SetPassword(server,user,inst,kvno,key)
        AFS::KAS        server
        char *  user
        char *  inst
        int32   kvno
        AFS::KTC_EKEY   key
    PPCODE:
    {
        int32 code;

        code = ubik_Call(KAM_SetPassword, server, 0, user, inst, kvno, *key);

        SETCODE(code);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));
    }

void
kas_KAM_DeleteUser(server,user,inst)
        AFS::KAS        server
        char *  user
        char *  inst
    PPCODE:
    {
        int32 code;

        code = ubik_Call(KAM_DeleteUser, server, 0, user, inst);
        SETCODE(code);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));
    }

void
kas_KAM_ListEntry(server,previous,index,count)
        AFS::KAS        server
        int32   previous
        int32   index
        int32   count
    PPCODE:
    {
        int32 code;
        struct kaident ki;

        code = ubik_Call(KAM_ListEntry, server, 0, previous, &index, &count, &ki);
        sv_setiv(ST(2), (IV) index);
        sv_setiv(ST(3), (IV) count);
        SETCODE(code);
        if (code == 0 && count >= 0) {
            EXTEND(sp, 2);
            PUSHs(sv_2mortal(newSVpv(ki.name, strlen(ki.name))));
            PUSHs(sv_2mortal(newSVpv(ki.instance, strlen(ki.instance))));
        }
    }

void
kas_KAM_SetFields(server,name,instance,flags,user_expire,max_ticket_life, maxAssoc, misc_auth_bytes, spare2=0)
        AFS::KAS        server
        char *  name
        char *  instance
        int32   flags
        int32   user_expire
        int32   max_ticket_life
        int32   maxAssoc
        uint32  misc_auth_bytes
        int32   spare2
    PPCODE:
    {
        int32 code;

        #  tpf nog 03/29/99
        #  wrong argument list: max_ticket_life was missing
        #       code = ubik_Call(KAM_SetFields, server, 0, name, instance,
        #               flags, user_expire, maxAssoc, spare1,spare2);
        code = ubik_Call(KAM_SetFields, server, 0, name, instance,
                         flags, user_expire, max_ticket_life, maxAssoc, misc_auth_bytes, spare2);
        SETCODE(code);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));
    }

void
kas_ka_ChangePassword(server,name,instance,oldkey,newkey)
        AFS::KAS        server
        char *  name
        char *  instance
        AFS::KTC_EKEY   oldkey
        AFS::KTC_EKEY   newkey
    PPCODE:
    {
        int32 code;

        code = ka_ChangePassword(name, instance, server, oldkey, newkey);
        SETCODE(code);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));
    }

void
kas_ka_GetToken(server,name,instance,start,end,auth_token,auth_domain="")
        AFS::KAS        server
        char *  name
        char *  instance
        int32   start
        int32   end
        AFS::KTC_TOKEN  auth_token
        char *  auth_domain
    PPCODE:
    {
        int32 code;
        struct ktc_token *t;
#if defined(AFS_3_4)
#else
        char *cname = NULL;
        char *cinst = NULL;
        char *cell = NULL;
#endif

        t = (struct ktc_token *) safemalloc(sizeof(struct ktc_token));
#if defined(AFS_3_4)
        code = ka_GetToken(name, instance, server, start, end, auth_token, auth_domain, t);
#else
        if (cell == 0) {
            cell = internal_GetLocalCell(&code);
            if (code)
                XSRETURN_UNDEF;
        }
        code = ka_GetToken(name, instance, cell, cname, cinst, server,
                           start, end, auth_token, auth_domain, t);
#endif
        if (code == 0) {
            SV *st;
            EXTEND(sp, 1);
            st = sv_newmortal();
            sv_setref_pv(st, "AFS::KTC_TOKEN", (void *) t);
            PUSHs(st);
            XSRETURN(1);
        }
        else {
            char buffer[256];
            sprintf(buffer, "AFS::KTC_TOKEN: ");
            KSETCODE(code, buffer);
            safefree(t);
            XSRETURN_UNDEF;
        }
    }

void
kas_ka_Authenticate(server,name,instance,service,key,start,end,pwexpires=-1)
        AFS::KAS        server
        char *  name
        char *  instance
        int32   service
        AFS::KTC_EKEY   key
        int32   start
        int32   end
        int32   pwexpires
    PPCODE:
    {
        int32 code;
        int32 pw;
        struct ktc_token *t;
#if defined(AFS_3_4)
#else
        char *cell = NULL;
#endif

        t = (struct ktc_token *) safemalloc(sizeof(struct ktc_token));
#if defined(AFS_3_4)
        code = ka_Authenticate(name, instance, server, service, key, start, end, t, &pw);
#else
        if (cell == 0) {
            cell = internal_GetLocalCell(&code);
            if (code)
                XSRETURN_UNDEF;
        }
        code = ka_Authenticate(name, instance, cell, server, service, key, start, end, t, &pw);
#endif
        if (code == 0) {
            SV *st;
            EXTEND(sp, 1);
            st = sv_newmortal();
            sv_setref_pv(st, "AFS::KTC_TOKEN", (void *) t);
            PUSHs(st);
            if (pwexpires != -1)
                sv_setiv(ST(7), (IV) pw);
            XSRETURN(1);
        }
        else {
            char buffer[256];
            sprintf(buffer, "AFS::KTC_TOKEN: ");
            KSETCODE(code, buffer);
            safefree(t);
            XSRETURN_UNDEF;
        }
    }


MODULE = AFS    PACKAGE = AFS   PREFIX = afs_

BOOT:
    initialize_bz_error_table();
    initialize_vols_error_table();
    initialize_vl_error_table();
    initialize_u_error_table();
    initialize_pt_error_table();
    initialize_ka_error_table();
    initialize_acfg_error_table();
    initialize_ktc_error_table();
    initialize_rxk_error_table();
/*     initialize_cmd_error_table(); */
/*     initialize_budb_error_table(); */
/*     initialize_butm_error_table(); */
/*     initialize_butc_error_table(); */

void
afs__finalize()
    CODE:
    {
        if (rx_initialized) {
            rx_Finalize();
            /* printf("AFS DEBUG rx_Finalize\n"); */
        }
    }

int32
afs_ascii2ptsaccess(access)
        char *  access
    CODE:
    {
        int32 code, flags;

        code = parse_pts_setfields(access, &flags);
        SETCODE(code);

        if (code != 0)
            flags = 0;
        RETVAL = flags;
    }
    OUTPUT:
        RETVAL

void
afs_ptsaccess2ascii(flags)
        int32   flags
    CODE:
    {
        SETCODE(0);
        ST(0) = sv_newmortal();
        sv_setpv(ST(0), parse_flags_ptsaccess(flags));
    }

void
afs_ka_ParseLoginName(login)
        char *  login
    PPCODE:
    {
        int32 code;
        char name[MAXKTCNAMELEN];
        char inst[MAXKTCNAMELEN];
        char cell[MAXKTCREALMLEN];

        code = ka_ParseLoginName(login, name, inst, cell);
        SETCODE(code);
        if (code == 0) {
            EXTEND(sp, 3);
            PUSHs(sv_2mortal(newSVpv(name, strlen(name))));
            PUSHs(sv_2mortal(newSVpv(inst, strlen(inst))));
            PUSHs(sv_2mortal(newSVpv(cell, strlen(cell))));
        }
    }

void
afs_ka_StringToKey(str,cell)
        char *  str
        char *  cell
    PPCODE:
    {
        struct ktc_encryptionKey *key;
        SV *st;

        key = (struct ktc_encryptionKey *) safemalloc(sizeof(*key));

        ka_StringToKey(str, cell, key);

        SETCODE(0);
        EXTEND(sp, 1);
        st = sv_newmortal();
        sv_setref_pv(st, "AFS::KTC_EKEY", (void *) key);
        PUSHs(st);
    }

void
afs_ka_UserAthenticateGeneral(p,pass,life,flags,pwexpires=-1,reason=0)
        AFS::KTC_PRINCIPAL      p
        char *  pass
        int32   life
        int32   flags
        int32   pwexpires
        char *  reason
    PPCODE:
    {
        int32 code, pw = 255;
        char *r;
        code = ka_UserAuthenticateGeneral(flags,
                                          p->name, p->instance, p->cell, pass, life, &pw, 0, &r);
        if (pwexpires != -1)
            sv_setiv(ST(4), (IV) pw);
        if (reason)
            sv_setpv(ST(5), r);
        SETCODE(code);
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));
    }

void
afs_ka_ReadPassword(prompt,verify=0,cell=0)
        char *  prompt
        int32   verify
        char *  cell
    PPCODE:
    {
        int32 code = 0;
        struct ktc_encryptionKey *key;
        SV *st;

        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        if (cell == 0) {
            cell = internal_GetLocalCell(&code);
            if (code)
                XSRETURN_UNDEF;
        }

        key = (struct ktc_encryptionKey *) safemalloc(sizeof(*key));
        code = ka_ReadPassword(prompt, verify, cell, key);
        if (code == 0) {
            EXTEND(sp, 1);
            st = sv_newmortal();
            sv_setref_pv(st, "AFS::KTC_EKEY", (void *) key);
            PUSHs(st);
            XSRETURN(1);
        }
        else {
            char buffer[256];
            sprintf(buffer, "AFS::KTC_EKEY: ");
            KSETCODE(code, buffer);
            safefree(key);
            XSRETURN_UNDEF;
        }
    }

void
afs_ka_UserReadPassword(prompt,reason=0)
        char *  prompt
        char *  reason
    PPCODE:
    {
        int32 code;
        char buffer[1024];
        char *r;
        code = ka_UserReadPassword(prompt, buffer, sizeof(buffer) - 1, &r);
        SETCODE(code);
        if (reason)
            sv_setpv(ST(1), r);
        if (code == 0) {
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newSVpv(buffer, strlen(buffer))));
        }
    }

void
afs_ka_GetAdminToken(p,key,lifetime,newt=1,reason=0)
        AFS::KTC_PRINCIPAL  p
        AFS::KTC_EKEY       key
        int32               lifetime
        int32               newt
        char *  reason
    PPCODE:
    {
        int32 code;
        struct ktc_token *t;
        char *message;

        t = (struct ktc_token *) safemalloc(sizeof(struct ktc_token));

        code = ka_GetAdminToken(p->name, p->instance, p->cell, key, lifetime, t, newt);
        SETCODE(code);

        if (code == 0) {
            SV *st;
            EXTEND(sp, 1);
            st = sv_newmortal();
            sv_setref_pv(st, "AFS::KTC_TOKEN", (void *) t);
            PUSHs(st);
        }
        else {
            safefree(t);
            switch (code) {
              case KABADREQUEST:
                  message = "password was incorrect";
                  break;
              case KAUBIKCALL:
                  message = "Authentication Server was unavailable";
                  break;
              default:
                  message = (char *) error_message(code);
            }
            sv_setpv(ST(4), message);
        }

    }


void
afs_ka_GetAuthToken(p,key,lifetime,pwexpires=-1)
        AFS::KTC_PRINCIPAL p
        AFS::KTC_EKEY      key
        int32              lifetime
        int32              pwexpires
    PPCODE:
    {
        int32 code;
        int32 pw;

        code = ka_GetAuthToken(p->name, p->instance, p->cell, key, lifetime, &pw);
        SETCODE(code);
        if (code == 0) {
            if (pwexpires != -1)
                sv_setiv(ST(3), (IV) pw);
        }
        EXTEND(sp, 1);
        PUSHs(sv_2mortal(newSViv(code == 0)));

    }


void
afs_ka_GetServerToken(p,lifetime,newt=1)
        AFS::KTC_PRINCIPAL      p
        int32                   lifetime
        int32                   newt
    PPCODE:
    {
        int32 code;
        struct ktc_token *t;
#if defined(AFS_3_4)
#else
        int32 dosetpag;
#endif

        t = (struct ktc_token *) safemalloc(sizeof(struct ktc_token));
#if defined(AFS_3_4)
        code = ka_GetServerToken(p->name, p->instance, p->cell, lifetime, t, newt);
#else
        dosetpag = 0;
        code = ka_GetServerToken(p->name, p->instance, p->cell, lifetime, t, newt, dosetpag);
#endif
        SETCODE(code);

        if (code == 0) {
            SV *st;
            EXTEND(sp, 1);
            st = sv_newmortal();
            sv_setref_pv(st, "AFS::KTC_TOKEN", (void *) t);
            PUSHs(st);
        }
        else {
            safefree(t);
        }
    }

void
afs_ka_nulltoken()
    PPCODE:
    {
        ST(0) = sv_newmortal();
        sv_setref_pv(ST(0), "AFS::KTC_TOKEN", (void *) &the_null_token);
        XSRETURN(1);
    }

void
afs_ka_AuthServerConn(token,service,cell=0)
        AFS::KTC_TOKEN  token
        int32           service
        char *          cell
    PPCODE:
    {
        int32 code;
        AFS__KAS server;

        if (token == &the_null_token)
            token = NULL;

        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        code = ka_AuthServerConn(cell, service, token, &server);
        SETCODE(code);

        if (code == 0) {
            ST(0) = sv_newmortal();
            sv_setref_pv(ST(0), "AFS::KAS", (void *) server);
            XSRETURN(1);
        }
    }

void
afs_ka_SingleServerConn(host,token,service,cell=0)
        char *          host
        AFS::KTC_TOKEN  token
        int32           service
        char *          cell
    PPCODE:
    {
        int32 code;
        AFS__KAS server;

        if (token == &the_null_token)
            token = NULL;

        code = ka_SingleServerConn(cell, host, service, token, &server);
        SETCODE(code);

        if (code == 0) {
            ST(0) = sv_newmortal();
            sv_setref_pv(ST(0), "AFS::KAS", (void *) server);
            XSRETURN(1);
        }
    }

void
afs_ka_des_string_to_key(str)
        char *  str
    PPCODE:
    {
        struct ktc_encryptionKey *key;
        SV *st;

        key = (struct ktc_encryptionKey *) safemalloc(sizeof(*key));

        des_string_to_key(str, key);
        SETCODE(0);
        EXTEND(sp, 1);
        st = sv_newmortal();
        sv_setref_pv(st, "AFS::KTC_EKEY", (void *) key);
        PUSHs(st);
    }

int32
afs_setpag()
    CODE:
    {
        int32 code;

        code = setpag();
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

void
afs_expandcell(cell)
        char *  cell
    PPCODE:
    {
        int32 code;
        struct afsconf_cell info;

        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        code = internal_GetCellInfo(cell, 0, &info);
        if (code != 0) {
            XSRETURN_UNDEF;
        }
        else {
            SETCODE(code);  /* fuer Fehler wird tiefer gesetzt... */
            ST(0) = sv_newmortal();
            sv_setpv(ST(0), info.name);
            XSRETURN(1);
        }
    }

void
afs_localcell()
    PPCODE:
    {
        int32 code;
        char *cell;

        cell = internal_GetLocalCell(&code);

        if (! code) SETCODE(code);  /* fuer Fehler wird tiefer gesetzt... */
        ST(0) = sv_newmortal();
        sv_setpv(ST(0), cell);
        XSRETURN(1);
    }

void
afs_getcellinfo(cell=0,ip=0)
        char *  cell
        int32   ip
    PPCODE:
    {
        int32 code;
        struct afsconf_cell info;

        if (cell && (cell[0] == '\0' || cell[0] == '0'))
            cell = NULL;

        code = internal_GetCellInfo(cell, 0, &info);
        if (code != 0) {
            XSRETURN_UNDEF;
        }
        else {
            int i;
            char *h;
            SETCODE(code);  /* fuer Fehler wird tiefer gesetzt... */
            XPUSHs(sv_2mortal(newSVpv(info.name, strlen(info.name))));
            for (i = 0; i < info.numServers; i++) {
                if (ip == 1) {
                    h = (char *) inet_ntoa(info.hostAddr[i].sin_addr);
                }
                else {
                    h = info.hostName[i];
                }
                XPUSHs(sv_2mortal(newSVpv(h, strlen(h))));
            }
            XSRETURN(i+1);
        }
    }

int32
afs_convert_numeric_names(...)
    CODE:
    {
        int32 flag;

        if (items > 1)
            croak("Usage: AFS::convert_numeric_names(flag)");
        if (items == 1) {
            flag = (int) SvIV(ST(0));
            convert_numeric_names = (flag != 0);
        }
        RETVAL = convert_numeric_names;
    }
    OUTPUT:
        RETVAL

int32
afs_raise_exception(...)
    CODE:
    {
        int32 flag;

        if (items > 1)
            croak("Usage: AFS::raise_exception(flag)");
        if (items == 1) {
            flag = (int) SvIV(ST(0));
            raise_exception = (flag != 0);
        }
        RETVAL = raise_exception;
    }
    OUTPUT:
        RETVAL

void
afs_configdir(...)
    PPCODE:
    {
        char *value;
        int32 code;

        if (items > 1)
            croak("Usage: AFS::configdir(dir)");

        if (items == 1) {
            STRLEN len;
            value = (char *) SvPV(ST(0), len);
            if (config_dir != NULL)
                safefree(config_dir);
            if (cdir != NULL) {
                afsconf_Close(cdir);
                cdir = NULL;
            }
            config_dir = (char *) safemalloc(len + 1);
            strcpy(config_dir, value);
            code = internal_GetConfigDir();
            # SETCODE(code);  wird tiefer gesetzt...
            ST(0) = sv_newmortal();
            sv_setiv(ST(0), (code == 0));
            XSRETURN(1);
        }
        else {
            code = internal_GetConfigDir();
            # SETCODE(code);  wird tiefer gesetzt...
            if (code == 0) {
                ST(0) = sv_newmortal();
                sv_setpv(ST(0), config_dir);
                XSRETURN(1);
            }
            else 
                XSRETURN_UNDEF;
        }
    }

  /* KTC routines */

AFS::KTC_PRINCIPAL
afs_ktc_ListTokens(context)
        int32   context
    PPCODE:
    {
        int32 code;
        struct ktc_principal *p;

        p = (struct ktc_principal *) safemalloc(sizeof(struct ktc_principal));
        code = ktc_ListTokens(context, &context, p);
        SETCODE(code);
        sv_setiv(ST(0), (IV) context);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setref_pv(ST(0), "AFS::KTC_PRINCIPAL", (void *) p);
        }
        else {
            safefree(p);
        }

        XSRETURN(1);
    }

void
afs_ktc_GetToken(server)
        AFS::KTC_PRINCIPAL      server
    PPCODE:
    {
        int32 code;
        struct ktc_principal *c;
        struct ktc_token *t;

        c = (struct ktc_principal *) safemalloc(sizeof(struct ktc_principal));
        t = (struct ktc_token *) safemalloc(sizeof(struct ktc_token));

        code = ktc_GetToken(server, t, sizeof(*t), c);
        SETCODE(code);

        if (code == 0) {
            SV *st, *sc;
            EXTEND(sp, 2);
            st = sv_newmortal();
            sv_setref_pv(st, "AFS::KTC_TOKEN", (void *) t);
            PUSHs(st);
            sc = sv_newmortal();
            sv_setref_pv(sc, "AFS::KTC_PRINCIPAL", (void *) c);
            PUSHs(sc);
        }
        else {
            safefree(c);
            safefree(t);
        }
    }

void
afs_ktc_FromString(s)
        SV *s
    PPCODE:
    {
        SV *sv;
        STRLEN len;
        char *str;
        struct ktc_token *t;

        str = SvPV(s, len);
        EXTEND(sp, 1);
        if (len == sizeof(struct ktc_token)) {
            t = (struct ktc_token *) safemalloc(sizeof(struct ktc_token));
            memcpy((void *) t, (void *) str, sizeof(struct ktc_token));

            sv = sv_newmortal();
            sv_setref_pv(sv, "AFS::KTC_TOKEN", (void *) t);
            PUSHs(sv);
        }
        else {
            PUSHs(&PL_sv_undef);
        }
    }

void
afs_ktc_SetToken(server,token,client,flags=0)
        AFS::KTC_PRINCIPAL   server
        AFS::KTC_TOKEN       token
        AFS::KTC_PRINCIPAL   client
        int32                flags
    PPCODE:
    {
        int32 code;
        code = ktc_SetToken(server, token, client, flags);
        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
afs_ktc_ForgetAllTokens()
    PPCODE:
    {
        int32 code;
        code = ktc_ForgetAllTokens();
        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
afs_error_message(code)
        int32   code
    PPCODE:
    {
        ST(0) = sv_newmortal();
        sv_setpv(ST(0), (char *) error_message(code));
        XSRETURN(1);
    }


  /* this function is generated automatically by constant_gen */
  /* You didn't think I would type in this crap did you? */
  /* thats what perl is for :-) */

#if defined(AFS_3_4)

void
constant(name, arg=0)
        char *  name
        int     arg
   PPCODE:
   {
  ST(0) = sv_newmortal();

  errno = EINVAL;

  switch (name[0]) {
  case 'A':
        switch (name[1]) {
        case 'F':
                switch (name[2]) {
                case 'S':
                if (strEQ(name,"AFSCONF_FAILURE")) sv_setiv(ST(0),AFSCONF_FAILURE);
                else if (strEQ(name,"AFSCONF_FULL")) sv_setiv(ST(0),AFSCONF_FULL);
                else if (strEQ(name,"AFSCONF_NOCELL")) sv_setiv(ST(0),AFSCONF_NOCELL);
                else if (strEQ(name,"AFSCONF_NODB")) sv_setiv(ST(0),AFSCONF_NODB);
                else if (strEQ(name,"AFSCONF_NOTFOUND")) sv_setiv(ST(0),AFSCONF_NOTFOUND);
                else if (strEQ(name,"AFSCONF_SYNTAX")) sv_setiv(ST(0),AFSCONF_SYNTAX);
                else if (strEQ(name,"AFSCONF_UNKNOWN")) sv_setiv(ST(0),AFSCONF_UNKNOWN);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                default:
                        ST(0) = ST(1) = &PL_sv_undef;
                        return;
                }
                break;
        case 'N':
                switch (name[2]) {
                case 'O':
                if (strEQ(name,"ANONYMOUSID")) sv_setiv(ST(0),ANONYMOUSID);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                case 'Y':
                if (strEQ(name,"ANYUSERID")) sv_setiv(ST(0),ANYUSERID);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                default:
                        ST(0) = ST(1) = &PL_sv_undef;
                        return;
                }
                break;
        case 'U':
                switch (name[2]) {
                case 'T':
                if (strEQ(name,"AUTHUSERID")) sv_setiv(ST(0),AUTHUSERID);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                default:
                        ST(0) = ST(1) = &PL_sv_undef;

src/AFS.xs  view on Meta::CPAN

                else if (strEQ(name,"VIOCLISTGROUPS")) sv_setiv(ST(0),VIOCLISTGROUPS);
                else if (strEQ(name,"VIOCNEWCELL")) sv_setiv(ST(0),VIOCNEWCELL);
                else if (strEQ(name,"VIOCNOP")) sv_setiv(ST(0),VIOCNOP);
                else if (strEQ(name,"VIOCPREFETCH")) sv_setiv(ST(0),VIOCPREFETCH);
                else if (strEQ(name,"VIOCSETAL")) sv_setiv(ST(0),VIOCSETAL);
                else if (strEQ(name,"VIOCSETCACHESIZE")) sv_setiv(ST(0),VIOCSETCACHESIZE);
                else if (strEQ(name,"VIOCSETTOK")) sv_setiv(ST(0),VIOCSETTOK);
                else if (strEQ(name,"VIOCSETVOLSTAT")) sv_setiv(ST(0),VIOCSETVOLSTAT);
                else if (strEQ(name,"VIOCSTAT")) sv_setiv(ST(0),VIOCSTAT);
                else if (strEQ(name,"VIOCUNLOG")) sv_setiv(ST(0),VIOCUNLOG);
                else if (strEQ(name,"VIOCUNPAG")) sv_setiv(ST(0),VIOCUNPAG);
                else if (strEQ(name,"VIOCWAITFOREVER")) sv_setiv(ST(0),VIOCWAITFOREVER);
                else if (strEQ(name,"VIOCWHEREIS")) sv_setiv(ST(0),VIOCWHEREIS);
                else if (strEQ(name,"VIOC_AFS_DELETE_MT_PT")) sv_setiv(ST(0),VIOC_AFS_DELETE_MT_PT);
                else if (strEQ(name,"VIOC_AFS_MARINER_HOST")) sv_setiv(ST(0),VIOC_AFS_MARINER_HOST);
                else if (strEQ(name,"VIOC_AFS_STAT_MT_PT")) sv_setiv(ST(0),VIOC_AFS_STAT_MT_PT);
                else if (strEQ(name,"VIOC_AFS_SYSNAME")) sv_setiv(ST(0),VIOC_AFS_SYSNAME);
                else if (strEQ(name,"VIOC_EXPORTAFS")) sv_setiv(ST(0),VIOC_EXPORTAFS);
                else if (strEQ(name,"VIOC_FILE_CELL_NAME")) sv_setiv(ST(0),VIOC_FILE_CELL_NAME);
                else if (strEQ(name,"VIOC_FLUSHVOLUME")) sv_setiv(ST(0),VIOC_FLUSHVOLUME);
                else if (strEQ(name,"VIOC_GAG")) sv_setiv(ST(0),VIOC_GAG);
                else if (strEQ(name,"VIOC_GETCELLSTATUS")) sv_setiv(ST(0),VIOC_GETCELLSTATUS);
                else if (strEQ(name,"VIOC_GETSPREFS")) sv_setiv(ST(0),VIOC_GETSPREFS);
                else if (strEQ(name,"VIOC_GET_PRIMARY_CELL")) sv_setiv(ST(0),VIOC_GET_PRIMARY_CELL);
                else if (strEQ(name,"VIOC_GET_WS_CELL")) sv_setiv(ST(0),VIOC_GET_WS_CELL);
                else if (strEQ(name,"VIOC_SETCELLSTATUS")) sv_setiv(ST(0),VIOC_SETCELLSTATUS);
                else if (strEQ(name,"VIOC_SETSPREFS")) sv_setiv(ST(0),VIOC_SETSPREFS);
                else if (strEQ(name,"VIOC_TWIDDLE")) sv_setiv(ST(0),VIOC_TWIDDLE);
                else if (strEQ(name,"VIOC_VENUSLOG")) sv_setiv(ST(0),VIOC_VENUSLOG);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                default:
                        ST(0) = ST(1) = &PL_sv_undef;
                        return;
                }
                break;
        default:
                ST(0) = ST(1) = &PL_sv_undef;
                return;
        }
        break;
  default:
        ST(0) = ST(1) = &PL_sv_undef;
        return;
  }

  errno = 0;
  XSRETURN(1);
  return;
 }

#else

void
constant(name, arg=0)
        char *  name
        int     arg
   PPCODE:
   {
  ST(0) = sv_newmortal();

  errno = EINVAL;

  switch (name[0]) {
  case 'A':
        switch (name[1]) {
        case 'F':
                switch (name[2]) {
                case 'S':
                if (strEQ(name,"AFSCONF_FAILURE")) sv_setiv(ST(0),AFSCONF_FAILURE);
                else if (strEQ(name,"AFSCONF_FULL")) sv_setiv(ST(0),AFSCONF_FULL);
                else if (strEQ(name,"AFSCONF_NOCELL")) sv_setiv(ST(0),AFSCONF_NOCELL);
                else if (strEQ(name,"AFSCONF_NODB")) sv_setiv(ST(0),AFSCONF_NODB);
                else if (strEQ(name,"AFSCONF_NOTFOUND")) sv_setiv(ST(0),AFSCONF_NOTFOUND);
                else if (strEQ(name,"AFSCONF_SYNTAX")) sv_setiv(ST(0),AFSCONF_SYNTAX);
                else if (strEQ(name,"AFSCONF_UNKNOWN")) sv_setiv(ST(0),AFSCONF_UNKNOWN);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                default:
                        ST(0) = ST(1) = &PL_sv_undef;
                        return;
                }
                break;
        case 'N':
                switch (name[2]) {
                case 'O':
                if (strEQ(name,"ANONYMOUSID")) sv_setiv(ST(0),ANONYMOUSID);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                case 'Y':
                if (strEQ(name,"ANYUSERID")) sv_setiv(ST(0),ANYUSERID);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                default:
                        ST(0) = ST(1) = &PL_sv_undef;
                        return;
                }
                break;
        case 'U':
                switch (name[2]) {
                case 'T':
                if (strEQ(name,"AUTHUSERID")) sv_setiv(ST(0),AUTHUSERID);
                else {
                     ST(0) = ST(1) = &PL_sv_undef;
                     return;
                }
                break;
                default:
                        ST(0) = ST(1) = &PL_sv_undef;



( run in 0.664 second using v1.01-cache-2.11-cpan-71847e10f99 )