Ejemplo n.º 1
0
int shpam_shadow_pass_remove(shfs_ino_t *file, uint64_t rem_uid)
{
  shbuf_t *rbuff;
  shbuf_t *buff;
  shseed_t *seeds;
  int total;
  int idx;
  int err;

  rbuff = shbuf_init();
  shfs_read(file, rbuff);

  buff = shbuf_init();
  seeds = (shseed_t *)shbuf_data(rbuff);
  total = shbuf_size(rbuff) / sizeof(shseed_t);
  for (idx = 0; idx < total; idx++) {
    if (seeds[idx].seed_uid == rem_uid)
      continue;

    shbuf_cat(buff, &seeds[idx], sizeof(shseed_t));
  }
  shbuf_free(&rbuff);

  err = shfs_write(file, buff);
  shbuf_free(&buff);
  if (err)
    return (err);
  
  return (0);
}
Ejemplo n.º 2
0
int shpam_shadow_pass_append(shfs_ino_t *file, shseed_t *seed)
{
  shbuf_t *buff;
  shseed_t *seeds;
  int total;
  int idx;
  int err;

  buff = shbuf_init();
  shfs_read(file, buff);

  seeds = (shseed_t *)shbuf_data(buff);
  total = shbuf_size(buff) / sizeof(shseed_t);
  for (idx = 0; idx < total; idx++) {
    if (seeds[idx].seed_uid == seed->seed_uid) {
      memcpy(&seeds[idx], seed, sizeof(shseed_t));
      break;
    }
  }
  if (idx == total) {
    shbuf_cat(buff, seed, sizeof(shseed_t));
  }

  err = shfs_write(file, buff);
  shbuf_free(&buff);
  if (err)
    return (err);
  
  return (0);
}
Ejemplo n.º 3
0
int shfs_file_write(shfs_ino_t *file, unsigned char *data, size_t data_len)
{
  shbuf_t *buff = shbuf_map(data, data_len);
  int err;

  err = shfs_write(file, buff);
  free(buff);

  return (err);
}
Ejemplo n.º 4
0
int shfs_ref_write(shfs_ino_t *file, shbuf_t *buff)
{
    shfs_t *fs;
    shfs_ino_t *ref;
    int err;

    err = shfs_ref_get(file, &fs, &ref);
    if (err)
        return (err);

    err = shfs_write(ref, buff);
    shfs_free(&fs);
    if (err)
        return (err);

    return (0);
}
Ejemplo n.º 5
0
int update_sexe_userdata(sexe_t *S)
{
  SHFL *fl;
  shjson_t *udata;
  shfs_t *fs;
  shbuf_t *buff;
  shkey_t *k;
  char path[PATH_MAX+1];
  char *str;
  int err;

  k = &S->pname;
  if (shkey_cmp(k, ashkey_blank())) {
fprintf(stderr, "DEBUG: update_sexe_userdata: no app key\n");
    return (0); /* blank */
  }
  sprintf(path, "/sys/data/sexe/%s", shkey_hex(k)); 

  lua_getglobal(S, "userdata");
  udata = sexe_table_get(S);
  if (!udata) {
fprintf(stderr, "DEBUG: update_sexe_userdata: no global 'userdata' variable.\n");
    return (SHERR_INVAL);
  }

  str = shjson_print(udata);
  if (!str) {
fprintf(stderr, "DEBUG: update_sexe_userdata: error encoding JSON.\n");
    return (SHERR_INVAL);
}
  shjson_free(&udata);

  buff = shbuf_init();
  shbuf_catstr(buff, str);
  free(str);


  fs = shfs_init(NULL);
  fl = shfs_file_find(fs, path);
  err = shfs_write(fl, buff);
  shbuf_free(&buff);
  shfs_free(&fs);

  return (err);
}
Ejemplo n.º 6
0
int pstore_write(int tx_op, char *name, unsigned char *data, size_t data_len)
{
    SHFL *fl;
    char prefix[256];
    char path[PATH_MAX+1];
    shbuf_t *buff;
    int err;

    pstore_init();

    memset(prefix, 0, sizeof(prefix));
    switch (tx_op) {
    case TX_ACCOUNT:
        strcpy(prefix, "account");
        break;
    case TX_IDENT:
        strcpy(prefix, "id");
        break;
    case TX_SESSION:
        strcpy(prefix, "session");
        break;
    case TX_APP:
        strcpy(prefix, "app");
        break;
    case TX_LEDGER:
        strcpy(prefix, "ledger");
        break;
    default:
        strcpy(prefix, "default");
        break;
    }

    sprintf(path, "/sys/net/tx/%s/%s", prefix, name);
    fl = shfs_file_find(_pstore_fs, path);
    buff = shbuf_init();
    shbuf_cat(buff, data, data_len);
    err = shfs_write(fl, buff);
    shbuf_free(&buff);
    if (err)
        return (err);

    return (0);
}
Ejemplo n.º 7
0
int shfs_rev_revert(shfs_ino_t *file)
{
  shbuf_t *buff;
  int err;

  buff = shbuf_init();
  err = shfs_rev_ref_read(file, "tag", "BASE", buff);
  if (err) {
    shbuf_free(&buff);
    return (err);
  }

  err = shfs_write(file, buff);
  shbuf_free(&buff);
  if (err)
    return (err);

  return (0);
}
Ejemplo n.º 8
0
int shpam_pshadow_store(shfs_ino_t *file, shseed_t *seed)
{
  shbuf_t *buff;
  shseed_t *seeds;
  int total;
  int idx;
  int err;

#if 0
  /* ensure record exists. */
  err = shpam_pshadow_load(file, seed->seed_uid, NULL);
  if (err)
    return (err);
#endif

  buff = shbuf_init();
  shfs_read(file, buff);

  seeds = (shseed_t *)shbuf_data(buff);
  total = shbuf_size(buff) / sizeof(shseed_t);
  for (idx = 0; idx < total; idx++) {
    if (seeds[idx].seed_uid == seed->seed_uid) {
      memcpy(&seeds[idx], seed, sizeof(shseed_t));
      break;
    }
  }
  if (idx == total) {
    shbuf_cat(buff, seed, sizeof(shseed_t));
  }

  err = shfs_write(file, buff);
  shbuf_free(&buff);
  if (err)
    return (err);

  return (0);
}
Ejemplo n.º 9
0
int shfs_file_copy(shfs_ino_t *src_file, shfs_ino_t *dest_file)
{
  shfs_t *ref_fs;
  shfs_ino_t *ref;
  shstat st;
  shbuf_t *buff;
  int err;

  if (!src_file || !dest_file)
    return (SHERR_INVAL);

  /* ensure there is something to copy */
  err = shfs_fstat(src_file, &st);
  if (err) {
fprintf(stderr, "DEBUG: shfs_file_copy: %d = shfs_fstat(src_file)\n", err);
    return (err);
  }

  if (shfs_type(dest_file) == SHINODE_DIRECTORY) {

#if 0
    /* extract tar archive */
    if (shfs_format(dest_file) == SHINODE_BINARY &&
        0 == strcmp(shfs_meta_get(dest_file, "content.mime"), 
          "application/x-tar")) {
      buff = shbuf_init();
      err = shfs_read(src_file, buff);
      if (err) {
        shbuf_free(&buff);
        return (err);
      }
      err = shfs_unarch(buff, dest_file);
      shbuf_free(&buff);
      return (0);
    }
#endif

    if (!(shfs_attr(src_file) & SHATTR_ARCH)) {
      if (IS_INODE_CONTAINER(shfs_type(src_file))) {
        dest_file = shfs_inode(dest_file, 
            shfs_filename(src_file), shfs_type(src_file));
      } else {
        dest_file = shfs_inode(dest_file, NULL, shfs_type(src_file));
      }
    }

  }

  ref =  NULL;
  ref_fs = NULL;
  if (shfs_format(dest_file) == SHINODE_REFERENCE) {
    /* apply operation to end-point inode. */
    err = shfs_ref_get(dest_file, &ref_fs, &ref);
    if (err) {
fprintf(stderr, "DEBUG: shfs_file_copy: %d = shfs_ref_get(dest_file)\n", err); 
      return (err);
}

    dest_file = ref;
  }

  if (shfs_format(dest_file) != SHINODE_EXTERNAL) { 
    /* direct copy data content without conversion when applicable. */
    switch (shfs_format(src_file)) {
#if 0
      case SHINODE_COMPRESS:
        err = shfs_zlib_copy(src_file, dest_file);
        if (err)
          return (err);
        return (0);
#endif
    }
  }

  /* default case */
  buff = shbuf_init();
  err = shfs_read(src_file, buff);
  if (err) {
fprintf(stderr, "DEBUG: shfs_file_copy: %d = shfs_read()\n", err); 
    goto done;
}

  err = shfs_write(dest_file, buff);
  shbuf_free(&buff);
  if (err) {
fprintf(stderr, "DEBUG: shfs_file_copy: %d = shfs_write()\n", err);
    goto done;
}

  /* success */
  err = 0;

done:
  shbuf_free(&buff);
  if (ref_fs)
    shfs_free(&ref_fs);
  return (err);
}