AFS

 view release on metacpan or  search on metacpan

src/AFS.xs  view on Meta::CPAN

#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>
#include <afs/ktime.h>
#if defined(AFS_OLD_COM_ERR)
#include <com_err.h>
#else
#include <afs/com_err.h>
#endif
#include <des.h>

#if defined(AFS_3_4) || defined(AFS_3_5)
#else
#define int32 afs_int32
#define uint32 afs_uint32
#endif

const char *const xs_version = "AFS.xs (Version 2.6.4)";

/* here because it seemed too painful to #define KERNEL before #inc afs.h */
struct VenusFid {
    int32 Cell;
    struct AFSFid Fid;
};

/* tpf nog 03/29/99 */
/* the following was added by leg@andrew, 10/9/96 */
/*#ifdef __hpux*//* only on hp700_ux90 systems */
#if defined(__hpux) || defined(_AIX) || defined(sun) || defined(__sun__) || defined(__sgi) || defined(__linux)
static int32 name_is_numeric(char *);
#endif

typedef SV *AFS__ACL;
typedef struct ktc_principal *AFS__KTC_PRINCIPAL;
typedef struct ktc_token *AFS__KTC_TOKEN;
typedef struct ktc_encryptionKey *AFS__KTC_EKEY;
typedef struct ubik_client *AFS__KAS;
typedef struct ubik_client *AFS__PTS;
typedef struct ubik_client *AFS__VLDB;
typedef struct ubik_client *AFS__VOS;
typedef struct rx_connection *AFS__BOS;

extern struct ubik_client *cstruct;
#include "afs_prototypes.h"
extern int afs_setpag();

static rxkad_level vsu_rxkad_level = rxkad_clear;
static struct ktc_token the_null_token;
static int32 convert_numeric_names = 1;
static int32 rx_initialized = 0;

#define MAXSIZE 2048
#define MAXINSIZE 1300

#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif

#define AFS_ASK   0
#define AFS_ABORT 1
#define AFS_FULL  2
#define AFS_INC   3

#ifdef AFS_PTHREAD_ENV
#undef clock_haveCurrentTime
#undef clock_UpdateTime
struct clock clock_now;
#endif /* AFS_PTHREAD_ENV*/

/* error handling macros */

#define ERROR_EXIT(code) {error=(code); goto error_exit;}

#define SETCODE(code) set_code(code)
#define BSETCODE(code, msg) bv_set_code(code, msg)
#define VSETCODE(code, msg) bv_set_code(code, msg)
#define KSETCODE(code, msg) k_set_code(code, msg)
#define PSETCODE(msg) p_set_code(msg)

static int32 raise_exception = 0;

void safe_hv_store (HV* ahv,char * key ,int i ,SV * asv,int j) {
   if (! hv_store(ahv, key, i, asv, j)) {
       fprintf(stderr,"Panic ... internal error. hv_store failed.\n");
       exit(1);
   }
   return;
}

static void bv_set_code(code, msg)
    int32 code;
    const char *msg;
{
    SV *sv = get_sv("AFS::CODE", TRUE);
    sv_setiv(sv, (IV) code);
/*   printf("BV_SET_CODE %s (%d)\n", msg, code); */
    if (code == 0) {
        sv_setpv(sv, "");
    }
    else {
        if (raise_exception) {
            char buffer[1024];
            sprintf(buffer, "AFS exception: %s (%d)", msg, code);
            croak(buffer);
        }
/*      printf("BV_SET_CODE %s (%d)\n", msg, code); */
        sv_setpv(sv, (char *) msg);
    }
    SvIOK_on(sv);
}

static void p_set_code(msg)
    const char *msg;
{
    int32 code = errno;
    SV *sv = get_sv("AFS::CODE", TRUE);
    sv_setiv(sv, (IV) code);
/*   printf("P_SET_CODE %s (%d)\n", msg, code); */
    if (code == 0) {
        sv_setpv(sv, "");
    }
    else {
        char buffer[1024];
        if (raise_exception) {
            sprintf(buffer, "AFS exception: %s (%s) (%d)", msg, error_message(code), code);
            croak(buffer);
        }
/*      printf("P_SET_CODE %s (%d)\n", msg, code); */
        sprintf(buffer, "%s: %s (%d)", msg, error_message(code), code);
        sv_setpv(sv, buffer);
    }
    SvIOK_on(sv);
}

static void k_set_code(code, msg)
    int32 code;
    const char *msg;
{
    SV *sv = get_sv("AFS::CODE", TRUE);
    sv_setiv(sv, (IV) code);
/*   printf("K_SET_CODE %s (%d)\n", msg, code); */
    if (code == 0) {
        sv_setpv(sv, "");
    }
    else {
        char buffer[1024];
        if (raise_exception) {
            sprintf(buffer, "AFS exception: %s (%s) (%d)", msg, error_message(code), code);
            croak(buffer);
        }
/*      printf("K_SET_CODE %s (%d)\n", msg, code); */
        sprintf(buffer, "%s: %s (%d)", msg, error_message(code), code);
        sv_setpv(sv, buffer);
    }
    SvIOK_on(sv);
}

static void set_code(code)
    int32 code;
{
    SV *sv = get_sv("AFS::CODE", TRUE);
    if (code == -1) { code = errno; }
/*     printf("SET_CODE %d\n", code); */
    sv_setiv(sv, (IV) code);
    if (code == 0) {
        sv_setpv(sv, "");
    }
    else {
        if (raise_exception) {
            char buffer[1024];
            sprintf(buffer, "AFS exception: %s (%d)", error_message(code), code);
            croak(buffer);
        }
        sv_setpv(sv, (char *) error_message(code));
    }
    SvIOK_on(sv);
}

/* taken from openafs-1.2.9  */
/* volser/vsprocs.c          */
int set_errbuff(buffer, errcode)
    char *buffer;
    int32 errcode;
{
    /*replace by a big switch statement */
    switch (errcode) {
      case 0:
          break;
      case -1:
          sprintf(buffer, "Possible communication failure\n");
          break;
      case VSALVAGE:
          sprintf(buffer, "Volume needs to be salvaged\n");
          break;
      case VNOVNODE:
          sprintf(buffer, "Bad vnode number quoted\n");
          break;
      case VNOVOL:
          sprintf(buffer, "Volume not attached, does not exist, or not on line\n");
          break;
      case VVOLEXISTS:
          sprintf(buffer, "Volume already exists\n");
          break;
      case VNOSERVICE:
          sprintf(buffer, "Volume is not in service\n");
          break;
      case VOFFLINE:
          sprintf(buffer, "Volume is off line\n");
          break;
      case VONLINE:
          sprintf(buffer, "Volume is already on line\n");
          break;
      case VDISKFULL:
          sprintf(buffer, "Partition is full\n");
          break;
      case VOVERQUOTA:
          sprintf(buffer, "Volume max quota exceeded\n");
          break;
      case VBUSY:
          sprintf(buffer, "Volume temporarily unavailable\n");
          break;
      case VMOVED:
          sprintf(buffer, "Volume has moved to another server\n");
          break;
      case VL_IDEXIST:
          sprintf(buffer, "VLDB: volume Id exists in the vldb\n");
          break;
      case VL_IO:
          sprintf(buffer, "VLDB: a read terminated too early\n");
          break;
      case VL_NAMEEXIST:
          sprintf(buffer, "VLDB: volume entry exists in the vldb\n");
          break;
      case VL_CREATEFAIL:

src/AFS.xs  view on Meta::CPAN

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

#ifdef AFS_PTHREAD_ENV
void IOMGR_Sleep (seconds)
  int seconds;
{
    double i,j;

    croak("DEBUG: IOMGR_Sleep not available ...\nPlease inform the author...");
    j = 0.0;
    i = 1.0/j;
}

void clock_UpdateTime ()
{
    double i,j;

    croak("DEBUG: clock_UpdateTime not available ...\nPlease inform the author..  .");
    j = 0.0;
    i = 1.0/j;
}

int clock_haveCurrentTime ()
{
    double i,j;

    croak("DEBUG: clock_haveCurrentTime not available...\nPlease inform the auth or...");
    j = 0.0;
    i = 1.0/j;
    return 1;
}
#endif /* AFS_PTHREAD_ENV*/

static int32 not_here(s)
    char *s;
{
    croak("%s not implemented on this architecture or under this AFS version", s);
    return -1;
}

int PrintDiagnostics(astring, acode)
    char *astring;
    afs_int32 acode;
{
    if (acode == EACCES) {
        fprintf(STDERR, "You are not authorized to perform the 'vos %s' command (%d)\n",
                astring, acode);
    }
    else {
        fprintf(STDERR, "Error in vos %s command.\n", astring);
        PrintError("", acode);
    }
    return 0;
}
/* end of error handling macros */


/* general helper functions */

static struct afsconf_dir *cdir = NULL;
static char *config_dir = NULL;

static int32 internal_GetConfigDir()
{
    if (cdir == NULL) {

        if (config_dir == NULL) {
#if defined(AFS_3_4)
            config_dir = (char *) safemalloc(strlen(AFSCONF_CLIENTNAME) + 1);
            strcpy(config_dir, AFSCONF_CLIENTNAME);
#else
            config_dir = (char *) safemalloc(strlen(AFSDIR_CLIENT_ETC_DIRPATH) + 1);
            strcpy(config_dir, AFSDIR_CLIENT_ETC_DIRPATH);
#endif
        }

        cdir = afsconf_Open(config_dir);
        if (!cdir) {
            char buffer[256];
            sprintf(buffer, "GetConfigDir: Can't open configuration directory (%s)", config_dir);
            PSETCODE(buffer);
            return errno;
        }
    }
    return 0;
}

static int32 internal_GetServerConfigDir()
{
    if (cdir == NULL) {

        if (config_dir == NULL) {
#if defined(AFS_3_4)
            config_dir = (char *) safemalloc(strlen(AFSCONF_SERVERNAME) + 1);
            strcpy(config_dir, AFSCONF_SERVERNAME);
#else
            config_dir = (char *) safemalloc(strlen(AFSDIR_SERVER_ETC_DIRPATH) + 1);
            strcpy(config_dir, AFSDIR_SERVER_ETC_DIRPATH);
#endif
        }

        cdir = afsconf_Open(config_dir);
        if (!cdir) {
            char buffer[256];
            sprintf(buffer, "GetServerConfigDir: Can't open configuration directory (%s)", config_dir);
            PSETCODE(buffer);
            return errno;
        }
    }
    return 0;
}

static int32 internal_GetCellInfo(cell, service, info)
    char *cell;
    char *service;

src/AFS.xs  view on Meta::CPAN



    success = 0;
    *code = 0;

    *code = UV_ListPartitions(server, &dummyPartList, &cnt);
    if (*code)
        return success;
    for (i = 0; i < cnt; i++) {
        if (dummyPartList.partFlags[i] & PARTVALID)
            if (dummyPartList.partId[i] == partId)
                success = 1;
    }
    return success;
}

afs_int32 GetServer(aname)
    char *aname;
{
    register struct hostent *th;
    afs_int32 addr;
    int b1, b2, b3, b4;
    register afs_int32 code;
    char hostname[MAXHOSTCHARS];

    code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
    if (code == 4) {
        addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
        addr = ntohl(addr);     /* convert to host order */
    }
    else {
        th = gethostbyname(aname);
        if (!th)
            return 0;
        /* memcpy(&addr, th->h_addr, sizeof(addr)); */
        Copy(th->h_addr, &addr, th->h_length, char);
    }

    if (addr == htonl(0x7f000001)) {    /* local host */
        code = gethostname(hostname, MAXHOSTCHARS);
        if (code)
            return 0;
        th = gethostbyname(hostname);   /* returns host byte order */
        if (!th)
            return 0;
        /* memcpy(&addr, th->h_addr, sizeof(addr)); */
        Copy(th->h_addr, &addr, th->h_length, char);
    }

    return (addr);
}

 /*sends the contents of file associated with <fd> and <blksize>  to Rx Stream 
    * associated  with <call> */
int SendFile(ufd, call, blksize)
    usd_handle_t ufd;
    register struct rx_call *call;
    long blksize;
{
    char *buffer = (char *) 0;
    afs_int32 error = 0;
    int done = 0;
    afs_uint32 nbytes;

    buffer = (char *) safemalloc(blksize);
    if (!buffer) {
        char buf[256];
        sprintf(buf, "malloc failed\n");
        VSETCODE(-1, buf);
        return -1;
    }

    while (!error && !done) {
#ifndef AFS_NT40_ENV            /* NT csn't select on non-socket fd's */
        fd_set in;
        FD_ZERO(&in);
        FD_SET((long) (ufd->handle), &in);
        /* don't timeout if read blocks */
#ifdef AFS_PTHREAD_ENV
        select(((long) (ufd->handle)) + 1, &in, 0, 0, 0);
#else
        IOMGR_Select(((long) (ufd->handle)) + 1, &in, 0, 0, 0); 
#endif /* AFS_PTHREAD_ENV*/
#endif
        error = USD_READ(ufd, buffer, blksize, &nbytes);
        if (error) {
            char buf[256];
            sprintf(buf, "File system read failed\n");
            VSETCODE(error, buf);
            break;
        }
        if (nbytes == 0) {
            done = 1;
            break;
        }
        if (rx_Write(call, buffer, nbytes) != nbytes) {
            error = -1;
            break;
        }
    }
    if (buffer)
        free(buffer);
    return error;
}

/* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
 * writes it out to the volume. */
afs_int32 WriteData(call, rock)
    struct rx_call *call;
    char *rock;
{
    char *filename;
    usd_handle_t ufd;
    long blksize;
    afs_int32 error, code;
    int ufdIsOpen = 0;

    error = 0;

    filename = rock;
    if (!filename || !*filename) {
        usd_StandardInput(&ufd);
        blksize = 4096;
        ufdIsOpen = 1;
    }
    else {
        code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
        if (code == 0) {
            ufdIsOpen = 1;
            code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
        }
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not access file '%s'\n", filename);
            error = VOLSERBADOP;
            VSETCODE(error, buffer);
            goto wfail;
        }
    }
    code = SendFile(ufd, call, blksize);
    if (code) {
        error = code;
        goto wfail;
    }
  wfail:
    if (ufdIsOpen) {
        code = USD_CLOSE(ufd);
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not close dump file %s\n",
                    (filename && *filename) ? filename : "STDOUT");
            VSETCODE(code, buffer);
            if (!error)
                error = code;
        }
    }
    return error;
}

/* Receive data from <call> stream into file associated
 * with <fd> <blksize>
 */
int ReceiveFile(ufd, call, blksize)
    usd_handle_t ufd;
    struct rx_call *call;
    long blksize;
{
    char *buffer = (char *) 0;
    afs_int32 bytesread;
    afs_uint32 bytesleft, w;
    afs_int32 error = 0;

    buffer = (char *) safemalloc(blksize);
    if (!buffer) {
        char buf[256];
        sprintf(buf, "memory allocation failed\n");
        VSETCODE(-1, buf);
        ERROR_EXIT(-1);
    }

    while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
        for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
#ifndef AFS_NT40_ENV            /* NT csn't select on non-socket fd's */
            fd_set out;
            FD_ZERO(&out);
            FD_SET((long) (ufd->handle), &out);
            /* don't timeout if write blocks */
#ifdef AFS_PTHREAD_ENV
            select(((long) (ufd->handle)) + 1, 0, &out, 0, 0);
#else
            IOMGR_Select(((long) (ufd->handle)) + 1, 0, &out, 0, 0); 
#endif /* AFS_PTHREAD_ENV*/
#endif
            error = USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
            if (error) {
                char buf[256];
                sprintf(buf, "File system write failed\n");
                VSETCODE(-1, buf);
                ERROR_EXIT(-1);
            }
        }
    }

  error_exit:
    if (buffer)
        free(buffer);
    return (error);
}

afs_int32 DumpFunction(call, filename)
    struct rx_call *call;
    char *filename;
{
    usd_handle_t ufd;           /* default is to stdout */
    afs_int32 error = 0, code;
    afs_hyper_t size;
    long blksize;
    int ufdIsOpen = 0;

    /* Open the output file */
    if (!filename || !*filename) {
        usd_StandardOutput(&ufd);
        blksize = 4096;
        ufdIsOpen = 1;
    }
    else {
        code = usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
        if (code == 0) {
            ufdIsOpen = 1;
            hzero(size);
            code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
        }
        if (code == 0) {
            code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
        }
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not create file '%s'\n", filename);
            VSETCODE(VOLSERBADOP, buffer);
            ERROR_EXIT(VOLSERBADOP);
        }
    }

    code = ReceiveFile(ufd, call, blksize);
    if (code)
        ERROR_EXIT(code);

  error_exit:
    /* Close the output file */
    if (ufdIsOpen) {
        code = USD_CLOSE(ufd);
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not close dump file %s\n",
                    (filename && *filename) ? filename : "STDIN");
            VSETCODE(code, buffer);
            if (!error)
                error = code;
        }
    }

    return (error);
}

struct tqElem {
    afs_int32 volid;
    struct tqElem *next;
};

struct tqHead {
    afs_int32 count;
    struct tqElem *next;
};

static struct tqHead busyHead, notokHead;

static void qInit(ahead)
    struct tqHead *ahead;
{
    Zero(ahead, 1, struct tqHead);
    return;
}

static void qPut(ahead, volid)
    struct tqHead *ahead;
    afs_int32 volid;
{
    struct tqElem *elem;

    elem = (struct tqElem *) safemalloc(sizeof(struct tqElem));
    elem->next = ahead->next;
    elem->volid = volid;
    ahead->next = elem;
    ahead->count++;
    return;
}

/* Kann vielleicht ganz raus ???    */
/* static void qGet(ahead, volid) */
/*     struct tqHead *ahead; */
/*     afs_int32 *volid; */
/* { */
/*     struct tqElem *tmp; */

/*     if (ahead->count <= 0) */
/*         return; */
/*     *volid = ahead->next->volid; */
/*     tmp = ahead->next; */
/*     ahead->next = tmp->next; */
/*     ahead->count--; */
/*     free(tmp); */
/*     return; */
/* } */

static int FileExists(filename)
    char *filename;
{
    usd_handle_t ufd;
    int code;
    afs_hyper_t size;

    code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);

src/AFS.xs  view on Meta::CPAN

        return ac - '0';
    if (ac >= 'a' && ac <= 'f')
        return ac - 'a' + 10;
    if (ac >= 'A' && ac <= 'F')
        return ac - 'A' + 10;
    return 0;
}

afs_uint32 GetUInt32(as, aval)
    register char *as;
    afs_uint32 *aval;
{
    register afs_uint32 total;
    register int tc;
    int base;

    total = 0;                  /* initialize things */

    /* skip over leading spaces */
    while ((tc = *as)) {
        if (tc != ' ' && tc != '\t')
            break;
    }

    /* compute the base */
    if (*as == '0') {
        as++;
        if (*as == 'x' || *as == 'X') {
            base = 16;
            as++;
        }
        else
            base = 8;
    }
    else
        base = 10;

    /* compute the # itself */
    while ((tc = *as)) {
        if (!ismeta(tc, base))
            return -1;
        total *= base;
        total += getmeta(tc);
        as++;
    }

    *aval = total;
    return 0;
}
#endif

/* keep those lines small */
static char *em(acode)
    afs_int32 acode;
{
    if (acode == -1)
        return "communications failure (-1)";
    else if (acode == -3)
        return "communications timeout (-3)";
    else
        return (char *) error_message(acode);
}

static struct rx_connection *internal_bos_new(code, hostname, localauth, noauth, aencrypt,
                                              tname)
    int32 *code;
    char *hostname;
    int localauth;
    int noauth;
    int aencrypt;
    char *tname;
{
    struct hostent *th;
    register struct rx_connection *tconn;
    struct rx_securityClass *sc[3];
    int scIndex;
    afs_int32 addr;
    int encryptLevel;
    struct ktc_principal sname;
    struct ktc_token ttoken;

    /* printf("bos DEBUG-1: %s \n", cdir); */
    th = (struct hostent *) hostutil_GetHostByName(hostname);
    if (!th) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS: can't find address for host '%s'\n", hostname);
        *code = -1;
        BSETCODE(code, buffer);
/*         printf("bos DEBUG-1: %s\n", buffer); */
        return NULL;
    }
    /* Copy(th->h_addr, &addr, sizeof(afs_int32), afs_int32); */
    Copy(th->h_addr, &addr, th->h_length, char);

    /* get tokens for making authenticated connections */
    if (!rx_initialized) {
        /* printf("bos DEBUG rx_Init\n"); */
        *code = rx_Init(0);
        if (*code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: could not initialize rx (%d)\n", *code);
            BSETCODE(code, buffer);
/*          printf("bos DEBUG-2\n"); */
            return NULL;
        }
    }
    rx_initialized = 1;

    *code = ka_Init(0);
    if (*code) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS: could not initialize ka (%d)\n", *code);
        BSETCODE(code, buffer);
/*          printf("bos DEBUG-3\n"); */
        return NULL;
    }

    if (localauth)
        internal_GetServerConfigDir();
    else
        internal_GetConfigDir();

src/AFS.xs  view on Meta::CPAN

/*         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) {
            /* if (istatus.errorSignal == SIGTERM) */
            /*    printf("due to shutdown request\n"); */
            /* else */
            /*    printf("due to signal %d\n", istatus.errorSignal); */
            safe_hv_store(stats, "errorSignal", 11, newSViv(istatus.errorSignal), 0);
        }
        else {
            /* printf("by exiting with code %d\n", istatus.errorCode); */
            safe_hv_store(stats, "errorCode", 9, newSViv(istatus.errorCode), 0);
        }
    }

    if (aint32p > 1) {
        AV *av = (AV *) sv_2mortal((SV *) newAV());

        /* try to display all the parms */
        for (i = 0;; i++) {
            tp = buffer;
            code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
            if (code)
                break;
            /* fprintf(stderr, "    Command %d is '%s'\n", i+1, buffer); */
            av_push(av, newSVpv(buffer, strlen(buffer)));
        }
        safe_hv_store(stats, "command", 7, newRV_inc((SV *) (av)), 0);

        tp = buffer;
        code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
        if (!code) {
            /* Any type of failure is treated as not having a notifier program */
            /* printf("    Notifier  is '%s'\n", buffer); */
            safe_hv_store(stats, "notifier", 8, newSVpv(buffer, strlen(buffer)), 0);
        }
        /* printf("\n"); */
    }
    return 0;
}

static afs_int32 GetServerGoal(aconn, aname)
    char *aname;
    struct rx_connection *aconn;
{
    char buffer[500];
    char *tp;
    register afs_int32 code;
    struct bozo_status istatus;

    tp = buffer;
    code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
    if (code) {
        printf("AFS::BOS: failed to get instance info for '%s' (%s)\n", aname, em(code));
        /* if we can't get the answer, assume its running */
        return BSTAT_NORMAL;
    }
    if (istatus.goal == 0)
        return BSTAT_SHUTDOWN;
    else
        return BSTAT_NORMAL;
}

#define PARMBUFFERSSIZE 32

static struct SalvageParms {
    afs_int32 Optdebug;
    afs_int32 Optnowrite;
    afs_int32 Optforce;
    afs_int32 Optoktozap;
    afs_int32 Optrootfiles;
    afs_int32 Optsalvagedirs;
    afs_int32 Optblockreads;
    afs_int32 OptListResidencies;
    afs_int32 OptSalvageRemote;
    afs_int32 OptSalvageArchival;
    afs_int32 OptIgnoreCheck;
    afs_int32 OptForceOnLine;
    afs_int32 OptUseRootDirACL;
    afs_int32 OptTraceBadLinkCounts;
    afs_int32 OptDontAskFS;
    afs_int32 OptLogLevel;
    afs_int32 OptRxDebug;
    afs_uint32 OptResidencies;
} mrafsParm;

static int DoSalvage(aconn, aparm1, aparm2, aoutName, showlog, parallel, atmpDir, orphans)
    struct rx_connection *aconn;
    char *aoutName;
    char *aparm1;
    char *aparm2;
    afs_int32 showlog;
    char *parallel;
    char *atmpDir;
    char *orphans;
{
    register afs_int32 code;
    char *parms[6];
    char buffer;
    char tbuffer[BOZO_BSSIZE];
    struct bozo_status istatus;
    struct rx_call *tcall;
    char *tp;
    FILE *outFile;
    int closeIt = 0;
    char partName[20];          /* canonical name for partition */
    char pbuffer[PARMBUFFERSSIZE];
    afs_int32 partNumber;
    char *notifier = NONOTIFIER;

    /* if a partition was specified, canonicalize the name, since
       the salvager has a stupid partition ID parser */
    if (aparm1) {
        partNumber = volutil_GetPartitionID(aparm1);
        if (partNumber < 0) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: could not parse partition ID '%s'\n", aparm1);
            BSETCODE(EINVAL, buffer);
            return EINVAL;
        }
        tp = (char *) volutil_PartitionName(partNumber);
        if (!tp) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: internal error parsing partition ID '%s'\n",
                    aparm1);
            BSETCODE(EINVAL, buffer);
            return EINVAL;
        }
        strcpy(partName, tp);
    }
    else
        partName[0] = 0;

    /* open the file name */
    if (aoutName) {
        outFile = fopen(aoutName, "w");
        if (!outFile) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: can't open specified SalvageLog file '%s'\n",
                    aoutName);
            BSETCODE(ENOENT, buffer);
            return ENOENT;
        }
        closeIt = 1;            /* close this file later */
    }
    else {
        outFile = stdout;
        closeIt = 0;            /* don't close this file later */
    }

    for (code = 2; code < 6; code++)
        parms[code] = "";
    if (!aparm2)
        aparm2 = "";
    /* MUST pass canonical (wire-format) salvager path to bosserver */
    strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
    if (*aparm2 != 0) {
        if ((strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) + 1) >
            BOZO_BSSIZE) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: command line too big\n");
            BSETCODE(E2BIG, buffer);
            return (E2BIG);
        }
        strcat(tbuffer, " ");
        strcat(tbuffer, partName);
        strcat(tbuffer, " ");
        strcat(tbuffer, aparm2);
    }
    else {
        if ((strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: command line too big\n");
            BSETCODE(E2BIG, buffer);
            return (E2BIG);
        }
        strcat(tbuffer, " -f ");
        strcat(tbuffer, partName);
    }

    /* add the parallel option if given */
    if (parallel != (char *) 0) {
        if ((strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE) {
            char buffer[256];

src/AFS.xs  view on Meta::CPAN

                    if (ht == NULL)
                        h = (char *) inet_ntoa(hosts[i]);
                    else
                        h = ht->h_name;
                }
                else {
                    h = (char *) inet_ntoa(hosts[i]);
                }
                XPUSHs(sv_2mortal(newSVpv(h, strlen(h))));
            }

        }
    }

void
fs__get_server_version(port,hostName="localhost",verbose=0)
        short port
        char *hostName
        int32 verbose
    CODE:
    {
#if defined(AFS_3_4)
        not_here("AFS::Utils::get_server_version");
#else
        struct sockaddr_in taddr;
        struct in_addr hostAddr;
        struct hostent *th;
        int32 host;
        short port_num = htons(port);
        int32 length = 64;
        int32 code;
        char version[64];
        int s;

          /* lookup host */
        if (hostName) {
            th = (struct hostent *) hostutil_GetHostByName(hostName);
            if (!th) {
                warn("rxdebug: host %s not found in host table\n", hostName);
                SETCODE(EFAULT);
                XSRETURN_UNDEF;
            }
            /* bcopy(th->h_addr, &host, sizeof(int32)); */
            Copy(th->h_addr, &host, th->h_length, char);
        }
        else
            host = htonl(0x7f000001);   /* IP localhost */

        hostAddr.s_addr = host;
        if (verbose)
            printf("Trying %s (port %d):\n", inet_ntoa(hostAddr), ntohs(port_num));

        s = socket(AF_INET, SOCK_DGRAM, 0);
        taddr.sin_family = AF_INET;
        taddr.sin_port = 0;
        taddr.sin_addr.s_addr = 0;

        code = bind(s, (struct sockaddr *) &taddr, sizeof(struct sockaddr_in));
        SETCODE(code);
        if (code) {
            perror("bind");
            XSRETURN_UNDEF;
        }

        code = rx_GetServerVersion(s, host, port_num, length, version);
        ST(0) = sv_newmortal();
        if (code < 0) {
            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));
        }
    }

src/AFS.xs  view on Meta::CPAN

        }
        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);
        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 : ENOENT, buffer);
            goto done;
        }

        if ((server && (strlen(server) != 0)) || (partition && (strlen(partition) != 0))) {
            if (!(server && (strlen(server) != 0)) || !(partition && (strlen(partition) != 0))) {
                char buffer[256];
                sprintf(buffer, "Must specify both SERVER and PARTITION arguments\n");
                VSETCODE(-1, buffer);
                goto done;
            }
            aserver = GetServer(server);
            if (aserver == 0) {
                char buffer[256];
                sprintf(buffer, "Invalid server name\n");
                VSETCODE(-1, buffer);
                goto done;
            }
            apart = volutil_GetPartitionID(partition);
            if (apart < 0) {
                char buffer[256];
                sprintf(buffer, "Invalid partition name\n");
                VSETCODE(-1, buffer);
                goto done;
            }
        }
        else {
            code = GetVolumeInfo(avolid, &aserver, &apart, &voltype, &entry);
            if (code) {
                SETCODE(code);
                goto done;
            }
        }

        if (time && strcmp(time, "0")) {
            code = ktime_DateToInt32(time, &fromdate);
            if (code) {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: failed to parse date '%s' (error=%d))\n", time, code);
                VSETCODE(code, buffer);
                goto done;
            }
        }
        if (file && (strlen(file) != 0)) {
            strcpy(filename, file);
        }
        else {
            strcpy(filename, "");
        }
#ifdef OpenAFS_1_4_05
        int iclone = 0;
    retry_dump:
        /* printf("vos_dump DEBUG-2 clone = %d omitdirs = %d \n", clone, omitdirs); */
        if ((!SvIOKp(clone))) {
            char buffer[256];
            sprintf(buffer, "Flag \"clone\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            RETVAL = 0;
            goto done;
        }
        else
            iclone = SvIV(clone);
        if (iclone) {
            /* printf("vos_dump DEBUG-2-1 clone = %d omitdirs = %d \n", clone, omitdirs); */
            code = UV_DumpClonedVolume(avolid, aserver, apart, fromdate,
                                       DumpFunction, filename, omitdirs);
        } else {
            /* printf("vos_dump DEBUG-2-2 clone = %d omitdirs = %d \n", clone, omitdirs); */
            code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction,
                                 filename, omitdirs);
        }
        /* printf("vos_dump DEBUG-3 code = %d \n", code); */
        if ((code == RXGEN_OPCODE) && (omitdirs)) {
            omitdirs = 0;
            goto retry_dump;
        }
#else
        /* printf("vos_dump DEBUG-4 \n"); */
        code = UV_DumpVolume(avolid, aserver, apart, fromdate, DumpFunction, filename);
        /* printf("vos_dump DEBUG-5 code = %d \n", code); */
#endif
        if (code) {
            PrintDiagnostics("dump", code);
            SETCODE(code);
            goto done;
        }

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

void
vos_partinfo(cstruct, server, partname=NULL)
        AFS::VOS cstruct

src/AFS.xs  view on Meta::CPAN

            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;
        }
        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

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

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

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

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

src/AFS.xs  view on Meta::CPAN

                    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); */
        if (arrayEntries.nbulkentries_val)
            free(arrayEntries.nbulkentries_val);

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

void
vos_listpart(cstruct, server)
        AFS::VOS cstruct
        char *server
    PREINIT:
        int32 aserver, code;
        struct partList dummyPartList;
        int i, total, cnt;
        char pname[10];
    PPCODE:
    {
        aserver = GetServer(server);
        if (aserver == 0) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", server);
            VSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }

src/AFS.xs  view on Meta::CPAN

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

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

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

        XSRETURN(2);
    }

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

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

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

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

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

        SETCODE(0);
        XSRETURN(2);
    }

int32
bos_delete(self, object)
        AFS::BOS self
        SV* object
    PREINIT:
        int32 code = 0, len, i;
        AV *av; SV *sv;
        char *name;

src/AFS.xs  view on Meta::CPAN

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

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

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

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

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

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

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

            av = (AV *) SvRV(object);
            len = av_len(av);
            if (len != -1) {
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                      /* instance = (char *) safemalloc(BOZO_BSSIZE); */
                        Newx(instance, BOZO_BSSIZE, char);
                        instance = SvPV(sv, namelen);
                        code = BOZO_SetStatus(self, instance, BSTAT_NORMAL);
                        if (code) {
                            char buffer[256];
                            sprintf(buffer, "AFS::BOS: failed to start instance %s (%s)\n",
                                    instance, em(code));
                            BSETCODE(code, buffer);
                            goto done;
                        }
                        /*if (instance) */
                        /*    Safefree(instance); */
                    }
                }                       /* for loop */
            }
        }

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

int32
bos__startup(self, object=NULL)

src/AFS.xs  view on Meta::CPAN

    PREINIT:
        int32 code = 0;   
    CODE:
    {
        not_here("AFS::BOS::setcellname");

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

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

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

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

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

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

src/AFS.xs  view on Meta::CPAN

            KSETCODE(code, buffer);
            safefree(t);
            XSRETURN_UNDEF;
        }
    }

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

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


MODULE = AFS    PACKAGE = AFS   PREFIX = afs_

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

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

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

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

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

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

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

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

void
afs_ka_StringToKey(str,cell)

src/AFS.xs  view on Meta::CPAN

            KSETCODE(code, buffer);
            safefree(key);
            XSRETURN_UNDEF;
        }
    }

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

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

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

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

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

    }


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

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

    }


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

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

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

src/AFS.xs  view on Meta::CPAN

            PUSHs(sc);
        }
        else {
            safefree(c);
            safefree(t);
        }
    }

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

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

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

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

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

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


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

#if defined(AFS_3_4)

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

  errno = EINVAL;

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



( run in 0.485 second using v1.01-cache-2.11-cpan-bbb979687b5 )