AFS

 view release on metacpan or  search on metacpan

src/AFS.xs  view on Meta::CPAN

/***********************************************************************
 *
 * AFS.xs - AFS extensions for Perl
 *
 * RCS-Id: @(#)$RCS-Id: src/AFS.xs 73757dc Thu Oct 23 12:46:20 2014 +0200 Norbert E Gruener$
 *
 * Copyright (c) 2003, International Business Machines Corporation and others.
 *
 * This software has been released under the terms of the IBM Public
 * License.  For details, see the IBM-LICENSE file in the LICENCES
 * directory or online at http://www.openafs.org/dl/license10.html
 *
 * Contributors
 *    2004-2014: Norbert E. Gruener <nog@MPA-Garching.MPG.de>
 *         2003: Alf Wachsmann <alfw@slac.stanford.edu>
 *               Venkata Phani Kiran Achanta <neo_phani@hotmail.com>, and
 *               Norbert E. Gruener <nog@MPA-Garching.MPG.de>
 *    2001-2002: Norbert E. Gruener <nog@MPA-Garching.MPG.de>
 *
 * The original library was written by Roland Schemers <schemers@slapshot.stanford.edu>
 * and is covered by the following copyright:
 *
 * Copyright (c) 1994 Board of Trustees, Leland Stanford Jr. University
 * For conditions of distribution and use, see the copyright notice in
 * the Stanford-LICENCE file.
 *
 * The code for the original library were mainly taken from the AFS
 * source distribution, which comes with this message:
 *
 *    Copyright (C) 1989-1994 Transarc Corporation - All rights reserved
 *    P_R_P_Q_# (C) COPYRIGHT IBM CORPORATION 1987, 1988, 1989
 *
 ***********************************************************************/

#include "EXTERN.h"

#ifdef __sgi                    /* needed to get a clean compile */
#include <setjmp.h>
#endif

#include "perl.h"
#include "XSUB.h"
#define NEED_newRV_noinc
#define NEED_sv_2pv_flags
#include "ppport.h"

#include <afs/param.h>
/* tired of seeing messages about TRUE/FALSE being redefined in rx/xdr.h */
#undef TRUE
#undef FALSE
#include <rx/xdr.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <errno.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/stat.h>
#undef INIT
#include <afs/stds.h>
#include <afs/afs.h>
#include <afs/vice.h>
#include <afs/venus.h>
#undef VIRTUE
#undef VICE
#include <afs/prs_fs.h>
#include <afs/afsint.h>

#include <afs/auth.h>
#include <afs/cellconfig.h>
#if defined(AFS_3_4)
#else
#include <afs/dirpath.h>
#endif
#include <ubik.h>
#include <rx/rxkad.h>
#include <afs/vldbint.h>
#include <afs/volser.h>
#ifndef RV_RDONLY
#define RV_FULLRST      0x000001
#define RV_OFFLINE      0x000002
#define RV_CRDUMP       0x000010
#define RV_CRKEEP       0x000020
#define RV_CRNEW        0x000040
#define RV_LUDUMP       0x000100
#define RV_LUKEEP       0x000200
#define RV_LUNEW        0x000400
#define RV_RDONLY       0x010000
#define RV_CPINCR       0x020000
#define RV_NOVLDB       0x040000
#define RV_NOCLONE      0x080000
#define RV_NODEL        0x100000
#endif
#include <afs/vlserver.h>
#include <afs/volint.h>
#include <afs/cmd.h>
#include <afs/usd.h>
#include <afs/ptclient.h>
#include <afs/pterror.h>
#include <afs/print.h>
#include <afs/kauth.h>
#include <afs/kautils.h>
#include <afs/bosint.h>
#include <afs/bnode.h>

src/AFS.xs  view on Meta::CPAN

          sprintf(buffer, "VLDB: vldb database is empty\n");
          break;
      case VL_ENTDELETED:
          sprintf(buffer, "VLDB: entry is deleted (soft delete)\n");
          break;
      case VL_BADNAME:
          sprintf(buffer, "VLDB: volume name is illegal\n");
          break;
      case VL_BADINDEX:
          sprintf(buffer, "VLDB: index was out of range\n");
          break;
      case VL_BADVOLTYPE:
          sprintf(buffer, "VLDB: bad volume type\n");
          break;
      case VL_BADSERVER:
          sprintf(buffer, "VLDB: illegal server number (not within limits)\n");
          break;
      case VL_BADPARTITION:
          sprintf(buffer, "VLDB: bad partition number\n");
          break;
      case VL_REPSFULL:
          sprintf(buffer, "VLDB: run out of space for replication sites\n");
          break;
      case VL_NOREPSERVER:
          sprintf(buffer, "VLDB: no such repsite server exists\n");
          break;
      case VL_DUPREPSERVER:
          sprintf(buffer, "VLDB: replication site server already exists\n");
          break;
      case VL_RWNOTFOUND:
          sprintf(buffer, "VLDB: parent r/w entry not found\n");
          break;
      case VL_BADREFCOUNT:
          sprintf(buffer, "VLDB: illegal reference count number\n");
          break;
      case VL_SIZEEXCEEDED:
          sprintf(buffer, "VLDB: vldb size for attributes exceeded\n");
          break;
      case VL_BADENTRY:
          sprintf(buffer, "VLDB: bad incoming vldb entry\n");
          break;
      case VL_BADVOLIDBUMP:
          sprintf(buffer, "VLDB: illegal max volid increment\n");
          break;
      case VL_IDALREADYHASHED:
          sprintf(buffer, "VLDB: (RO/BACK) Id already hashed\n");
          break;
      case VL_ENTRYLOCKED:
          sprintf(buffer, "VLDB: vldb entry is already locked\n");
          break;
      case VL_BADVOLOPER:
          sprintf(buffer, "VLDB: bad volume operation code\n");
          break;
      case VL_BADRELLOCKTYPE:
          sprintf(buffer, "VLDB: bad release lock type\n");
          break;
      case VL_RERELEASE:
          sprintf(buffer, "VLDB: status report: last release was aborted\n");
          break;
      case VL_BADSERVERFLAG:
          sprintf(buffer, "VLDB: invalid replication site server flag\n");
          break;
      case VL_PERM:
          sprintf(buffer, "VLDB: no permission access for call\n");
          break;
      case VOLSERREAD_DUMPERROR:
          sprintf(buffer, "VOLSER:  Problems encountered in reading the dump file !\n");
          break;
      case VOLSERDUMPERROR:
          sprintf(buffer, "VOLSER: Problems encountered in doing the dump !\n");
          break;
      case VOLSERATTACH_ERROR:
          sprintf(buffer, "VOLSER: Could not attach the volume\n");
          break;
      case VOLSERDETACH_ERROR:
          sprintf(buffer, "VOLSER: Could not detach the volume\n");
          break;
      case VOLSERILLEGAL_PARTITION:
          sprintf(buffer, "VOLSER: encountered illegal partition number\n");
          break;
      case VOLSERBAD_ACCESS:
          sprintf(buffer, "VOLSER: permission denied, not a super user\n");
          break;
      case VOLSERVLDB_ERROR:
          sprintf(buffer, "VOLSER: error detected in the VLDB\n");
          break;
      case VOLSERBADNAME:
          sprintf(buffer, "VOLSER: error in volume name\n");
          break;
      case VOLSERVOLMOVED:
          sprintf(buffer, "VOLSER: volume has moved\n");
          break;
      case VOLSERBADOP:
          sprintf(buffer, "VOLSER: illegal operation\n");
          break;
      case VOLSERBADRELEASE:
          sprintf(buffer, "VOLSER: release could not be completed\n");
          break;
      case VOLSERVOLBUSY:
          sprintf(buffer, "VOLSER: volume is busy\n");
          break;
      case VOLSERNO_MEMORY:
          sprintf(buffer, "VOLSER: volume server is out of memory\n");
          break;
      case VOLSERNOVOL:
          sprintf(buffer,
                  "VOLSER: no such volume - location specified incorrectly or volume does not exist\n");
          break;
      case VOLSERMULTIRWVOL:
          sprintf(buffer,
                  "VOLSER: multiple RW volumes with same ID, one of which should be deleted\n");
          break;
      case VOLSERFAILEDOP:
          sprintf(buffer, "VOLSER: not all entries were successfully processed\n");
          break;
      default:
          sprintf(buffer, "Unknown ERROR code\n");
          break;
    }
    return 0;
}

src/AFS.xs  view on Meta::CPAN

    struct ubik_client *server;
    char *name;
{
    namelist lnames;
    idlist lids;
    register int32 code;

    lids.idlist_len = 1;
    lids.idlist_val = (int32 *) safemalloc(sizeof(int32));
    *lids.idlist_val = id;
    lnames.namelist_len = 0;
    lnames.namelist_val = NULL;
    code = ubik_Call(PR_IDToName, server, 0, &lids, &lnames);
    if (lnames.namelist_val) {
        strncpy(name, (char *) lnames.namelist_val, PR_MAXNAMELEN);
        if (lnames.namelist_val)
            free(lnames.namelist_val);
    }
    if (lids.idlist_val)
        safefree(lids.idlist_val);
    return code;
}

static int32 internal_pr_id(server, name, id, anon)
    struct ubik_client *server;
    char *name;
    int32 *id;
    int32 anon;
{
    namelist lnames;
    idlist lids;
    int32 code;

    if (convert_numeric_names && name_is_numeric(name)) {
        *id = atoi(name);
        return 0;
    }

    lids.idlist_len = 0;
    lids.idlist_val = 0;
    lnames.namelist_len = 1;
    lnames.namelist_val = (prname *) safemalloc(PR_MAXNAMELEN);
    stolower(name);
    strncpy((char *) lnames.namelist_val, name, PR_MAXNAMELEN);
    code = ubik_Call(PR_NameToID, server, 0, &lnames, &lids);
    if (lids.idlist_val) {
        *id = *lids.idlist_val;
        if (lids.idlist_val)
            free(lids.idlist_val);
    }
    if (lnames.namelist_val)
        safefree(lnames.namelist_val);

    if (code == 0 && anon == 0 && *id == ANONYMOUSID) {
        code = PRNOENT;
    }

    return code;
}

static int32 parse_pts_setfields(access, flags)
    char *access;
    int32 *flags;
{
    *flags = 0;
    if (strlen(access) != 5)
        return PRBADARG;

    if (access[0] == 'S')
        *flags |= 0x80;
    else if (access[0] == 's')
        *flags |= 0x40;
    else if (access[0] != '-')
        return PRBADARG;

    if (access[1] == 'O')
        *flags |= 0x20;
    else if (access[1] != '-')
        return PRBADARG;

    if (access[2] == 'M')
        *flags |= 0x10;
    else if (access[2] == 'm')
        *flags |= 0x08;
    else if (access[2] != '-')
        return PRBADARG;

    if (access[3] == 'A')
        *flags |= 0x04;
    else if (access[3] == 'a')
        *flags |= 0x02;
    else if (access[3] != '-')
        return PRBADARG;

    if (access[4] == 'r')
        *flags |= 0x01;
    else if (access[4] != '-')
        return PRBADARG;

    return 0;
}

static char *parse_flags_ptsaccess(flags)
    int32 flags;
{
    static char buff[6];
    strcpy(buff, "-----");
    if (flags & 0x01)
        buff[4] = 'r';
    if (flags & 0x02)
        buff[3] = 'a';
    if (flags & 0x04)
        buff[3] = 'A';
    if (flags & 0x08)
        buff[2] = 'm';
    if (flags & 0x10)
        buff[2] = 'M';
    if (flags & 0x20)
        buff[1] = 'O';
    if (flags & 0x40)
        buff[0] = 's';
    if (flags & 0x80)
        buff[0] = 'S';
    return buff;
}

static int parse_prcheckentry(server, stats, entry, lookupids, convertflags)
    struct ubik_client *server;
    HV *stats;
    struct prcheckentry *entry;
    int32 lookupids;
    int convertflags;
{
    int32 code;
    char name[PR_MAXNAMELEN];

    safe_hv_store(stats, "id", 2, newSViv(entry->id), 0);
    safe_hv_store(stats, "name", 4, newSVpv(entry->name, strlen(entry->name)), 0);
    if (convertflags) {
        safe_hv_store(stats, "flags", 5, newSVpv(parse_flags_ptsaccess(entry->flags), 5), 0);
    }
    else {
        safe_hv_store(stats, "flags", 5, newSViv(entry->flags), 0);
    }
    if (lookupids) {
        code = internal_pr_name(server, entry->owner, name);
        if (code)
            safe_hv_store(stats, "owner", 5, newSViv(entry->owner), 0);
        else
            safe_hv_store(stats, "owner", 5, newSVpv(name, strlen(name)), 0);
        code = internal_pr_name(server, entry->creator, name);
        if (code)
            safe_hv_store(stats, "creator", 7, newSViv(entry->creator), 0);
        else
            safe_hv_store(stats, "creator", 7, newSVpv(name, strlen(name)), 0);
    }
    else {
        safe_hv_store(stats, "owner", 5, newSViv(entry->owner), 0);
        safe_hv_store(stats, "creator", 7, newSViv(entry->creator), 0);
    }
    safe_hv_store(stats, "ngroups", 7, newSViv(entry->ngroups), 0);
/*  safe_hv_store(stats, "nusers",6, newSViv(entry->nusers),0);*/
    safe_hv_store(stats, "count", 5, newSViv(entry->count), 0);
/*
  safe_hv_store(stats, "reserved0",9, newSViv(entry->reserved[0]),0);
  safe_hv_store(stats, "reserved1",9, newSViv(entry->reserved[1]),0);
  safe_hv_store(stats, "reserved2",9, newSViv(entry->reserved[2]),0);
  safe_hv_store(stats, "reserved3",9, newSViv(entry->reserved[3]),0);
  safe_hv_store(stats, "reserved4",9, newSViv(entry->reserved[4]),0);
*/
    return 1;
}

static int parse_prdebugentry(server, stats, entry, lookupids, convertflags)
    struct ubik_client *server;
    HV *stats;
    struct prdebugentry *entry;
    int32 lookupids;
    int convertflags;
{
    int32 code;
    char name[PR_MAXNAMELEN];
    char buff[128];
    int i;

    safe_hv_store(stats, "id", 2, newSViv(entry->id), 0);
    safe_hv_store(stats, "name", 4, newSVpv(entry->name, strlen(entry->name)), 0);

    if (convertflags) {
        safe_hv_store(stats, "flags", 5, newSVpv(parse_flags_ptsaccess(entry->flags), 5), 0);
    }
    else {
        safe_hv_store(stats, "flags", 5, newSViv(entry->flags), 0);
    }

    if (lookupids) {
        code = internal_pr_name(server, entry->owner, name);
        if (code)
            safe_hv_store(stats, "owner", 5, newSViv(entry->owner), 0);
        else
            safe_hv_store(stats, "owner", 5, newSVpv(name, strlen(name)), 0);

        code = internal_pr_name(server, entry->creator, name);
        if (code)
            safe_hv_store(stats, "creator", 7, newSViv(entry->creator), 0);
        else
            safe_hv_store(stats, "creator", 7, newSVpv(name, strlen(name)), 0);

        for (i = 0; i < 10; i++) {
            sprintf(buff, "entries%d", i);
            code = internal_pr_name(server, entry->entries[i], name);
            if (code)
                safe_hv_store(stats, buff, strlen(buff), newSViv(entry->entries[i]), 0);
            else
                safe_hv_store(stats, buff, strlen(buff), newSVpv(name, strlen(name)), 0);

        }

    }
    else {
        safe_hv_store(stats, "owner", 5, newSViv(entry->owner), 0);
        safe_hv_store(stats, "creator", 7, newSViv(entry->creator), 0);
        for (i = 0; i < 10; i++) {
            sprintf(buff, "entries%d", i);
            safe_hv_store(stats, buff, strlen(buff), newSViv(entry->entries[i]), 0);
        }

    }
    safe_hv_store(stats, "cellid", 6, newSViv(entry->cellid), 0);
    safe_hv_store(stats, "next", 4, newSViv(entry->next), 0);
    safe_hv_store(stats, "nextID", 6, newSViv(entry->nextID), 0);
    safe_hv_store(stats, "nextname", 8, newSViv(entry->nextname), 0);
    safe_hv_store(stats, "ngroups", 7, newSViv(entry->ngroups), 0);
    safe_hv_store(stats, "nusers", 6, newSViv(entry->nusers), 0);
    safe_hv_store(stats, "count", 5, newSViv(entry->count), 0);
    safe_hv_store(stats, "instance", 8, newSViv(entry->instance), 0);
    safe_hv_store(stats, "owned", 5, newSViv(entry->owned), 0);
    safe_hv_store(stats, "nextOwned", 9, newSViv(entry->nextOwned), 0);
    safe_hv_store(stats, "parent", 6, newSViv(entry->parent), 0);
    safe_hv_store(stats, "sibling", 7, newSViv(entry->sibling), 0);
    safe_hv_store(stats, "child", 5, newSViv(entry->child), 0);
    safe_hv_store(stats, "reserved0", 9, newSViv(entry->reserved[0]), 0);
    safe_hv_store(stats, "reserved1", 9, newSViv(entry->reserved[1]), 0);
    safe_hv_store(stats, "reserved2", 9, newSViv(entry->reserved[2]), 0);
    safe_hv_store(stats, "reserved3", 9, newSViv(entry->reserved[3]), 0);
    safe_hv_store(stats, "reserved4", 9, newSViv(entry->reserved[4]), 0);

    return 1;
}

static int32 check_name_for_id(name, id)
    char *name;
    int32 id;

src/AFS.xs  view on Meta::CPAN

            VSETCODE(code, buffer);
            return (code);
	    break;
	}
    }

    afsconf_Close(tdir);

    if (secproc)	/* tell UV module about default authentication */
	(*secproc) (sc, scIndex);
    if (server) {
	serverconns[0] = rx_NewConnection(server, port,
					  usrvid, sc, scIndex);
    } else {
	if (info.numServers > maxservers) {
            char buffer[256];
            sprintf(buffer,
		    "%s: info.numServers=%d (> maxservers=%d)\n",
		    funcName, info.numServers, maxservers);
	    code = 1;
            VSETCODE(code, buffer);
            return (code);
	}
	for (i = 0; i < info.numServers; i++) {
	    serverconns[i] =
		rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
				 info.hostAddr[i].sin_port, usrvid,
				 sc, scIndex);
	}
    }
    /* Are we just setting up connections, or is this really ubik stuff? */
    if (uclientp) {
	*uclientp = 0;
	code = ubik_ClientInit(serverconns, uclientp);
	if (code) {
            char buffer[256];
            sprintf(buffer, "%s: ubik client init failed.\n", funcName);
            VSETCODE(code, buffer);
            return (code);
	}
    }
    return 0;
}

/* copy taken from <src/volser/vsutils.c> OpenAFS-1.4.14.1 */
static afs_int32
internal_vsu_ClientInit(int noAuthFlag, const char *confDir, char *cellName, afs_int32 sauth,
	       struct ubik_client **uclientp, int (*secproc)())
{
    return internal_ugen_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp,
			   secproc, "internal_vsu_ClientInit", vsu_rxkad_level,
			   VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 90,
			   0, 0, USER_SERVICE_ID);
}
/* end of helper functions for VOS && VLDB class */


/* helper functions for VOS class: */

#ifndef OpenAFS
void vsu_SetCrypt(cryptflag)
    int cryptflag;
{
    if (cryptflag) {
        vsu_rxkad_level = rxkad_crypt;
    }
    else {
        vsu_rxkad_level = rxkad_auth;
    }
}
#endif

int32 GetVolumeInfo(volid, server, part, voltype, rentry)
    afs_int32 volid, *server, *part, *voltype;
    register struct nvldbentry *rentry;
{
    afs_int32 vcode;
    int i, index = -1;

    vcode = VLDB_GetEntryByID(volid, -1, rentry);
    if (vcode) {
        char buffer[256];
        sprintf(buffer, "Could not fetch the entry for volume %u from VLDB \n", volid);
        VSETCODE(vcode, buffer);
        return (vcode);
    }
    MapHostToNetwork(rentry);
    if (volid == rentry->volumeId[ROVOL]) {
        *voltype = ROVOL;
        for (i = 0; i < rentry->nServers; i++) {
            if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL) &&
                !(rentry->serverFlags[i] & RO_DONTUSE))
                index = i;
        }
        if (index == -1) {
            char buffer[256];
            sprintf(buffer, "RO volume is not found in VLDB entry for volume %u\n",
                    volid);
            VSETCODE(-1, buffer);
            return -1;
        }

        *server = rentry->serverNumber[index];
        *part = rentry->serverPartition[index];
        return 0;
    }

    index = Lp_GetRwIndex(rentry);
    if (index == -1) {
        char buffer[256];
        sprintf(buffer, "RW Volume is not found in VLDB entry for volume %u\n", volid);
        VSETCODE(-1, buffer);
        return -1;
    }
    if (volid == rentry->volumeId[RWVOL]) {
        *voltype = RWVOL;
        *server = rentry->serverNumber[index];
        *part = rentry->serverPartition[index];
        return 0;
    }
    if (volid == rentry->volumeId[BACKVOL]) {
        *voltype = BACKVOL;
        *server = rentry->serverNumber[index];
        *part = rentry->serverPartition[index];

src/AFS.xs  view on Meta::CPAN

    afs_int32 a_count;

{                               /*XDisplayVolumes */

    int totalOK;                /*Total OK volumes */
    int totalNotOK;             /*Total screwed volumes */
    int totalBusy;              /*Total busy volumes */
    int i;                      /*Loop variable */
    char buff[32];

    /* Initialize counters and (global!!) queues.*/
    totalOK = 0;
    totalNotOK = 0;
    totalBusy = 0;
    qInit(&busyHead);
    qInit(&notokHead);

    /* Display each volume in the list.*/
    for (i = 0; i < a_count; i++) {
        HV *vol = (HV *) sv_2mortal((SV *) newHV());
        myXDisplayFormat(vol,
                         a_xInfoP,
                         a_servID,
                         a_partID, &totalOK, &totalNotOK, &totalBusy);
        if (a_xInfoP->status == VOK) {
            safe_hv_store(part, a_xInfoP->name, strlen(a_xInfoP->name), newRV_inc((SV *) (vol)), 0);
        }
        else if (a_xInfoP->status == VBUSY) {
            sprintf(buff, "volume_busy_%d", i);
            safe_hv_store(part, buff, strlen(buff), newRV_inc((SV *) (vol)), 0);
            /* fprintf(STDERR, "DEBUG-1: %s %d\n", buff, strlen(buff)); */
        }
        else {
            sprintf(buff, "volume_notok_%d", i);
            safe_hv_store(part, buff, strlen(buff), newRV_inc((SV *) (vol)), 0);
            /* fprintf(STDERR, "DEBUG-2: %s %d\n", buff, strlen(buff)); */
        }
        a_xInfoP++;
    }

    /* If any volumes were found to be busy or screwed, display them.*/
    safe_hv_store(part, " totalOK", 8, newSViv(totalOK), 0);
    safe_hv_store(part, " totalBusy", 10, newSViv(totalBusy), 0);
    safe_hv_store(part, " totalNotOK", 11, newSViv(totalNotOK), 0);
}                               /*XDisplayVolumes */
/* end of helper functions for VOS class */


/* helper functions for VLDB class: */

void myEnumerateEntry(stats, entry)
    HV *stats;
    struct nvldbentry *entry;
{
    int i;
    char pname[10];
    char hostname[256];
    int isMixed = 0;
    AV *av = (AV *) sv_2mortal((SV *) newAV());

    if (entry->flags & RW_EXISTS)
        safe_hv_store(stats, "RWrite", 6, newSViv(entry->volumeId[RWVOL]), 0);
    if (entry->flags & RO_EXISTS)
        safe_hv_store(stats, "ROnly", 5, newSViv(entry->volumeId[ROVOL]), 0);
    if (entry->flags & BACK_EXISTS)
        safe_hv_store(stats, "Backup", 6, newSViv(entry->volumeId[BACKVOL]), 0);
    if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
        safe_hv_store(stats, "cloneId", 7, newSViv(entry->cloneId), 0);

    safe_hv_store(stats, "nServers", 8, newSViv(entry->nServers), 0);

    for (i = 0; i < entry->nServers; i++) {
        if (entry->serverFlags[i] & NEW_REPSITE)
            isMixed = 1;
    }

    for (i = 0; i < entry->nServers; i++) {
        HV *server = (HV *) sv_2mortal((SV *) newHV());
        MapPartIdIntoName(entry->serverPartition[i], pname);
        strcpy(hostname, (char *) hostutil_GetNameByINet(entry->serverNumber[i]));
        safe_hv_store(server, "name", 4, newSVpv(hostname, strlen((char *) hostname)), 0);
        safe_hv_store(server, "partition", 9, newSVpv(pname, strlen((char *) pname)), 0);

        safe_hv_store(server, "serverFlags", 11, newSViv(entry->serverFlags[i]), 0);

        if (entry->serverFlags[i] & ITSRWVOL)
            safe_hv_store(server, "type", 4, newSVpv("RW", 2), 0);
        else
            safe_hv_store(server, "type", 4, newSVpv("RO", 2), 0);

        if (isMixed) {
            if (entry->serverFlags[i] & NEW_REPSITE)
                safe_hv_store(server, "release", 7, newSVpv("New release", 11), 0);
            else
                safe_hv_store(server, "release", 7, newSVpv("Old release", 11), 0);
        }
        else {
            if (entry->serverFlags[i] & RO_DONTUSE)
                safe_hv_store(server, "release", 7, newSVpv("Not released", 12), 0);
        }
        av_push(av, newRV_inc((SV *) (server)));
    }
    safe_hv_store(stats, "server", 6, newRV_inc((SV *) (av)), 0);

    safe_hv_store(stats, "flags", 5, newSViv(entry->flags), 0);
    if (entry->flags & VLOP_ALLOPERS)
        safe_hv_store(stats, "locked", 6, newSViv(entry->flags & VLOP_ALLOPERS), 0);

    return;
}

static int VolumeInfoCmd(stats, name)
    HV *stats;
    char *name;
{
    struct nvldbentry entry;
    afs_int32 vcode;

    /* printf("DEBUG-1-VolumeInfoCmd %s \n", name); */
    /* The vlserver will handle names with the .readonly
     * and .backup extension as well as volume ids.
     */
    vcode = VLDB_GetEntryByName(name, &entry);
    /* printf("DEBUG-2-VolumeInfoCmd %d \n", vcode); */
    if (vcode)
        return (vcode);

    /* printf("DEBUG-3-VolumeInfoCmd \n"); */
    MapHostToNetwork(&entry);
    /* printf("DEBUG-4-VolumeInfoCmd \n"); */
    myEnumerateEntry(stats, &entry);
    /* printf("DEBUG-5-VolumeInfoCmd \n"); */

    return 0;
}

/* static void PostVolumeStats_ZZZ(volinfo, entry) */
/*     HV *volinfo; */
/*     struct nvldbentry *entry; */
/* { */
/*     myEnumerateEntry(volinfo, entry); */
/*     /\* Check for VLOP_ALLOPERS *\/ */
/*     if (entry->flags & VLOP_ALLOPERS) */
/*         fprintf(STDOUT, "    Volume is currently LOCKED  \n"); */
/*     return; */
/* } */

static void myprint_addrs(addr, addrs, m_uuid, nentries, print, noresolve)
    HV * addr;
    const bulkaddrs * addrs;
    const afsUUID * m_uuid;
    int nentries;
    int print;
    int noresolve;
{
    afs_int32 vcode;
    afs_int32 i;
    afs_int32 *addrp;
    bulkaddrs m_addrs;
    ListAddrByAttributes m_attrs;
    afs_int32 m_unique, m_nentries, *m_addrp;
    afs_int32 base, index;
    char buf[1024];

#ifdef OpenAFS
    if (print) {
        afsUUID_to_string(m_uuid, buf, sizeof(buf));
        safe_hv_store(addr, "UUID", 4, newSVpv(buf, strlen(buf)), 0);
    }
#else
    noresolve = 0;
#endif

    /* print out the list of all the server */
    addrp = (afs_int32 *) addrs->bulkaddrs_val;
    for (i = 0; i < nentries; i++, addrp++) {
        char key[7];
        int j = i + 1;
        /* If it is a multihomed address, then we will need to 
         * get the addresses for this multihomed server from
         * the vlserver and print them.
         */
        if (((*addrp & 0xff000000) == 0xff000000) && ((*addrp) & 0xffff)) {
            /* Get the list of multihomed fileservers */
            base = (*addrp >> 16) & 0xff;
            index = (*addrp) & 0xffff;

            if ((base >= 0) && (base <= VL_MAX_ADDREXTBLKS) &&
                (index >= 1) && (index <= VL_MHSRV_PERBLK)) {
                AV *names = newAV();
                AV *IPs = newAV();

                m_attrs.Mask = VLADDR_INDEX;
                m_attrs.index = (base * VL_MHSRV_PERBLK) + index;
                m_nentries = 0;
                m_addrs.bulkaddrs_val = 0;
                m_addrs.bulkaddrs_len = 0;
                vcode = ubik_Call(VL_GetAddrsU, cstruct, 0,
                                  &m_attrs, &m_uuid, &m_unique, &m_nentries, &m_addrs);
                if (vcode) {
                    char buffer[256];
                    sprintf(buffer,
                            "AFS::VLDB: could not list the multi-homed server addresses\n");

src/AFS.xs  view on Meta::CPAN

                            ttoken.kvno);
                }
                /* kerberos tix */
                if (aencrypt)
                    encryptLevel = rxkad_crypt;
                else
                    encryptLevel = rxkad_clear;
                sc[2] = (struct rx_securityClass *)
                    rxkad_NewClientSecurityObject
                    (encryptLevel, &ttoken.sessionKey,
                     ttoken.kvno, ttoken.ticketLen, ttoken.ticket);
                scIndex = 2;
            }
            else
                fprintf(stderr, "AFS::BOS %d (getting tickets)", *code);
        }
        if ((scIndex == 0) || (sc[scIndex] == 0)) {
            fprintf(stderr, "AFS::BOS: running unauthenticated\n");
            scIndex = 0;
        }
    }
    tconn = rx_NewConnection(addr, htons(AFSCONF_NANNYPORT), 1, sc[scIndex], scIndex);
    if (!tconn) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS: could not create rx connection\n");
        *code = -1;
        BSETCODE(code, buffer);
/*         printf("bos DEBUG-7\n"); */
        return NULL;
    }
    rxs_Release(sc[scIndex]);

    return tconn;
}

static int DoStat(stats, aname, aconn, aint32p, firstTime)
    HV *stats;
    IN char *aname;
    IN register struct rx_connection *aconn;
    IN int aint32p;
    IN int firstTime;           /* true iff first instance in cmd */
{
    afs_int32 temp;
    char buffer[500];
    register afs_int32 code;
    register afs_int32 i;
    struct bozo_status istatus;
    char *tp;
    char *is1, *is2, *is3, *is4;        /* instance strings */
    char info[255];

    tp = buffer;
    code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
    if (code) {
        char buf[256];
        sprintf(buf, "AFS::BOS: failed to get instance info for '%s' (%s)\n",
                aname, em(code));
        BSETCODE(code, buf);
        return -1;
    }
    if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS)) {
        char buf[256];
        sprintf(buf, "Bosserver reports inappropriate access on server directories\n");
        BSETCODE(-1, buf);
    }
    /*printf("Instance %s, ", aname); */
    if (aint32p) {
        /* printf("(type is %s) ", buffer); */
        safe_hv_store(stats, "type", 4, newSVpv(buffer, strlen(buffer)), 0);
    }

    sprintf(info, "%s", "");
    if (istatus.fileGoal == istatus.goal) {
        if (!istatus.goal)
            sprintf(info, "%s", "disabled");
    }
    else {
        if (istatus.fileGoal)
            sprintf(info, "%s", "temporarily disabled");
        else
            sprintf(info, "%s", "temporarily enabled");
    }
    safe_hv_store(stats, "info", 4, newSVpv(info, strlen(info)), 0);
    safe_hv_store(stats, "goal", 4, newSViv(istatus.goal), 0);
    safe_hv_store(stats, "fileGoal", 8, newSViv(istatus.fileGoal), 0);

    if (istatus.flags & BOZO_ERRORSTOP) {
        /* printf("stopped for too many errors, "); */
        safe_hv_store(stats, "status", 6, newSViv(BOZO_ERRORSTOP), 0);
    }
    if (istatus.flags & BOZO_HASCORE) {
        /* printf("has core file, "); */
        safe_hv_store(stats, "status", 6, newSViv(BOZO_HASCORE), 0);
    }
    safe_hv_store(stats, "flags", 5, newSViv(istatus.flags), 0);

    tp = buffer;
    code = BOZO_GetStatus(aconn, aname, &temp, &tp);
    if (code) {
        char buf[256];
        sprintf(buf, "AFS::BOS: failed to get status for instance '%s' (%s)\n",
                aname, em(code));
        BSETCODE(code, buf);
    }
    else {
        /* printf("currently ", aname); */
        /* if (temp == BSTAT_NORMAL) printf("running normally.\n"); */
        /* else if (temp == BSTAT_SHUTDOWN) printf("shutdown.\n"); */
        /* else if (temp == BSTAT_STARTINGUP) printf("starting up.\n"); */
        /* else if (temp == BSTAT_SHUTTINGDOWN) printf("shutting down.\n"); */
        safe_hv_store(stats, "status", 6, newSViv(temp), 0);
        if (buffer[0] != 0) {
            /* printf("    Auxiliary status is: %s.\n", buffer); */
            safe_hv_store(stats, "aux_status", 10, newSVpv(buffer, strlen(buffer)), 0);
        }
    }

    /* are we done yet? */
    if (!aint32p)
        return 0;

    if (istatus.procStartTime) {
        /* printf("    Process last started at %s (%d proc starts)\n", */
        /*        DateOf(istatus.procStartTime), istatus.procStarts); */
        safe_hv_store(stats, "procStartTime", 13, newSViv(istatus.procStartTime), 0);
        safe_hv_store(stats, "procStarts", 10, newSViv(istatus.procStarts), 0);
    }
    if (istatus.lastAnyExit) {
        /* printf("    Last exit at %s\n", DateOf(istatus.lastAnyExit)); */
        safe_hv_store(stats, "lastAnyExit", 11, newSViv(istatus.lastAnyExit), 0);
    }
    if (istatus.lastErrorExit) {
        is1 = is2 = is3 = is4 = (char *) 0;
        /* printf("    Last error exit at %s, ", DateOf(istatus.lastErrorExit)); */
        safe_hv_store(stats, "lastErrorExit", 13, newSViv(istatus.lastErrorExit), 0);
        code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
        /* don't complain about failing call, since could simply mean
         * interface mismatch.
         */
        if (code == 0) {
            if (*is1 != 0) {
                /* non-null instance string */
                /* printf("by %s, ", is1); */
                safe_hv_store(stats, "by", 2, newSVpv(is1, strlen(is1)), 0);
            }
            if (is1)
                free(is1);
            if (is2)
                free(is2);
            if (is3)
                free(is3);
            if (is4)
                free(is4);
        }
        if (istatus.errorSignal) {

src/AFS.xs  view on Meta::CPAN

            return 0;
        facl = format_rights(acl);
        safe_hv_store(nh, user, strlen(user), newSVpv(facl, strlen(facl)), 0);
        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);

src/AFS.xs  view on Meta::CPAN

            }
            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; */

src/AFS.xs  view on Meta::CPAN

            SETCODE(code);
        }
        else {
            sv_setpv(ST(0), version);
        }
#endif
    }

void
fs_get_syslib_version()
    CODE:
    {
        extern char *AFSVersion;

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

void
fs_XSVERSION()
    CODE:
    {
        ST(0) = sv_newmortal();
        sv_setpv(ST(0), xs_version);
    }

void
fs_sysname(newname=0)
        char *  newname
    CODE:
    {
        struct ViceIoctl vi;
        int32 code, set;
        char space[MAXSIZE];

        set = (newname && *newname);

        vi.in = space;
        bcopy(&set, space, sizeof(set));
        vi.in_size = sizeof(set);
        if (set) {
            strcpy(space + sizeof(set), newname);
            vi.in_size += strlen(newname) + 1;
        }
        vi.out_size = MAXSIZE;
        vi.out = (caddr_t) space;
        code = pioctl(NULL, VIOC_AFS_SYSNAME, &vi, 0);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setpv(ST(0), space + sizeof(set));
        }
    }

void
fs_getcrypt()
    CODE:
    {
#ifdef VIOC_GETRXKCRYPT
        struct ViceIoctl vi;
        int32 code, flag;
        char space[MAXSIZE];

        vi.in_size = 0;
        vi.out_size = MAXSIZE;
        vi.out = (caddr_t) space;
        code = pioctl(0, VIOC_GETRXKCRYPT, &vi, 1);
        SETCODE(code);

        ST(0) = sv_newmortal();
        if (code == 0) {
            bcopy((char *) space, &flag, sizeof(int32));
            sv_setiv(ST(0), flag);
        }
#else
        not_here("AFS::CM::getcrypt");
#endif
    }

int32
fs_setcrypt(as)
        char *as
    CODE:
    {
#ifdef VIOC_SETRXKCRYPT
        struct ViceIoctl vi;
        int32 code, flag;

        if (strcmp(as, "on") == 0)
            flag = 1;
        else if (strcmp(as, "off") == 0)
            flag = 0;
        else {
            warn("setcrypt: %s must be \"on\" or \"off\".\n", as);
            SETCODE(EINVAL);
            XSRETURN_UNDEF;
        }

        vi.in = (char *) &flag;
        vi.in_size = sizeof(flag);
        vi.out_size = 0;
        code = pioctl(0, VIOC_SETRXKCRYPT, &vi, 1);
        SETCODE(code);
        RETVAL = (code == 0);
#else
        not_here("AFS::CM::setcrypt");
#endif
    }
    OUTPUT:
        RETVAL

void
fs_whichcell(dir,follow=1)
        char *  dir
        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(dir, VIOC_FILE_CELL_NAME, &vi, follow);
        SETCODE(code);
        ST(0) = sv_newmortal();
        if (code == 0) {
            sv_setpv(ST(0), space);
        }
    }

void
fs_lsmount(path,follow=1)
        char *  path
        int32   follow
    CODE:
    {
        struct ViceIoctl vi;
        int32 code;
        char space[MAXSIZE];
        char *dir, *file;
        char parent[1024];

        if (strlen(path) > (sizeof(parent) - 1))
            code = EINVAL;
        else {
            strcpy(parent, path);
            file = strrchr(parent, '/');
            if (file) {
                dir = parent;
                *file++ = '\0';
            }
            else {
                dir = ".";
                file = parent;
            }

            vi.in_size = strlen(file) + 1;
            vi.in = file;

src/AFS.xs  view on Meta::CPAN

        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);

src/AFS.xs  view on Meta::CPAN

        if (rovolid == 0) {
            arovolid = NULL;
        }
        code = UV_CreateVolume3(tserver, pnum, name, quota, 0, 0, 0, 0, &volid, arovolid, &bkvolid);
#else
        code = UV_CreateVolume2(tserver, pnum, name, quota, 0, 0, 0, 0, &volid);
#endif
        if (code) {
            #PrintDiagnostics("create", code);
            SETCODE(code);
            goto done;
        }

        SETCODE(0);
        RETVAL = (int32)volid;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vos_backup(cstruct, name)
        AFS::VOS cstruct
        char *name
    PREINIT:
        int32 avolid, aserver, apart, vtype, code, err;
        int32 buvolid, buserver, bupart, butype;
        struct nvldbentry entry;
        struct nvldbentry buentry;
    CODE:
    {
        RETVAL = 0;
        avolid = vsu_GetVolumeID(name, cstruct, &err);
        if (avolid == 0) {
            char buffer[256];
            if (err)
                set_errbuff(buffer, err);
            else
                sprintf(buffer, "AFS::VOS: can't find volume ID or name '%s'\n", name);
            VSETCODE(err ? err : ENOENT, buffer);
            goto done;
        }
        code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
        if (code) {
            SETCODE(code);
            goto done;
        }
                /* verify this is a readwrite volume */

        if (vtype != RWVOL) {
            char buffer[256];
            sprintf(buffer, "%s not RW volume\n", name);
            VSETCODE(-1, buffer);
            goto done;
        }

                /* is there a backup volume already? */

        if (entry.flags & BACK_EXISTS) {
            /* yep, where is it? */

            buvolid = entry.volumeId[BACKVOL];
            code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
            if (code) {
                SETCODE(code);
                goto done;
            }
            /* is it local? */
            code = VLDB_IsSameAddrs(buserver, aserver, &err);
            if (err) {
                char buffer[256];
                sprintf(buffer,
                        "Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
                        buserver);
                VSETCODE(err, buffer);
                goto done;
            }
            if (!code) {
                char buffer[256];
                sprintf(buffer, "FATAL ERROR: backup volume %u exists on server %u\n",
                        buvolid, buserver);
                VSETCODE(-1, buffer);
                goto done;
            }
        }
                /* nope, carry on */

        code = UV_BackupVolume(aserver, apart, avolid);

        if (code) {
            PrintDiagnostics("backup", code);
            SETCODE(0);
            goto done;
        }
        #fprintf(STDOUT, "Created backup volume for %s \n", name);
        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vos_remove(cstruct, name, servername=NULL, parti=NULL)
        AFS::VOS cstruct
        char *name
        char *servername
        char *parti
    PREINIT:
        afs_int32 err, code = 0;
        afs_int32 server = 0, partition = -1, volid;
        afs_int32 idx, j;
    CODE:
    {
        RETVAL = 0;
        if (servername && strlen(servername) != 0) {
            server = GetServer(servername);
            if (!server) {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
                VSETCODE(ENOENT, buffer);
                goto done;
            }
        }

        if (parti && strlen(parti) != 0) {
            partition = volutil_GetPartitionID(parti);
            if (partition < 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", parti);
                VSETCODE(EINVAL, buffer);
                goto done;
            }

            /* Check for validity of the partition */
            if (!IsPartValid(partition, server, &code)) {
                char buffer[256];
                if (code)
                    set_errbuff(buffer, code);
                else
                    sprintf(buffer, "AFS::VOS: partition %s does not exist on the server\n",
                            parti);
                VSETCODE(ENOENT, buffer);
                goto done;
            }
        }

        volid = vsu_GetVolumeID(name, cstruct, &err);
        if (volid == 0) {
            char buffer[256];
            sprintf(buffer, "Can't find volume name '%s' in VLDB\n", name);
            if (err)
                set_errbuff(buffer, err);
            VSETCODE(ENOENT, buffer);
            goto done;
        }

            /* If the server or partition option are not complete, try to fill
             * them in from the VLDB entry.
             */
        if ((partition == -1) || !server) {
            struct nvldbentry entry;

            code = VLDB_GetEntryByID(volid, -1, &entry);
            if (code) {
                char buffer[256];
                sprintf(buffer, "Could not fetch the entry for volume %u from VLDB\n", volid);
                VSETCODE(code, buffer);
                goto done;
            }

            if (((volid == entry.volumeId[RWVOL]) && (entry.flags & RW_EXISTS)) ||
                ((volid == entry.volumeId[BACKVOL]) && (entry.flags & BACK_EXISTS))) {
                idx = Lp_GetRwIndex(&entry);
                if ((idx == -1) ||
                    (server && (server != entry.serverNumber[idx])) ||
                    ((partition != -1) && (partition != entry.serverPartition[idx]))) {
                    char buffer[256];
                    sprintf(buffer, "AFS::VOS: Volume '%s' no match\n", name);
                    VSETCODE(ENOENT, buffer);
                    goto done;
                }
            }
            else if ((volid == entry.volumeId[ROVOL]) && (entry.flags & RO_EXISTS)) {
                for (idx = -1, j = 0; j < entry.nServers; j++) {
                    if (entry.serverFlags[j] != ITSROVOL)
                        continue;

                    if (((server == 0) || (server == entry.serverNumber[j])) &&
                        ((partition == -1) || (partition == entry.serverPartition[j]))) {
                        if (idx != -1) {
                            char buffer[256];
                            sprintf(buffer, "AFS::VOS: Volume '%s' matches more than one RO\n",
                                    name);
                            VSETCODE(ENOENT, buffer);
                            goto done;
                        }
                        idx = j;
                    }
                }
                if (idx == -1) {
                    char buffer[256];
                    sprintf(buffer, "AFS::VOS: Volume '%s' no match\n", name);
                    VSETCODE(ENOENT, buffer);
                    goto done;
                }
            }
            else {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: Volume '%s' no match\n", name);
                VSETCODE(ENOENT, buffer);
                goto done;
            }

            server = htonl(entry.serverNumber[idx]);
            partition = entry.serverPartition[idx];
        }

        code = UV_DeleteVolume(server, partition, volid);
        if (code) {
            PrintDiagnostics("remove", code);
            SETCODE(code);
            goto done;
        }

        SETCODE(0);
        RETVAL = volid;

        done:
        ;
    }
    OUTPUT: 
        RETVAL

int32
vos_rename(cstruct,oldname,newname)
        AFS::VOS cstruct
        char * oldname
        char * newname
    PREINIT:
        afs_int32 code1, code2, code;
        struct nvldbentry entry;
    CODE:
    {

src/AFS.xs  view on Meta::CPAN

            char buffer[256];
            sprintf(buffer, "Illegal volume name %s, should not end in .readonly or .backup\n",
                    newname);
            VSETCODE(-1, buffer);
            goto done;
        }
        if (IsNumeric(newname)) {
            char buffer[256];
            sprintf(buffer, "Illegal volume name %s, should not be a number\n", newname);
            VSETCODE(-1, buffer);
            goto done;
        }
        MapHostToNetwork(&entry);
        code = UV_RenameVolume(&entry, oldname, newname);
        if (code) {
            PrintDiagnostics("rename", code);
            SETCODE(code);
            goto done;
        }
        #fprintf(STDOUT, "Renamed volume %s to %s\n", oldname, newname);

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vos__setfields(cstruct, name, mquota=Nullsv, clearuse=Nullsv)
        AFS::VOS cstruct
        char *name
        SV * mquota
        SV * clearuse
    PREINIT:
#ifdef OpenAFS
        struct nvldbentry entry;
        volintInfo info;
        int32 volid;
        int32 clear, code, err;
        int32 aserver, apart;
        int previdx = -1;
#endif
    CODE:
    {
#ifdef OpenAFS
        if (!mquota)
            mquota = newSViv(-1);
        if (!clearuse)
            clearuse = newSViv(0);
        if ((!SvIOKp(mquota))) {     /* -max <quota> */
            char buffer[256];
            sprintf(buffer, "invalid quota value\n");
            VSETCODE(EINVAL, buffer);
            goto done;
        }
        if ((!SvIOKp(clearuse))) {     /* -clearuse */
            char buffer[256];
            sprintf(buffer, "flag \"clearuse\" is not an integer\n");
            VSETCODE(EINVAL, buffer);
            goto done;
        }

        /* printf("vos-setfields DEBUG-1 name %s mquota %d clearuse %d \n", name, (int)SvIV(mquota), (int)SvIV(clearuse)); */
        RETVAL = 0;
        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);
            goto done;
        }

        code = VLDB_GetEntryByID(volid, RWVOL, &entry);
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not fetch the entry for volume number %u from VLDB \n", volid);
            VSETCODE(code, buffer);
            goto done;
        }
        MapHostToNetwork(&entry);

        GetServerAndPart(&entry, RWVOL, &aserver, &apart, &previdx);
        if (previdx == -1) {
            char buffer[256];
            sprintf(buffer, "Volume %s does not exist in VLDB\n\n", name);
            VSETCODE(ENOENT, buffer);
            goto done;
        }

        Zero(&info, 1, volintInfo);

        info.volid = volid;
        info.type = RWVOL;
        info.creationDate = -1;
        info.updateDate = -1;
        info.dayUse = -1;
        info.maxquota = -1;
        info.flags = -1;
        info.spare0 = -1;
        info.spare1 = -1;
        info.spare2 = -1;
        info.spare3 = -1;

        info.maxquota = SvIV(mquota);

        clear = SvIV(clearuse);
        if (clear)
            info.dayUse = 0;
        code = UV_SetVolumeInfo(aserver, apart, volid, &info);
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not update volume info fields for volume number %u\n", volid);
            VSETCODE(code, buffer);
        }
        else
            SETCODE(code);
        RETVAL = 1;

        done:
        ;
#else
        not_here("AFS::VOS::setfields");
#endif
    }
    OUTPUT:
        RETVAL

int32
vos_restore(cstruct,server,partition,name,file=NULL,id=NULL,inter=Nullsv,overwrite=NULL,offline=Nullsv,readonly=Nullsv)
        AFS::VOS cstruct
        char *server
        char *partition
        char *name
        char *file
        char *id
        SV *  inter
        char *overwrite
        SV *  offline
        SV *  readonly
    PREINIT:
        afs_int32 avolid, aparentid, aserver, apart, code, vcode, err;
        afs_int32 aoverwrite = AFS_ASK;
        int restoreflags, voltype = RWVOL, ireadonly = 0, ioffline = 0;
        char afilename[NameLen], avolname[VOLSER_MAXVOLNAME +1];
        char volname[VOLSER_MAXVOLNAME +1];
        struct nvldbentry entry;
    CODE:
    {
        aparentid = 0;
        if (!inter) {
            inter = newSViv(0);
        }
        if (!offline) {
            offline = newSViv(0);
        }
        if (!readonly) {
            readonly = newSViv(0);
        }
        if ((!SvIOKp(inter))) {
            char buffer[256];
            sprintf(buffer, "Flag \"inter\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            aoverwrite = AFS_ASK;
        if ((!SvIOKp(offline))) {
            char buffer[256];
            sprintf(buffer, "Flag \"offline\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            ioffline = SvIV(offline);
        if ((!SvIOKp(readonly))) {
            char buffer[256];
            sprintf(buffer, "Flag \"readonly\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            ireadonly = SvIV(readonly);

        if (id && strlen(id) != 0) {
            avolid = vsu_GetVolumeID(id, cstruct, &err);
            if (avolid == 0) {
                char buffer[256];
                if (err)
                    set_errbuff(buffer, err);
                else
                    sprintf(buffer, "AFS::VOS: can't find volume '%s'\n", id);
                VSETCODE(err ? err : -1, buffer);
                RETVAL = 0;
                goto done;
            }
        }
        else
            avolid = 0;

        if (overwrite && strlen(overwrite) != 0) {

src/AFS.xs  view on Meta::CPAN

            sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            RETVAL = 0;
            goto done;
        }
        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);
            RETVAL = 0;
            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::VOS: partition %s does not exist on the server\n",
                        partition);
            VSETCODE(code ? code : -1, buffer);
            RETVAL = 0;
            goto done;
        }
        strcpy(avolname, name);
        if (!ISNAMEVALID(avolname)) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: the name of the volume %s exceeds the size limit\n",
                    avolname);
            VSETCODE(-1, buffer);
            RETVAL = 0;
            goto done;
        }
        if (!VolNameOK(avolname)) {
            char buffer[256];
            sprintf(buffer, "Illegal volume name %s, should not end in .readonly or .backup\n",
                    avolname);
            VSETCODE(-1, buffer);
            RETVAL = 0;
            goto done;
        }
        if (file && strlen(file) != 0) {
            strcpy(afilename, file);
            if (!FileExists(afilename)) {
                char buffer[256];
                sprintf(buffer, "Can't access file %s\n", afilename);
                VSETCODE(-1, buffer);
                RETVAL = 0;
                goto done;
            }
        }
        else {
            strcpy(afilename, "");
        }

                /* Check if volume exists or not */

        vsu_ExtractName(volname, avolname);
        vcode = VLDB_GetEntryByName(volname, &entry);
        if (vcode) {                    /* no volume - do a full restore */
            restoreflags = RV_FULLRST;
            if ((aoverwrite == AFS_INC) || (aoverwrite == AFS_ABORT)) {
                char buffer[256];
                sprintf(buffer, "Volume does not exist; Will perform a full restore\n");
                VSETCODE(vcode, buffer);
            }
        }
        else if ((!ireadonly && Lp_GetRwIndex(&entry) == -1)     /* RW volume does not exist - do a full */
                 ||(ireadonly && !Lp_ROMatch(0, 0, &entry))) {   /* RO volume does not exist - do a full */
            restoreflags = RV_FULLRST;
            if ((aoverwrite == AFS_INC) || (aoverwrite == AFS_ABORT))
                fprintf(stderr, "%s Volume does not exist; Will perform a full restore\n",
                        ireadonly ? "RO" : "RW");

            if (avolid == 0) {
                avolid = entry.volumeId[voltype];
            }
            else if (entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) {
                avolid = entry.volumeId[voltype];
            }
            aparentid = entry.volumeId[RWVOL];
        }
        else {                 /* volume exists - do we do a full incremental or abort */
            int Oserver, Opart, Otype, vol_elsewhere = 0;
            struct nvldbentry Oentry;
            int c, dc;

            if (avolid == 0) {
                avolid = entry.volumeId[voltype];
            }
            else if (entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) {
                avolid = entry.volumeId[voltype];
            }
            aparentid = entry.volumeId[RWVOL];

            /* A file name was specified  - check if volume is on another partition */
            vcode = GetVolumeInfo(avolid, &Oserver, &Opart, &Otype, &Oentry);
            if (vcode) {
                SETCODE(0);
                RETVAL = 0;
                goto done;
            }

            vcode = VLDB_IsSameAddrs(Oserver, aserver, &err);
            if (err) {
                char buffer[256];
                sprintf(buffer,
                        "Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
                        Oserver, err);
                VSETCODE(err, buffer);
                RETVAL = 0;
                goto done;
            }
            if (!vcode || (Opart != apart))
                vol_elsewhere = 1;

            if (aoverwrite == AFS_ASK) {
                if (strcmp(afilename, "") == 0) {       /* The file is from standard in */
                    char buffer[256];
                    sprintf(buffer,
                            "Volume exists and no OVERWRITE argument specified; Aborting restore command\n");
                    VSETCODE(-1, buffer);
                    RETVAL = 0;
                    goto done;
                }

                /* Ask what to do */
                if (vol_elsewhere) {
                    char buffer[256];
                    sprintf(buffer,
                            "The volume %s %u already exists on a different server/part\n",
                            volname, entry.volumeId[voltype]);
                    VSETCODE(-1, buffer);
                    fprintf(stderr, "Do you want to do a full restore or abort? [fa](a): ");
                }
                else {
                    char buffer[256];
                    sprintf(buffer, "The volume %s %u already exists in the VLDB\n",
                            volname, entry.volumeId[voltype]);
                    VSETCODE(-1, buffer);
                    fprintf(stderr,
                            "Do you want to do a full/incremental restore or abort? [fia](a): ");
                }
                dc = c = getchar();
                while (!(dc == EOF || dc == '\n'))
                    dc = getchar();     /* goto end of line */
                if ((c == 'f') || (c == 'F'))
                    aoverwrite = AFS_FULL;
                else if ((c == 'i') || (c == 'I'))
                    aoverwrite = AFS_INC;
                else
                    aoverwrite = AFS_ABORT;
            }

            if (aoverwrite == AFS_ABORT) {
                char buffer[256];
                sprintf(buffer, "Volume exists; Aborting restore command\n");
                VSETCODE(-1, buffer);
                RETVAL = 0;
                goto done;
            }
            else if (aoverwrite == AFS_FULL) {
                restoreflags = RV_FULLRST;
                fprintf(stderr, "Volume exists; Will delete and perform full restore\n");
            }
            else if (aoverwrite == AFS_INC) {
                restoreflags = 0;
                if (vol_elsewhere) {
                    char buffer[256];
                    sprintf(buffer,
                            "%s volume %u already exists on a different server/part; not allowed\n",
                            ireadonly ? "RO" : "RW", avolid);
                    VSETCODE(-1, buffer);
                    RETVAL = 0;
                    goto done;
                }
            }
        }

        if ((ioffline))
            restoreflags |= RV_OFFLINE;
        if (ireadonly)
            restoreflags |= RV_RDONLY;

        /* restoreflags |= RV_CRNEW; */
        /* restoreflags |= RV_LUDUMP; */
#ifdef OpenAFS_1_4_05
        code = UV_RestoreVolume2(aserver, apart, avolid, aparentid, avolname,
                                 restoreflags, WriteData, afilename);
#else
        code = UV_RestoreVolume(aserver, apart, avolid, avolname,
                                restoreflags, WriteData, afilename);
#endif
        if (code) {
            PrintDiagnostics("restore", code);
            SETCODE(code);
            RETVAL = 0;
            goto done;
        }

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vos_dump(cstruct, id, time=NULL, file=NULL, server=NULL, partition=NULL, clone=Nullsv, omit=Nullsv)
        AFS::VOS cstruct
        char *id
        char *time
        char *file
        char *server
        char *partition
        SV *  clone
        SV *  omit
    PREINIT:
        afs_int32 avolid, aserver, apart, voltype, fromdate=0, code=0, err, i;
        char filename[NameLen];
        struct nvldbentry entry;
        afs_int32 omitdirs = 0;
    CODE:
    {
        if (!clone)
            clone = newSViv(0);
        if (!omit)
            omit = newSViv(0);
        if ((!SvIOKp(omit))) {
            char buffer[256];
            sprintf(buffer, "Flag \"omit\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            omitdirs = SvIV(omit);     /* -omit */
        /* printf("vos_dump DEBUG-1 clone = %d omit = %d omitdirs = %d \n", clone, omit, omitdirs); */
        RETVAL = 0;
        rx_SetRxDeadTime(60 * 10);
        for (i = 0; i < MAXSERVERS; i++) {
            struct rx_connection *rxConn = ubik_GetRPCConn((struct ubik_client *) cstruct, i);
            if (rxConn == 0)
                break;
            rx_SetConnDeadTime(rxConn, rx_connDeadTime);
            if (rxConn->service)
                rxConn->service->connDeadTime = rx_connDeadTime;
        }

        avolid = vsu_GetVolumeID(id, cstruct, &err);

src/AFS.xs  view on Meta::CPAN

                    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];
                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("listvol", code);
                SETCODE(-1);
                XSRETURN_UNDEF;
            }
        }

        for (i = 0; i < cnt; i++) {
            if (dummyPartList.partFlags[i] & PARTVALID) {
                /*HV *part = (HV*)sv_2mortal((SV*)newHV()); */
                HV *part = newHV();
                if (wantExtendedInfo)
                    code = UV_XListVolumes(aserver,
                                           dummyPartList.partId[i], all, &xInfoP, &count);

src/AFS.xs  view on Meta::CPAN

            VSETCODE(code ? code : -1, buffer);
            goto done;
        }
        code = VLDB_GetEntryByID(volid, -1, &entry);
        if (!code) {
            if (volid == entry.volumeId[RWVOL])
                backupid = entry.volumeId[BACKVOL];
            #fprintf(stderr,
            #        "Warning: Entry for volume number %u exists in VLDB (but we're zapping it anyway!)\n",
            #        volid);
        }
        if (zapbackupid) {
            volintInfo *pntr = (volintInfo *) 0;

            if (!backupid) {
                code = UV_ListOneVolume(server, part, volid, &pntr);
                if (!code) {
                    if (volid == pntr->parentID)
                        backupid = pntr->backupID;
                    if (pntr)
                        free(pntr);
                }
            }
            if (backupid) {
                code = UV_VolumeZap(server, part, backupid);
                if (code) {
                    PrintDiagnostics("zap", code);
                    SETCODE(code);
                    goto done;
                }
                fprintf(STDOUT, "Backup Volume %u deleted\n", backupid);
            }
        }
        code = UV_VolumeZap(server, part, volid);
        if (code) {
            PrintDiagnostics("zap", code);
            SETCODE(code);
            goto done;
        }
        #fprintf(STDOUT, "Volume %u deleted\n", volid);
        SETCODE(0);
        RETVAL = volid;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vos_offline(cstruct, servername, parti, id, busy=Nullsv, sleep=Nullsv)
        AFS::VOS cstruct
        char* servername
        char* parti
        char *id
        SV *  busy
        SV *  sleep
    PREINIT:
        int32 server, partition, volid;
        int32 code, err=0;
        int32 ibusy=0, isleep=0, transflag, transdone;
    CODE:
    {
        if (!busy)
            busy = newSViv(0);
        if (!sleep)
            sleep = newSViv(0);
        if ((!SvIOKp(busy))) {
            char buffer[256];
            sprintf(buffer, "Flag \"busy\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            ibusy = SvIV(busy);         /* -busy */
        if ((!SvIOKp(sleep))) {
            char buffer[256];
            sprintf(buffer, "Flag \"sleep\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            isleep = SvIV(sleep);       /* -sleep */
        RETVAL = 0;
        server = GetServer(servername);
        if (server == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
            VSETCODE(-1, buffer);
            goto done;
        }

        partition = volutil_GetPartitionID(parti);
        if (partition < 0) {
            char buffer[256];
            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;
        }

        transflag = (ibusy ? ITBusy : ITOffline);
        transdone = (isleep ? 0 /*online */ : VTOutOfService);
        if (ibusy && !isleep) {
            char buffer[256];
            sprintf(buffer, "SLEEP argument must be used with BUSY flag\n");
            VSETCODE(-1, buffer);
            goto done;
        }

        code = UV_SetVolume(server, partition, volid, transflag, transdone, isleep);
        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

int32
vos_online(cstruct, servername, parti, id)
        AFS::VOS cstruct
        char* servername
        char* parti
        char *id
    PREINIT:
        int32 server, partition, volid;
        int32 code, err=0;
    CODE:
    {
        RETVAL = 0;
        server = GetServer(servername);
        if (server == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
            VSETCODE(-1, buffer);
            goto done;
        }

        partition = volutil_GetPartitionID(parti);
        if (partition < 0) {
            char buffer[256];
            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;

src/AFS.xs  view on Meta::CPAN

                        ccode = (char *) re_comp(itp);
                        if (ccode) {
                            char buffer[256];
                            sprintf(buffer,
                                    "Unrecognizable XPREFIX regular expression: '%s': %s\n", itp,
                                    ccode);
                            VSETCODE(ccode, buffer);
                            XSRETURN_UNDEF;
                        }
                    }
                }                       /*for */
            }
        }

        /* printf("vos-backupsys DEBUG-12\n"); */
        Zero(&arrayEntries, 1, nbulkentries);   /* initialize to hint the stub to alloc space */
        vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
        if (vcode) {
            VSETCODE(vcode, "Could not access the VLDB for attributes");
            XSRETURN_UNDEF;
        }

            /* a bunch of output generation code deleted. A.W. */

        /* printf("vos-backupsys DEBUG-13\n"); */
        for (j = 0; j < nentries; j++) {        /* process each vldb entry */
            vllist = &arrayEntries.nbulkentries_val[j];
            /* printf("vos-backupsys DEBUG-13-1 Name %s\n", vllist->name); */

            if (seenprefix) {
                av = (AV *) SvRV(seenprefix);
                len = av_len(av);
                /* printf("vos-backupsys DEBUG-14 Len %d\n", len); */
                for (i = 0; i <= len; i++) {
                    regex = *av_fetch(av, i, 0);
                    itp = SvPV_nolen(regex);
                    /* printf("vos-backupsys DEBUG-14-1 RE %s \n", itp); */
                    if (strncmp(itp, "^", 1) == 0) {
                        ccode = (char *) re_comp(itp);
                        if (ccode) {
                            char buffer[256];
                            sprintf(buffer, "Error in PREFIX regular expression: '%s': %s\n",
                                    itp, ccode);
                            VSETCODE(ccode, buffer);
                            XSRETURN_UNDEF;
                        }
                        match = (re_exec(vllist->name) == 1);
                    }
                    else {
                        match = (strncmp(vllist->name, itp, strlen(itp)) == 0);
                    }
                    if (match)
                        break;
                }
            }
            else {
                match = 1;
                /* printf("vos-backupsys DEBUG-15 MATCH %d\n", match); */
            }

            /* Without the -exclude flag: If it matches the prefix, then
             *    check if we want to exclude any from xprefix.
             * With the -exclude flag: If it matches the prefix, then
             *    check if we want to add any from xprefix.
             */
            if (match && seenxprefix) {
                av = (AV *) SvRV(seenxprefix);
                len = av_len(av);
                for (i = 0; i <= len; i++) {
                    regex = *av_fetch(av, i, 0);
                    itp = SvPV_nolen(regex);
                    if (strncmp(itp, "^", 1) == 0) {
                        ccode = (char *) re_comp(itp);
                        if (ccode) {
                            char buffer[256];
                            sprintf(buffer, "Error in PREFIX regular expression: '%s': %s\n",
                                    itp, ccode);
                            VSETCODE(ccode, buffer);
                            XSRETURN_UNDEF;
                        }
                        if (re_exec(vllist->name) == 1) {
                            match = 0;
                            break;
                        }
                    }
                    else {
                        if (strncmp(vllist->name, itp, strlen(itp)) == 0) {
                            match = 0;
                            break;
                        }
                    }
                }
            }

            /* printf("vos-backupsys DEBUG-16-1: exclude %d match %d\n", iexclude, match); */
            if (iexclude)
                match = !match;         /* -exclude will reverse the match */
            if (!match)
                continue;               /* Skip if no match */

            /* printf("vos-backupsys DEBUG-16-2: noaction %d match %d\n", inoaction, match); */
            /* Print list of volumes to backup */
            if (inoaction) {
                av_push(av1, newSVpv(vllist->name, strlen(vllist->name)));
                continue;
            }

            /* printf("vos-backupsys DEBUG-17\n"); */
            if (!(vllist->flags & RW_EXISTS)) {
                if (verbose) {
                    fprintf(STDOUT, "Omitting to backup %s since RW volume does not exist \n",
                            vllist->name);
                    fprintf(STDOUT, "\n");
                }
                fflush(STDOUT);
                continue;
            }

            /* printf("vos-backupsys DEBUG-18\n"); */
            avolid = vllist->volumeId[RWVOL];
            MapHostToNetwork(vllist);
            GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
            if (aserver1 == -1 || apart1 == -1) {
                av_push(av2, newSVpv(vllist->name, strlen(vllist->name)));
                fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n", vllist->name);
                totalFail++;
                continue;
            }
            /* 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); */

src/AFS.xs  view on Meta::CPAN

        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

src/AFS.xs  view on Meta::CPAN

             * 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 */
        /* printf("DEBUG-8 \n"); */
        if (parti) {
            /* printf("DEBUG-9 \n"); */
            apart = volutil_GetPartitionID(parti);
            if (apart < 0) {
                char buffer[256];
                sprintf(buffer, "AFS::VLDB: could not interpret partition name '%s'\n", parti);
                VSETCODE(-1, buffer);
                XSRETURN_UNDEF;
            }
            attributes.partition = apart;
            attributes.Mask |= VLLIST_PARTITION;
        }

        /* printf("DEBUG-10 \n"); */
        if (lock) {
            /* printf("DEBUG-11 \n"); */
            attributes.Mask |= VLLIST_FLAG;
            attributes.flag = VLOP_ALLOPERS;
        }

        /* printf("DEBUG-12 \n"); */
        for (thisindex = 0; (thisindex != -1); thisindex = nextindex) {
             /* printf("DEBUG-13 \n"); */
            /* memset(&arrayEntries, 0, sizeof(arrayEntries)); */
            /* 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;

src/AFS.xs  view on Meta::CPAN

        ;
    }
    OUTPUT:
        RETVAL

int32
vldb_unlockvldb(cstruct, server=NULL, partition=NULL)
        AFS::VLDB cstruct
        char *server
        char *partition
    PREINIT:
        afs_int32 apart = -1;
        afs_int32 aserver = 0,code;
        afs_int32 vcode;
        struct VldbListByAttributes attributes;
        nbulkentries arrayEntries;
        register struct nvldbentry *vllist;
        afs_int32 nentries;
        int j;
        afs_int32 volid;
        afs_int32 totalE = 0;
    CODE:
    {
        RETVAL = 0;
        attributes.Mask = 0;

        if (server && (strlen(server) != 0)) {  /* server specified */
            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;
            }
            attributes.server = ntohl(aserver);
            attributes.Mask |= VLLIST_SERVER;
        }

        if (partition && (strlen(partition) != 0)) {    /* partition specified */
            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;
            }
            attributes.partition = apart;
            attributes.Mask |= VLLIST_PARTITION;
        }
        attributes.flag = VLOP_ALLOPERS;
        attributes.Mask |= VLLIST_FLAG;
        Zero(&arrayEntries, 1, nbulkentries);   /*initialize to hint the stub  to alloc space */
        vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
        if (vcode) {
            char buffer[256];
            sprintf(buffer, "Could not access the VLDB for attributes\n");
            VSETCODE(vcode, buffer);
            goto done;
        }
        for (j = 0; j < nentries; j++) {        /* process each entry */
            vllist = &arrayEntries.nbulkentries_val[j];
            volid = vllist->volumeId[RWVOL];
            vcode =
                ubik_Call(VL_ReleaseLock, cstruct, 0, volid, -1,
                          LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
            if (vcode) {
                char buffer[256];
                sprintf(buffer, "Could not unlock entry for volume %s\n", vllist->name);
                VSETCODE(vcode, buffer);
                totalE++;
            }

        }

        if (totalE)
            fprintf(STDOUT, "Could not unlock %u VLDB entries of %u locked entries\n", totalE,
                nentries);

        if (arrayEntries.nbulkentries_val)
            free(arrayEntries.nbulkentries_val);

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vldb__syncvldb(cstruct, server=NULL, partition=NULL, volname=NULL)
        AFS::VLDB cstruct
        char *server
        char *partition
        char *volname
    PREINIT:
        afs_int32 pname = 0, code;        /* part name */
        int flags = 0;
        afs_int32 tserver = 0;
    CODE:
    {
        RETVAL = 0;
        /* printf("server %s, part %s volume %s \n", server, partition, volname); */
        if (server && (strlen(server) != 0)) {
            tserver = GetServer(server);
            if (!tserver) {
                char buffer[256];
                sprintf(buffer, "AFS::VLDB: host '%s' not found in host table\n", server);
                VSETCODE(-1, buffer);
                goto done;
            }
        }

        if (partition && (strlen(partition) != 0)) {
            pname = volutil_GetPartitionID(partition);
            if (pname < 0) {
                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);
            goto done;
        }
        code = UV_RemoveSite(aserver, apart, avolid);
        printf("\n");
        if (code) {
            PrintDiagnostics("remsite", code);
            SETCODE(code);
            goto done;
        }
        RETVAL = 1;
        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vldb_syncserv(cstruct, servername, parti=NULL)
        AFS::VLDB cstruct
        char *servername
        char *parti
    PREINIT:
        afs_int32 pname = 0, code;       /* part name */
        afs_int32 tserver;
        int flags = 0;
    CODE:
    {
        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

src/AFS.xs  view on Meta::CPAN

            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;
                }
                safe_hv_store(status, ibuffer, strlen(ibuffer), newRV_inc((SV *) (stats)), 0);
            }
        }

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

        done:
        ;
  }

int32
bos_setauth(self, tp)
        AFS::BOS self
        char *tp
    PREINIT:
        int32 code = 0;
        int32 flag;
    CODE: 
    {
        not_here("AFS::BOS::setauth");

        RETVAL = 42;
        if (strcmp(tp, "on") == 0)
            flag = 0;                   /* auth req.: noauthflag is false */
        else if (strcmp(tp, "off") == 0)
            flag = 1;
        else {
            char buffer[256];
            sprintf(buffer,
                    "AFS::BOS: illegal authentication specifier '%s', must be 'off' or 'on'.\n",
                    tp);
            BSETCODE(-1, buffer);
            RETVAL = 0;
        }

        if (RETVAL == 42) {
            code = BOZO_SetNoAuthFlag(self, flag);
            if (code) {
                char buffer[256];
                sprintf(buffer, "AFS::BOS %d (failed to set authentication flag)", code);
                BSETCODE(code, buffer);
            }
            SETCODE(code);
            RETVAL = (code == 0);
        }
    }
    OUTPUT:
        RETVAL

int32
bos_exec(self, cmd)
        AFS::BOS self
        char *cmd
    PREINIT:
        int32 code = 0;
    CODE:
    {
        code = BOZO_Exec(self, cmd);
        if (code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: failed to execute command (%s)\n", em(code));
            BSETCODE(code, buffer);
        }
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
bos_addhost(self, object, clone=Nullsv)
        AFS::BOS self
        SV* object
        SV *  clone
    PREINIT:
        int32 code = 0;
            int len, i;
            AV *av;
            SV *sv;
            char *host;
            int iclone;
            STRLEN namelen;
    CODE:
    {

        if (!clone) {
            clone = newSViv(0);
        }
        if (!SvIOKp(clone)) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: Flag \"clone\" should be numeric.\n");
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }
        iclone = SvIV(clone);

        RETVAL = 0;
        if (!SvROK(object)) {
            av = newAV();
            av_push(av,object);

src/AFS.xs  view on Meta::CPAN

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
bos_removehost(self, object)
        AFS::BOS self
        SV* object
    PREINIT:
        int32 code = 0;
        char *host;
        int len, i;
        AV *av;
        SV *sv;
    CODE:
    {
        if (!SvROK(object)) {
            av = newAV();
            av_push(av,object);
        }
        else if (SvTYPE(SvRV(object)) == SVt_PVAV) {
            av = (AV *) SvRV(object);
        }
        else {
            BSETCODE(-1, "AFS::BOS: HOST not an array reference\n");
            XSRETURN_UNDEF;
        }

        len = av_len(av);
        if (len != -1) {
            for (i = 0; i <= len; i++) {
                sv = *av_fetch(av, i, 0);
                if (sv && !SvROK(sv)) {
                    host = SvPV_nolen(sv);
                    code = BOZO_DeleteCellHost(self, host);
                    if (code) {
                        char buffer[240];
                        sprintf(buffer, "AFS::BOS: failed to delete host '%s' (%s)\n", host,
                                em(code));
                        BSETCODE(code, buffer);
                    }
                }
            }                       /* for loop */
        }
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
bos_prune(self, all=0, bak=0, old=0, core=0)
        AFS::BOS self
        int all
        int bak
        int old
        int core
    PREINIT:
        int32 code = 0, flags = 0;
    CODE: 
    {
        if (bak)
            flags |= BOZO_PRUNEBAK;
        if (old)
            flags |= BOZO_PRUNEOLD;
        if (core)
            flags |= BOZO_PRUNECORE;
        if (all)
            flags |= 0xff;

        if (!flags) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS nothing to prune");
            BSETCODE(999, buffer);
            RETVAL = 0;
        }
        else {
            code = BOZO_Prune(self, flags);
            if (code) {
              char buffer[256];
              sprintf(buffer, "AFS::BOS has failed to prune server files");
              BSETCODE(code, buffer);
            }
            SETCODE(code);
            RETVAL = (code == 0);
        }
    }
    OUTPUT:
        RETVAL

int32
bos_adduser(self, object)
        AFS::BOS self
        SV * object
    PREINIT:
        int32 code = 0;
        char *name;
        int len, i;
        AV *av;
        SV *sv;
    CODE:
    {
        if (!SvROK(object)) {
            av = newAV();
            av_push(av,object);
        }
        else if (SvTYPE(SvRV(object)) == SVt_PVAV) {
            av = (AV *) SvRV(object);
        }
        else {
            BSETCODE(-1, "AFS::BOS: USER not an array reference\n");
            XSRETURN_UNDEF;
        }

        len = av_len(av);
        if (len != -1) {
            for (i = 0; i <= len; i++) {
                sv = *av_fetch(av, i, 0);
                if (sv && !SvROK(sv)) {
                    name = SvPV_nolen(sv);
                    code = BOZO_AddSUser(self, name);
                    if (code) {
                        char buffer[240];
                        sprintf(buffer, "AFS::BOS: failed to add user '%s' (%s)\n", name,
                                em(code));
                        BSETCODE(code, buffer);
                    }
                }
            }                       /* for loop */
        }
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
bos_removeuser(self, object)

src/AFS.xs  view on Meta::CPAN

        int32 blockreads
        int32 ListResidencies
        int32 SalvageRemote
        int32 SalvageArchival
        int32 IgnoreCheck
        int32 ForceOnLine
        int32 UseRootDirACL
        int32 TraceBadLinkCounts
        int32 DontAskFS
        int32 LogLevel
        int32 rxdebug
        int32 Residencies
    PREINIT:
        afs_int32 code = 0, rc;
        char tname[BOZO_BSSIZE];
        afs_int32 newID;
        extern struct ubik_client *cstruct;
        afs_int32 curGoal, mrafs = 0;
        char *tp;
    CODE:
    {
        not_here("AFS::BOS::salvage");

        if (partition && strlen(partition) == 0)
            partition = NULL;
        if (volume && strlen(volume) == 0)
            volume = NULL;
        if (outName && strlen(outName) == 0)
            outName = NULL;
        if (parallel && strlen(parallel) == 0)
            parallel = NULL;
        if (tmpDir && strlen(tmpDir) == 0)
            tmpDir = NULL;
        if (orphans && strlen(orphans) == 0)
            orphans = NULL;

        Zero(&mrafsParm, 1, mrafsParm);

            /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
            /* XXX this should really be done some other way, potentially by RPC */
        tp = (char *) &tname;
        if ((code = BOZO_GetInstanceParm(self, "fs", 3, &tp) == 0))
            mrafs = 1;

            /* we can do a volume, a partition or the whole thing, but not mixtures
             * thereof */
        if (!partition && volume) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: must specify partition to salvage individual volume.\n");
            BSETCODE(-1, buffer);
            goto done;
        }
        if (showlog && outName) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: can not specify both -file and -showlog.\n");
            BSETCODE(-1, buffer);
            goto done;
        }
        if (all && (partition || volume)) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: can not specify ALL with other flags.\n");
            BSETCODE(-1, buffer);
            goto done;
        }

        if (orphans && mrafs) {
            char buffer[256];
            sprintf(buffer, "Can't specify -orphans for MR-AFS fileserver\n");
            BSETCODE(EINVAL, buffer);
            goto done;
        }

        if (mrafs) {
            if (debug)
                mrafsParm.Optdebug = 1;
            if (nowrite)
                mrafsParm.Optnowrite = 1;
            if (force)
                mrafsParm.Optforce = 1;
            if (oktozap)
                mrafsParm.Optoktozap = 1;
            if (rootfiles)
                mrafsParm.Optrootfiles = 1;
            if (salvagedirs)
                mrafsParm.Optsalvagedirs = 1;
            if (blockreads)
                mrafsParm.Optblockreads = 1;
            if (ListResidencies)
                mrafsParm.OptListResidencies = 1;
            if (SalvageRemote)
                mrafsParm.OptSalvageRemote = 1;
            if (SalvageArchival)
                mrafsParm.OptSalvageArchival = 1;
            if (IgnoreCheck)
                mrafsParm.OptIgnoreCheck = 1;
            if (ForceOnLine)
                mrafsParm.OptForceOnLine = 1;
            if (UseRootDirACL)
                mrafsParm.OptUseRootDirACL = 1;
            if (TraceBadLinkCounts)
                mrafsParm.OptTraceBadLinkCounts = 1;
            if (DontAskFS)
                mrafsParm.OptDontAskFS = 1;
            if (LogLevel)
                mrafsParm.OptLogLevel = LogLevel;
            if (rxdebug)
                mrafsParm.OptRxDebug = 1;
            if (Residencies) {
                if (SalvageRemote || SalvageArchival) {
                    char buffer[256];
                    sprintf(buffer,
                            "Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
                    BSETCODE(EINVAL, buffer);
                    goto done;
                }
/* muss naeher ueberprueft werden !!!  */
/* #if defined(OpenAFS_1_2) */
/*                 code = GetUInt32(Residencies, &mrafsParm.OptResidencies); */
/* #else */
/* #if defined(OpenAFS_1_3) || defined(OpenAFS_1_4) || defined(OpenAFS_1_5) */
/*                 code = util_GetUInt32(Residencies, &mrafsParm.OptResidencies); */

src/AFS.xs  view on Meta::CPAN

                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);

src/AFS.xs  view on Meta::CPAN

        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)));
            }

src/AFS.xs  view on Meta::CPAN

        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);

src/AFS.xs  view on Meta::CPAN

#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)

src/AFS.xs  view on Meta::CPAN

            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);

src/AFS.xs  view on Meta::CPAN

        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;
                }



( run in 0.659 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )