Example #1
0
int install_sexe_userdata(sexe_t *S, char *tag)
{
  SHFL *fl;
  shjson_t *udata;
  shfs_t *fs;
  shbuf_t *buff;
  shkey_t *k;
  char path[PATH_MAX+1];
  int is_new;

  k = shkey_str(tag);
  sprintf(path, "/sys/data/sexe/%s", shkey_hex(k)); 
  memcpy(&S->pname, k, sizeof(S->pname));
  shkey_free(&k);

  buff = shbuf_init();
  fs = shfs_init(NULL);
  fl = shfs_file_find(fs, path);
  is_new = shfs_read(fl, buff);

  udata = shjson_init(shbuf_size(buff) ? (char *)shbuf_data(buff) : NULL);
  shbuf_free(&buff);

  if (is_new)
    shjson_num_add(udata, "birth", shtimef(shtime()));

  sexe_table_set(S, udata);
  lua_setglobal(S, "userdata");
  shjson_free(&udata);

  shfs_free(&fs);

  return (0);
}
Example #2
0
int shfs_ref_get(shfs_ino_t *file,
                 shfs_t **ref_fs_p, shfs_ino_t **ref_p)
{
    shfs_ino_t *ref;
    shfs_ino_t *parent;
    shpeer_t *peer;
    shfs_t *fs;
    shkey_t *hier;
    shbuf_t *buff;
    char path[SHFS_PATH_MAX];
    int hier_cnt;
    int err;
    int i;

    *ref_p = NULL;
    *ref_fs_p = NULL;

    if (!file || !file->tree)
        return (SHERR_INVAL);

    buff = shbuf_init();
    err = _shfs_ref_raw_read(file, buff);
    if (err)
        return (err);

    peer = (shpeer_t *)shbuf_data(buff);
    hier = (shkey_t *)(shbuf_data(buff) + sizeof(shpeer_t));

    fs = shfs_init(peer);
    if (!fs)
        return (SHERR_IO);

    memset(path, 0, sizeof(path));
    strcpy(path, "/");
    ref = fs->fsbase_ino;
    for (i = SHFS_MAX_REFERENCE_HIERARCHY - 1; i >= 0; i--) {
        if (shkey_cmp(&hier[i], ashkey_blank()))
            continue;
        if (shkey_cmp(&hier[i], shfs_token(file->tree->fsbase_ino)))
            continue;

        ref = shfs_inode_load(ref, &hier[i]);
        if (!ref) {
            shfs_free(&fs);
            return (SHERR_NOENT);
        }

        if (shfs_type(ref) == SHINODE_DIRECTORY)
            strncat(path, "/", SHFS_PATH_MAX - strlen(path) - 1);
        strncat(path, shfs_filename(ref), SHFS_PATH_MAX - strlen(path) - 1);
    }

    shbuf_free(&buff);

    *ref_p = ref;
    *ref_fs_p = fs;

    return (0);
}
Example #3
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);
}
Example #4
0
int shpam_shadow_open(uint64_t uid, shadow_t **shadow_p, shseed_t **seed_p)
{
  shadow_t ret_shadow;

  if (!_shadow_fs) {
    _shadow_fs = shfs_init(NULL);
    _shadow_file = shpam_shadow_file(_shadow_fs);
  }

  if (shadow_p) {
    shadow_t *sh;

    memset(&ret_shadow, 0, sizeof(ret_shadow));
    err = shfs_cred_load(file, seed_key, (unsigned char *)&ret_shadow, sizeof(ret_shadow));
    if (err)
      return (err);

    sh = (shadow_t *)calloc(1, sizeof(shadow_t));
    memcpy(sh, &ret_shadow, sizeof(ret_shadow));
    *shadow_p = sh;
  }

  if (seed_p) {
    shseed_t ret_seed;
    shseed_t *seed;

    err = shpam_pshadow_load(_shadow_file, uid, &ret_seed); 
    if (err)
      return (err);

    seed = (shseed_t *)calloc(1, sizeof(shseed_t));
    memcpy(seed, &ret_seed, sizeof(ret_seed));
    *seed_p = seed;
  }

  return (0);
}