AFS

 view release on metacpan or  search on metacpan

src/AFS.xs  view on Meta::CPAN

    }
    else {
        *code = internal_GetConfigDir();
        if (*code)
            return NULL;
        *code = afsconf_GetLocalCell(cdir, localcell, sizeof(localcell));
        if (*code) {
            char buffer[256];
            sprintf(buffer, "GetLocalCell: Can't determine local cell name");
            PSETCODE(buffer);
            return NULL;
        }
    }
    return localcell;
}

static void stolower(s)
    char *s;
{
    while (*s) {
        if (isupper(*s))
            *s = tolower(*s);
        s++;
    }
}

/* return 1 if name is all '-' or digits. Used to remove orphan
     entries from ACls */
static int32 name_is_numeric(name)
    char *name;
{

    if (*name != '-' && !isdigit(*name))
        return 0;
    else
        name++;

    while (*name) {
        if (!isdigit(*name))
            return 0;
        name++;
    }

    return 1;                   /* name is (most likely numeric) */
}
/* end of general helper functions */


/* helper functions for PTS class: */

static struct ubik_client *internal_pts_new(code, sec, cell)
    int32 *code;
    int32 sec;
    char *cell;
{
    struct rx_connection *serverconns[MAXSERVERS];
    struct rx_securityClass *sc = NULL;
    struct ktc_token token;
    struct afsconf_cell info;
/*  tpf nog 03/29/99
 *  caused by changes in ubikclient.c,v 2.20 1996/12/10
 *            and     in ubikclient.c,v 2.24 1997/01/21
 * struct ubik_client *client;                             */
    struct ubik_client *client = 0;
    struct ktc_principal prin;
    int32 i;


    *code = internal_GetConfigDir();
    if (*code == 0)
        *code = internal_GetCellInfo(cell, "afsprot", &info);

    if (*code)
        return NULL;

    if (!rx_initialized) {
        /* printf("pts DEBUG rx_Init\n"); */
        *code = rx_Init(0);
        if (*code) {
            char buffer[256];
            sprintf(buffer, "AFS::PTS: could not initialize Rx (%d)\n", *code);
            BSETCODE(code, buffer);
            return NULL;
        }
        rx_initialized = 1;
    }

    if (sec > 0) {
        strcpy(prin.cell, info.name);
        prin.instance[0] = 0;
        strcpy(prin.name, "afs");
        *code = ktc_GetToken(&prin, &token, sizeof(token), NULL);
        if (*code) {
            if (sec == 2) {
                char buffer[256];
                sprintf(buffer, "AFS::PTS: failed to get token for service AFS (%d)\n", *code);
                BSETCODE(code, buffer);
                return NULL;    /* we want security or nothing */
            }
            sec = 0;
        }
        else {
            sc = (struct rx_securityClass *) rxkad_NewClientSecurityObject
                (rxkad_clear, &token.sessionKey, token.kvno,
                 token.ticketLen, token.ticket);
        }
    }

    if (sec == 0)
        sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
    else
        sec = 2;

    bzero(serverconns, sizeof(serverconns));
    for (i = 0; i < info.numServers; i++) {
        serverconns[i] = rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
                                          info.hostAddr[i].sin_port, PRSRV, sc, sec);
    }

    *code = ubik_ClientInit(serverconns, &client);
    if (*code) {

src/AFS.xs  view on Meta::CPAN

	case CCL | CSTAR:
	case NCCL | CSTAR:
	    curlp = lp;
	    while (cclass(ep, *lp++, ep[-1] == (CCL | CSTAR)));
	    ep += *ep;
	    goto star;

	  star:
	    do {
		lp--;
		if (rv = advance(lp, ep))
		    return (rv);
	    } while (lp > curlp);
	    return (0);

	default:
	    return (-1);
	}
}

static int
backref(register int i, register char *lp)
{
    register char *bp;

    bp = braslist[i];
    while (*bp++ == *lp++)
	if (bp >= braelist[i])
	    return (1);
    return (0);
}

static int
cclass(register char *set, register char c, int af)
{
    register int n;

    if (c == 0)
	return (0);
    n = *set++;
    while (--n)
	if (*set++ == c)
	    return (af);
    return (!af);
}

/* copy taken from <src/ubik/uinit.c> OpenAFS-1.4.14.1 */
static afs_int32
internal_ugen_ClientInit(int noAuthFlag, const char *confDir, char *cellName, afs_int32 sauth,
	       struct ubik_client **uclientp, int (*secproc) (),
	       char *funcName, afs_int32 gen_rxkad_level,
	       afs_int32 maxservers, char *serviceid, afs_int32 deadtime,
	       afs_uint32 server, afs_uint32 port, afs_int32 usrvid)
{
    afs_int32 code, scIndex, i;
    struct afsconf_cell info;
    struct afsconf_dir *tdir;
    struct ktc_principal sname;
    struct ktc_token ttoken;
    struct rx_securityClass *sc;
    /* This must change if VLDB_MAXSERVERS becomes larger than MAXSERVERS */
    static struct rx_connection *serverconns[MAXSERVERS];
    char cellstr[64];

    if (!rx_initialized) {
        /* printf("ugen DEBUG rx_Init\n"); */
        code = rx_Init(0);
        if (code) {
            char buffer[256];
            sprintf(buffer, "%s: could not initialize rx.\n", funcName);
            VSETCODE(code, buffer);
            return (code);
        }
        rx_initialized = 1;
    }
    rx_SetRxDeadTime(deadtime);

    if (sauth) {		/* -localauth */
	tdir = afsconf_Open(AFSDIR_SERVER_ETC_DIRPATH);
	if (!tdir) {
            char buffer[256];
            sprintf(buffer,
		    "%s: Could not process files in configuration directory (%s).\n",
		    funcName, AFSDIR_SERVER_ETC_DIRPATH);
	    code = -1;
            VSETCODE(code, buffer);
            return (code);
	}
	code = afsconf_ClientAuth(tdir, &sc, &scIndex);	/* sets sc,scIndex */
	if (code) {
	    afsconf_Close(tdir);
            char buffer[256];
            sprintf(buffer,
		    "%s: Could not get security object for -localAuth\n",
		    funcName);
            VSETCODE(code, buffer);
            return (code);
	}
	code = afsconf_GetCellInfo(tdir, tdir->cellName, serviceid, &info);
	if (code) {
	    afsconf_Close(tdir);
            char buffer[256];
            sprintf(buffer,
		    "%s: can't find cell %s's hosts in %s/%s\n",
		    funcName, cellName, AFSDIR_SERVER_ETC_DIRPATH,
		    AFSDIR_CELLSERVDB_FILE);
            VSETCODE(code, buffer);
            return (code);
	}
    } else {			/* not -localauth */
	tdir = afsconf_Open(confDir);
	if (!tdir) {
            char buffer[256];
            sprintf(buffer,
		    "%s: Could not process files in configuration directory (%s).\n",
		    funcName, confDir);
	    code = -1;
            VSETCODE(code, buffer);
            return (code);
	}

src/AFS.xs  view on Meta::CPAN

        while (*p && *p != '\n')
            p++;
        if (*p == '\n')
            p++;
    }
    return 1;
}

static int parse_volstat(stats, space)
    HV *stats;
    char *space;
{
    struct VolumeStatus *status;
    char *name, *offmsg, *motd;
    char type[32];
    status = (VolumeStatus *) space;
    name = (char *) status + sizeof(*status);
    offmsg = name + strlen(name) + 1;
    motd = offmsg + strlen(offmsg) + 1;
    safe_hv_store(stats, "Name", 4, newSVpv(name, strlen(name)), 0);
    safe_hv_store(stats, "OffMsg", 6, newSVpv(offmsg, strlen(offmsg)), 0);
    safe_hv_store(stats, "Motd", 4, newSVpv(motd, strlen(motd)), 0);
    safe_hv_store(stats, "Vid", 3, newSViv(status->Vid), 0);
    safe_hv_store(stats, "ParentId", 8, newSViv(status->ParentId), 0);
    safe_hv_store(stats, "Online", 6, newSViv(status->Online), 0);
    safe_hv_store(stats, "InService", 9, newSViv(status->InService), 0);
    safe_hv_store(stats, "Blessed", 7, newSViv(status->Blessed), 0);
    safe_hv_store(stats, "NeedsSalvage", 12, newSViv(status->NeedsSalvage), 0);
    if (status->Type == ReadOnly)
        strcpy(type, "ReadOnly");
    else if (status->Type == ReadWrite)
        strcpy(type, "ReadWrite");
    else
        sprintf(type, "%d", status->Type);
    safe_hv_store(stats, "Type", 4, newSVpv(type, strlen(type)), 0);
    safe_hv_store(stats, "MinQuota", 8, newSViv(status->MinQuota), 0);
    safe_hv_store(stats, "MaxQuota", 8, newSViv(status->MaxQuota), 0);
    safe_hv_store(stats, "BlocksInUse", 11, newSViv(status->BlocksInUse), 0);
    safe_hv_store(stats, "PartBlocksAvail", 15, newSViv(status->PartBlocksAvail), 0);
    safe_hv_store(stats, "PartMaxBlocks", 13, newSViv(status->PartMaxBlocks), 0);
    return 1;
}
/* end of helper functions for FS class: */


/* helper functions for KAS class: */
static int parse_kaentryinfo(stats, ka)
    HV *stats;
    struct kaentryinfo *ka;
{
    char buffer[sizeof(struct kaident)];

    sprintf(buffer, "%s%s%s", ka->modification_user.name,
            ka->modification_user.instance[0] ? "." : "", ka->modification_user.instance);

    safe_hv_store(stats, "modification_user", 17, newSVpv(buffer, strlen(buffer)), 0);
    safe_hv_store(stats, "minor_version", 13, newSViv(ka->minor_version), 0);
    safe_hv_store(stats, "flags", 5, newSViv(ka->flags), 0);
    safe_hv_store(stats, "user_expiration", 15, newSViv(ka->user_expiration), 0);
    safe_hv_store(stats, "modification_time", 17, newSViv(ka->modification_time), 0);
    safe_hv_store(stats, "change_password_time", 20, newSViv(ka->change_password_time), 0);
    safe_hv_store(stats, "max_ticket_lifetime", 19, newSViv(ka->max_ticket_lifetime), 0);
    safe_hv_store(stats, "key_version", 11, newSViv(ka->key_version), 0);
    safe_hv_store(stats, "keyCheckSum", 11, newSVuv(ka->keyCheckSum), 0);
    safe_hv_store(stats, "misc_auth_bytes", 15, newSVuv(ka->misc_auth_bytes), 0);
    safe_hv_store(stats, "passwd_reuse", 12, newSViv(ka->reserved3), 0);
    /*               1234567890123456789012345 */
    return 1;
}

static int parse_ka_getstats(stats, dstats, kas, kad)
    HV *stats;
    HV *dstats;
    struct kasstats *kas;
    struct kadstats *kad;
{
    safe_hv_store(stats, "minor_version", 13, newSViv(kas->minor_version), 0);
    safe_hv_store(stats, "allocs", 6, newSViv(kas->allocs), 0);
    safe_hv_store(stats, "frees", 5, newSViv(kas->frees), 0);
    safe_hv_store(stats, "cpws", 4, newSViv(kas->cpws), 0);
    safe_hv_store(stats, "reserved1", 9, newSViv(kas->reserved1), 0);
    safe_hv_store(stats, "reserved2", 9, newSViv(kas->reserved2), 0);
    safe_hv_store(stats, "reserved3", 9, newSViv(kas->reserved3), 0);
    safe_hv_store(stats, "reserved4", 9, newSViv(kas->reserved4), 0);

    /* dynamic stats */

    safe_hv_store(dstats, "minor_version", 13, newSViv(kad->minor_version), 0);

    safe_hv_store(dstats, "host", 4, newSViv(kad->host), 0);
    safe_hv_store(dstats, "start_time", 10, newSViv(kad->start_time), 0);
    safe_hv_store(dstats, "hashTableUtilization", 20, newSViv(kad->hashTableUtilization), 0);
    safe_hv_store(dstats, "string_checks", 13, newSViv(kad->string_checks), 0);
    safe_hv_store(dstats, "reserved1", 9, newSViv(kad->reserved1), 0);
    safe_hv_store(dstats, "reserved2", 9, newSViv(kad->reserved2), 0);
    safe_hv_store(dstats, "reserved3", 9, newSViv(kad->reserved3), 0);
    safe_hv_store(dstats, "reserved4", 9, newSViv(kad->reserved4), 0);
    safe_hv_store(dstats, "Authenticate_requests", 21, newSViv(kad->Authenticate.requests), 0);
    safe_hv_store(dstats, "Authenticate_aborts", 19, newSViv(kad->Authenticate.aborts), 0);
    safe_hv_store(dstats, "ChangePassword_requests", 23,
             newSViv(kad->ChangePassword.requests), 0);
    safe_hv_store(dstats, "ChangePassword_aborts", 21, newSViv(kad->ChangePassword.aborts), 0);
    safe_hv_store(dstats, "GetTicket_requests", 18, newSViv(kad->GetTicket.requests), 0);
    safe_hv_store(dstats, "GetTicket_aborts", 16, newSViv(kad->GetTicket.aborts), 0);
    safe_hv_store(dstats, "CreateUser_requests", 19, newSViv(kad->CreateUser.requests), 0);
    safe_hv_store(dstats, "CreateUser_aborts", 17, newSViv(kad->CreateUser.aborts), 0);
    safe_hv_store(dstats, "SetPassword_requests", 20, newSViv(kad->SetPassword.requests), 0);
    safe_hv_store(dstats, "SetPassword_aborts", 18, newSViv(kad->SetPassword.aborts), 0);
    safe_hv_store(dstats, "SetFields_requests", 18, newSViv(kad->SetFields.requests), 0);
    safe_hv_store(dstats, "SetFields_aborts", 16, newSViv(kad->SetFields.aborts), 0);
    safe_hv_store(dstats, "DeleteUser_requests", 19, newSViv(kad->DeleteUser.requests), 0);
    safe_hv_store(dstats, "DeleteUser_aborts", 17, newSViv(kad->DeleteUser.aborts), 0);
    safe_hv_store(dstats, "GetEntry_requests", 17, newSViv(kad->GetEntry.requests), 0);
    safe_hv_store(dstats, "GetEntry_aborts", 15, newSViv(kad->GetEntry.aborts), 0);
    safe_hv_store(dstats, "ListEntry_requests", 18, newSViv(kad->ListEntry.requests), 0);
    safe_hv_store(dstats, "ListEntry_aborts", 16, newSViv(kad->ListEntry.aborts), 0);
    safe_hv_store(dstats, "GetStats_requests", 17, newSViv(kad->GetStats.requests), 0);
    safe_hv_store(dstats, "GetStats_aborts", 15, newSViv(kad->GetStats.aborts), 0);
    safe_hv_store(dstats, "GetPassword_requests", 20, newSViv(kad->GetPassword.requests), 0);
    safe_hv_store(dstats, "GetPassword_aborts", 18, newSViv(kad->GetPassword.aborts), 0);
    safe_hv_store(dstats, "GetRandomKey_requests", 21, newSViv(kad->GetRandomKey.requests), 0);

src/AFS.xs  view on Meta::CPAN

        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, VIOCFLUSH, &vi, follow);

        SETCODE(code);
        RETVAL = (code == 0);
    }
    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, ".");

src/AFS.xs  view on Meta::CPAN

            /* printf("vldb_addsite DEBUG-4 Roid %s AROVolid %d\n", roid, arovolid); */
            vsu_ExtractName(avolname, roid);
            arovolid = vsu_GetVolumeID(avolname, cstruct, &err);
            /* printf("vldb_addsite DEBUG-5 Roid %s AROVolid %d\n", roid, arovolid); */
            if (!arovolid) {
                char buffer[256];
                sprintf(buffer, "AFS::VLDB: invalid ro volume id '%s'\n", roid);
                VSETCODE(-1, buffer);
                goto done;
            }
        }
#endif
        aserver = GetServer(server);
        if (aserver == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            goto done;
        }
        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);
            goto done;
        }
        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",
                        partition);
            VSETCODE(code ? code : -1, buffer);
            goto done;
        }
#if defined(OpenAFS_1_4_12)
        code = UV_AddSite2(aserver, apart, avolid, arovolid, valid);
#else
#if defined(OpenAFS_1_4_07)
        code = UV_AddSite(aserver, apart, avolid, valid);
#else
        code = UV_AddSite(aserver, apart, avolid);
#endif
#endif
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: addsite didn't work\n");
            VSETCODE(code, buffer);
            goto done;
        }
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vldb_changeloc(cstruct, id, server, partition)
        AFS::VLDB cstruct
        char *id
        char *server
        char *partition
    PREINIT:
#ifdef OpenAFS
        afs_int32 avolid, aserver, apart, code, err;
#endif
    CODE:
    {
#ifdef OpenAFS
        /* printf("DEBUG-1\n"); */
        RETVAL = 0;
        avolid = vsu_GetVolumeID(id, 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", id);
            VSETCODE(err ? err : -1, buffer);
            goto done;
        }
        /* printf("DEBUG-2\n"); */
        aserver = GetServer(server);
        if (aserver == 0) {
            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);

src/AFS.xs  view on Meta::CPAN

                char buffer[256];
                sprintf(buffer, "AFS::VLDB: could not interpret partition name '%s'\n",
                        partition);
                VSETCODE(-1, buffer);
                goto done;
            }
            if (!tserver) {
                char buffer[256];
                sprintf(buffer, "The PARTITION argument requires a SERVER argument\n");
                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",
                            partition);
                VSETCODE(code ? code : -1, buffer);
                goto done;
            }
            flags = 1;
        }

        if (volname && (strlen(volname) != 0)) {
            /* Synchronize an individual volume */
            code = UV_SyncVolume(tserver, pname, volname, flags);
        }
        else {
            if (!tserver) {
                char buffer[256];
                sprintf(buffer, "Without a VOLUME argument, the server argument is required\n");
                VSETCODE(-1, buffer);
                goto done;
            }
            code = UV_SyncVldb(tserver, pname, flags, 0 /*unused */ );
        }

        if (code) {
            char buffer[256];
            set_errbuff(buffer, code);
            VSETCODE(code, buffer);
            #PrintDiagnostics("syncvldb", code);
            #SETCODE(code);
            goto done;
        }
        else
            SETCODE(0);

        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vldb__changeaddr(cstruct, oldip, newip, remove=0)
        AFS::VLDB cstruct
        char *oldip
        char *newip
        int32 remove
    PREINIT:
        int32 ip1, ip2, vcode;
    CODE:
    {
        RETVAL = 0;

        ip1 = GetServer(oldip);
        if (!ip1) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: invalid host address\n");
            VSETCODE(EINVAL, buffer);
            goto done;
        }

        if ((newip && (strlen(newip)) && remove) || (!newip && !remove)) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: Must specify either 'NEWADDR <addr>' or 'REMOVE' flag\n");
            VSETCODE(EINVAL, buffer);
            goto done;
        }

        if (newip && (strlen(newip)) != 0) {
            ip2 = GetServer(newip);
            if (!ip2) {
                char buffer[256];
                sprintf(buffer, "AFS::VLDB: invalid host address\n");
                VSETCODE(EINVAL, buffer);
                goto done;
            }
        }
        else {
            /* Play a trick here. If we are removing an address, ip1 will be -1
             * and ip2 will be the original address. This switch prevents an
             * older revision vlserver from removing the IP address.
             */
            remove = 1;
            ip2 = ip1;
            ip1 = 0xffffffff;
        }

        vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
        if (vcode) {
            char buffer[256];
            if (remove) {
                char buff[80];
                sprintf(buff, "Could not remove server %s from the VLDB", oldip);
                if (vcode == VL_NOENT) {
                    sprintf(buffer, "%s\nvlserver does not support the REMOVE flag or VLDB: no such entry", buff);
                }
                else {
                    sprintf(buffer, "%s\n", buff);
                }
            }
            else {
                sprintf(buffer, "Could not change server %s to server %s\n", oldip, newip);
            }
            VSETCODE(vcode, buffer);
            goto done;
        }

        if (remove) {
            fprintf(STDOUT, "Removed server %s from the VLDB\n", oldip);
        }
        else {
            fprintf(STDOUT, "Changed server %s to server %s\n", oldip, newip);
        }

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vldb_remsite(cstruct,server,partition,name)
        AFS::VLDB cstruct
        char *server
        char *partition
        char *name
    PREINIT:
        afs_int32 avolid, aserver, apart, code = 1, err;
        char avolname[VOLSER_MAXVOLNAME + 1];
    CODE:
    {
        RETVAL = 0;
#ifdef OpenAFS_1_4
        vsu_ExtractName(avolname, name);
#else
        strcpy(avolname, name);
#endif
        avolid = vsu_GetVolumeID(avolname, 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", avolname);
            VSETCODE(err ? err : -1, buffer);
            goto done;
        }
        aserver = GetServer(server);
        if (aserver == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VLDB: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            goto done;
        }
        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);

src/AFS.xs  view on Meta::CPAN

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

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

int32
bos__stop(self, object=NULL, wait=0)
        AFS::BOS self
        SV * object
        int wait
    PREINIT:
        int32 code = 0;
    CODE:
    {
      /*                printf("DEBUG-XS-bos-stop-1 \n"); */
        if (object && (! (SvTYPE(SvRV(object)) == SVt_PVAV))) {
            code = -1;
            BSETCODE(code, "AFS::BOS: SERVER not an array reference\n");
            goto done;
        }

       /*                 printf("DEBUG-XS-bos-stop-2 \n"); */
        if (object && (SvTYPE(SvRV(object)) == SVt_PVAV)) {
            AV *av;
            SV *sv;
            char *instance;
            STRLEN namelen;
            int i, len;

            /*                      printf("DEBUG-XS-bos-stop-3 \n"); */
            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) {
                      /* instance = (char *) safemalloc(BOZO_BSSIZE); */
                        Newx(instance, BOZO_BSSIZE, char);
                        instance = SvPV(sv, namelen);
                        /*                      printf("DEBUG-XS-bos-stop-3-1 %d %s\n", len, instance); */
                        code = BOZO_SetStatus(self, instance, BSTAT_SHUTDOWN); 
                       /*                      printf("DEBUG-XS-bos-stop-3-2 %d \n", code); */
                        if (code) {
                            char buffer[256];
                            sprintf(buffer, "AFS::BOS: failed to change stop instance %s (%s)\n",
                                    instance, em(code));
                            BSETCODE(code, buffer);
                            goto done;
                        }
                        /*if (instance) */
                        /*    Safefree(instance); */
                    }
                }                       /* for loop */
            }
            /*                      printf("DEBUG-XS-bos-stop-4 \n"); */
        }

        /*         printf("DEBUG-XS-bos-stop-5 \n"); */
        if (wait) {
          /*                  printf("DEBUG-XS-bos-stop-5-1 \n"); */
            code = BOZO_WaitAll(self);
/*                  printf("DEBUG-XS-bos-stop-5-2 %d \n", code); */
            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;
            }
        }
        /*                  printf("DEBUG-XS-bos-stop-6 \n"); */
        SETCODE(code);
        done:
        /*                  printf("DEBUG-XS-bos-stop-7 \n"); */
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
bos__shutdown(self, object=NULL, wait=0)
        AFS::BOS self
        SV * object
        int wait
    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);
            if (len != -1) {
                for (i = 0; i <= len; i++) {

src/AFS.xs  view on Meta::CPAN

    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));
            BSETCODE(code, buffer);
        }
        RETVAL = val;
#else
        RETVAL = 0;
        not_here("AFS::BOS::getrestricted");
#endif
    }
    OUTPUT:
        RETVAL

int32
bos_setrestricted(self, mode)
        AFS::BOS self
        char *mode
    CODE:
    {
#ifdef BOS_RESTRICTED_MODE
        int32 val, code;
        util_GetInt32(mode, &val);
        code = BOZO_SetRestrictedMode(self, val);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to set restricted mode (%s)\n", em(code));
            BSETCODE(code, buffer);
        }



( run in 0.565 second using v1.01-cache-2.11-cpan-d8267643d1d )