int query_entity_id(isns_client_t *clnt, int argc, char **argv) { isns_attr_list_t query_key = ISNS_ATTR_LIST_INIT; isns_object_list_t objects = ISNS_OBJECT_LIST_INIT; uint32_t status; isns_simple_t *qry; const char *eid; if (argc == 1 && !strcmp(argv[0], "help")) { printf("Query iSNS for own entity ID.\n" "No arguments allowed\n"); exit(0); } if (argc != 0) isns_fatal("EID query - no arguments accepted\n"); isns_attr_list_append_string(&query_key, ISNS_TAG_ISCSI_NAME, isns_config.ic_source_name); qry = isns_create_query(clnt, &query_key); isns_attr_list_destroy(&query_key); isns_query_request_attr_tag(qry, ISNS_TAG_ENTITY_IDENTIFIER); status = isns_client_call(clnt, &qry); if (status != ISNS_SUCCESS) { isns_error("Query failed: %s\n", isns_strerror(status)); return status; } status = isns_query_response_get_objects(qry, &objects); if (status) { isns_error("Unable to extract object list from query response: %s\n", isns_strerror(status), status); return status; } status = ISNS_NO_SUCH_ENTRY; if (objects.iol_count == 0) { isns_error("Node %s not registered with iSNS\n", isns_config.ic_source_name); } else if (!isns_object_get_string(objects.iol_data[0], ISNS_TAG_ENTITY_IDENTIFIER, &eid)) { isns_error("Query for %s returned an object without EID\n", isns_config.ic_source_name); } else { printf("%s\n", eid); status = ISNS_SUCCESS; } isns_object_list_destroy(&objects); isns_simple_free(qry); return status; }
/* * Enroll a new client */ int enroll_client(isns_client_t *clnt, int argc, char **argv) { isns_attr_list_t attrs = ISNS_ATTR_LIST_INIT; const char *client_name; int status; if (argc == 0) usage(1, "Missing client name"); client_name = *argv++; --argc; isns_attr_list_append_string(&attrs, OPENISNS_TAG_POLICY_SPI, client_name); #if 0 isns_attr_list_append_string(&attrs, OPENISNS_TAG_POLICY_SOURCE_NAME, client_name); #endif if (!opt_keyfile) { static char namebuf[PATH_MAX]; snprintf(namebuf, sizeof(namebuf), "%s.key", client_name); opt_keyfile = namebuf; } if (argc && !parse_policy(argc, argv, &attrs, "Enroll an iSNS client", "--enroll hostname")) isns_fatal("Cannot parse policy\n"); /* If no key is given, generate one */ if (!isns_attr_list_contains(&attrs, OPENISNS_TAG_POLICY_KEY)) { printf("No key given, generating one\n"); isns_attr_list_append_attr(&attrs, generate_key_callback()); } status = __create_policy(clnt, &attrs); isns_attr_list_destroy(&attrs); return status; }
/* * Look up the policy object given its SPI */ isns_object_t * __isns_db_keystore_lookup(isns_db_keystore_t *store, const char *name, size_t namelen) { isns_attr_list_t keys = ISNS_ATTR_LIST_INIT; char namebuf[256]; if (namelen >= sizeof(namebuf)) return NULL; memcpy(namebuf, name, namelen); namebuf[namelen] = '\0'; isns_attr_list_append_string(&keys, OPENISNS_TAG_POLICY_SPI, namebuf); return isns_db_lookup(store->sd_db, NULL, &keys); }