AFS

 view release on metacpan or  search on metacpan

src/AFS.xs  view on Meta::CPAN

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

src/AFS.xs  view on Meta::CPAN


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

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

        }
    }

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

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;
            vi.out_size = MAXSIZE;
            vi.out = (caddr_t) space;
            code = pioctl(dir, VIOC_AFS_STAT_MT_PT, &vi, follow);
        }

        SETCODE(code);

src/AFS.xs  view on Meta::CPAN

        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;

src/AFS.xs  view on Meta::CPAN

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

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

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

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

        aserver = 0;
        apart = 0;

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

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

src/AFS.xs  view on Meta::CPAN

                    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;

src/AFS.xs  view on Meta::CPAN

bos_removeuser(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_DeleteSUser(self, name);
                    if (code) {
                        char buffer[240];
                        sprintf(buffer, "AFS::BOS: failed to delete user");
                        if (code == ENOENT)
                            sprintf(buffer, "%s (no such user)\n", buffer);
                        else
                            sprintf(buffer, "%s (%s)\n", em(code), buffer);
                        BSETCODE(code, buffer);
                    }
                }
            }                       /* for loop */
        }
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL


int32
bos_addkey(self, kvno, string=NULL)
        AFS::BOS self
        int32 kvno
        char *string
    PREINIT:
        int32 code = 0;
        struct ktc_encryptionKey tkey;
        char *tcell = (char *) 0;    /* use current cell */
        char buf[BUFSIZ], ver[BUFSIZ];
    CODE:
    {
        not_here("AFS::BOS::addkey");

        Zero(&tkey, 1, struct ktc_encryptionKey);

        RETVAL = 42;
        if (string)
            strcpy(buf, string);
        else {
            /* prompt for key */
            code = des_read_pw_string(buf, sizeof(buf), "input key: ", 0);
            if (code || strlen(buf) == 0) {
                char buffer[256];
                sprintf(buffer, "Bad key: \n");
                BSETCODE(code ? code : -1, buffer);
                RETVAL = 0;
            }
            code = des_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
            if (code || strlen(ver) == 0) {
                char buffer[256];
                sprintf(buffer, "Bad key: \n");
                BSETCODE(code ? code : -1, buffer);
                RETVAL = 0;
            }
            if (strcmp(ver, buf) != 0) {
                char buffer[256];
                sprintf(buffer, "\nInput key mismatch\n");
                BSETCODE(-1, buffer);
                RETVAL = 0;
            }
        }

        if (RETVAL == 42) {
            if (kvno == 999) {
                /* bcrypt key */
                strcpy((char *) &tkey, buf);
            }
            else {                      /* kerberos key */
                ka_StringToKey(buf, tcell, &tkey);
            }

            code = BOZO_AddKey(self, kvno, &tkey);
            if (code) {
                char buffer[256];
                sprintf(buffer, "AFS::BOS: failed to set key %d (%s)\n", kvno, em(code));
                BSETCODE(code, buffer);
            }

            SETCODE(code);
            RETVAL = (code == 0);
        }
        if (tcell)
            free(tcell);
    }
    OUTPUT:
        RETVAL

int32
bos_removekey(self, object)
        AFS::BOS self
        SV* object
    PREINIT:
        int32 code = 0;
        int32 temp;
    CODE:
    {
        not_here("AFS::BOS::removekey");

        if (SvIOK(object)) {
            temp = (int32) SvIV(object);
            code = BOZO_DeleteKey(self, temp);
        }
        else if (SvTYPE(SvRV(object)) == SVt_PVAV) {
            /* object is array ref */
            int len, i;
            AV *av;
            SV *sv;

            av = (AV *) SvIV(object);
            len = av_len(av);
            if (len != -1) {
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                        temp = SvIV(sv);
                        code = BOZO_DeleteKey(self, temp);
                        if (code) {
                            char buffer[256];
                            sprintf(buffer, "AFS::BOS: failed to deletekey");
                            BSETCODE(code, buffer);
                        }
                    }
                }                       /* for loop */
            }
        }
        SETCODE(code);
        RETVAL = (code == 0);
    }
    OUTPUT:
        RETVAL

int32
bos__create(self, name, type, object, notifier=NULL)
        AFS::BOS self
        char *name
        char *type
        SV *object
        char *notifier
    PREINIT:
        int32 i, len, code = 0;
        char *parms[6];
        AV *av; SV *sv;
        STRLEN namelen;
    CODE:
    {
        if (SvTYPE(SvRV(object)) != SVt_PVAV) {
            code = -1;
            BSETCODE(code, "AFS::BOS COMMAND not an array reference\n");
            goto done;
        }

        for (i = 0; i < 6; i++)
            parms[i] = "";

        av = (AV *) SvRV(object);
        len = av_len(av);
        if (len != -1) {

src/AFS.xs  view on Meta::CPAN

            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_SetTStatus(self, instance, BSTAT_SHUTDOWN);
                        if (code) {
                            char buffer[256];
                            sprintf(buffer, "AFS::BOS: failed to shutdown instance %s (%s)\n",
                                    instance, em(code));
                            BSETCODE(code, buffer);
                            goto done;
                        }
                        /*if (instance) */
                        /*    Safefree(instance); */
                    }
                }                       /* for loop */
            }
        }
        else {
            code = BOZO_ShutdownAll(self);
            if (code) {
                char buffer[256];
                sprintf(buffer, "AFS::BOS: failed to shutdown servers (%s)\n", em(code));
                BSETCODE(code, buffer);
                goto done;
            }
        }

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

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

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

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

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

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

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

int32
bos_salvage(self, partition=NULL, volume=NULL, all=0, outName=NULL, showlog=0, parallel=NULL, tmpDir=NULL, orphans=NULL, localauth=0, tmpname=NULL, debug=0, nowrite=0, force=0, oktozap=0, rootfiles=0, salvagedirs=0, blockreads=0, ListResidencies=0, S...
        AFS::BOS self
        char *partition
        char *volume
        int32 all
        char *outName
        int32 showlog
        char *parallel
        char *tmpDir
        char *orphans
        int32 localauth
        char *tmpname
        int32 debug
        int32 nowrite
        int32 force
        int32 oktozap
        int32 rootfiles
        int32 salvagedirs
        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)



( run in 0.791 second using v1.01-cache-2.11-cpan-39bf76dae61 )