+ char *old = query->data;
+ size_t size = strlen(old) + 1;
+ char *new = old + size;
+ struct osl_object obj = {.data = old, .size = size};
+ struct osl_row *row;
+ struct para_buffer pb = {
+ .max_size = shm_get_shmmax(),
+ .private_data = &fd,
+ .max_size_handler = pass_buffer_as_shm
+ };
+ int ret;
+
+ ret = osl(osl_get_row(attribute_table, ATTCOL_NAME, &obj, &row));
+ if (ret < 0)
+ goto out;
+ obj.data = new;
+ obj.size = strlen(new) + 1;
+ ret = osl(osl_update_object(attribute_table, row, ATTCOL_NAME, &obj));
+out:
+ if (ret < 0)
+ para_printf(&pb, "%s\n", para_strerror(-ret));
+ else
+ afs_event(ATTRIBUTE_RENAME, &pb, NULL);
+ if (pb.offset)
+ pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+ free(pb.buf);
+}
+
+int com_mvatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
+{
+ int ret;
+
+ if (argc != 3)
+ return -E_ATTR_SYNTAX;
+ ret = send_standard_callback_request(argc - 1, argv + 1, com_mvatt_callback,
+ sc_send_result, scc);
+ if (ret < 0)
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
+ return ret;
+}
+
+/** Data passed to the action handler of com_rmatt(). */
+struct remove_attribute_action_data {
+ /** Message buffer. */
+ struct para_buffer pb;
+ /** Numver of attributes removed. */
+ int num_removed;
+ /** Bitwise "or" of the removed attributes. */
+ uint64_t mask_of_removed_atts;
+};
+
+static int remove_attribute(struct osl_table *table, struct osl_row *row,
+ const char *name, void *data)
+{
+ struct remove_attribute_action_data *raad = data;
+ int ret;
+ struct rmatt_event_data red = {.name = name};
+
+ ret = get_attribute_bitnum_by_name(name, &red.bitnum);
+ if (ret < 0)
+ return para_printf(&raad->pb, "%s: %s\n", name, para_strerror(-ret));
+ ret = osl(osl_del_row(table, row));
+ if (ret < 0)
+ return para_printf(&raad->pb, "%s: %s\n", name, para_strerror(-ret));
+ ret = para_printf(&raad->pb, "removed attribute %s\n", name);
+ raad->num_removed++;
+ raad->mask_of_removed_atts |= (1 << red.bitnum);
+ afs_event(ATTRIBUTE_REMOVE, &raad->pb, &red);
+ return ret;
+}
+
+static void com_rmatt_callback(int fd, const struct osl_object *query)
+{
+ struct remove_attribute_action_data raad = {
+ .num_removed = 0,
+ .pb = {
+ .max_size = shm_get_shmmax(),
+ .private_data = &fd,
+ .max_size_handler = pass_buffer_as_shm
+ }
+ };
+ int ret, ret2 = 0;
+ struct pattern_match_data pmd = {
+ .table = attribute_table,
+ .patterns = *query,
+ .loop_col_num = ATTCOL_BITNUM,
+ .match_col_num = ATTCOL_NAME,
+ .data = &raad,
+ .action = remove_attribute
+ };
+ ret = for_each_matching_row(&pmd);
+ if (ret < 0)
+ ret2 = para_printf(&raad.pb, "%s\n", para_strerror(-ret));
+ else if (!raad.num_removed)
+ ret2 = para_printf(&raad.pb, "no match -- nothing removed\n");
+ if (ret2 >= 0 && raad.pb.offset)
+ pass_buffer_as_shm(raad.pb.buf, raad.pb.offset, &fd);
+ free(raad.pb.buf);