int shpam_shadow_setpass(shfs_ino_t *file, shseed_t *seed, shkey_t *sess_key) { shadow_t *ent; shadow_t save; shkey_t *seed_key; int err; seed_key = shkey_bin((char *)&seed->seed_uid, sizeof(seed->seed_uid)); ent = shpam_shadow(file, seed_key); shkey_free(&seed_key); if (!ent) return (SHERR_NOENT); memcpy(&save, ent, sizeof(shadow_t)); if (shtime64() >= save.sh_expire) return (SHERR_KEYEXPIRED); if (!shkey_cmp(&save.sh_sess, sess_key)) return (SHERR_KEYREJECTED); seed_key = shkey_bin((char *)&seed->seed_uid, sizeof(seed->seed_uid)); err = shpam_shadow_session_expire(file, seed_key, sess_key); shkey_free(&seed_key); if (err) return (err); err = shpam_shadow_pass_append(file, seed); if (err) return (err); return (0); }
int shpam_shadow_delete(shfs_ino_t *file, char *acc_name, shkey_t *sess_key) { shadow_t *ent; shadow_t save; shkey_t *seed_key; int ret_err; int err; if (!sess_key) return (SHERR_INVAL); seed_key = shpam_seed(acc_name); ent = shpam_shadow(file, seed_key); shkey_free(&seed_key); if (!ent) return (SHERR_NOKEY); memcpy(&save, ent, sizeof(shadow_t)); if (shtime64() >= save.sh_expire) return (SHERR_KEYEXPIRED); if (!shkey_cmp(&save.sh_sess, sess_key)) return (SHERR_KEYREJECTED); if (save.sh_flag & SHPAM_LOCK) return (SHERR_ACCESS); ret_err = 0; err = shfs_cred_remove(file, &save.sh_seed); if (err) ret_err = err; err = shpam_shadow_pass_remove(file, shpam_uid(acc_name)); if (err) ret_err = err; return (ret_err); }
/** * Creates a new bond with the local shared as sender. * @note Set the bond state to confirm to initiate transaction. */ tx_bond_t *create_bond(shkey_t *bond_key, double duration, double fee, double basis) { bond = (tx_bond_t *)calloc(1, sizeof(tx_bond_t)); if (!bond) return (SHERR_NOMEM); local_transid_generate(TX_BOND, &bond->tx); bond->bond_stamp = shtime64(); bond->bond_stamp = shtime_adj(bond->bond_stamp, duration); bond->bond_credit = (uint64_t)(fee / 0.00000001); bond->bond_basis = (uint32_t)(basis * 10000); bond->bond_state = TXBOND_PENDING; /* authenticate bond info */ generate_bond_signature(bond); err = tx_init(NULL, (tx_t *)bond, TX_BOND); if (err) return (err); return (bond); }