static void setUser(Dict* args, void* vctx, String* txid, struct Allocator* requestAlloc) { struct Context* const ctx = Identity_check((struct Context*) vctx); struct Jmp jmp; Jmp_try(jmp) { int64_t* user = Dict_getInt(args, String_CONST("uid")); int64_t* group = Dict_getInt(args, String_CONST("gid")); int gid = group ? (int)*group : 0; int64_t* keepNetAdmin = Dict_getInt(args, String_CONST("keepNetAdmin")); Security_setUser(*user, gid, *keepNetAdmin, ctx->logger, &jmp.handler, requestAlloc); } Jmp_catch { sendError(jmp.message, txid, ctx->admin); return; } sendError("none", txid, ctx->admin); }
static void getUser(Dict* args, void* vctx, String* txid, struct Allocator* requestAlloc) { struct Context* const ctx = Identity_check((struct Context*) vctx); String* user = Dict_getString(args, String_CONST("user")); Dict* ret = Security_getUser((user) ? user->bytes : NULL, requestAlloc); Admin_sendMessage(ret, txid, ctx->admin); }
static void flush(Dict* args, void* vcontext, String* txid) { struct Context* context = (struct Context*) vcontext; // We only remove users which were added using this api. CryptoAuth_removeUsers(context->ca, context); sendResponse(String_CONST("none"), context->admin, txid); }
static void ethInterfaceSetBeacon(int ifNum, Dict* eth, struct Context* ctx) { int64_t* beaconP = Dict_getInt(eth, String_CONST("beacon")); if (beaconP) { int64_t beacon = *beaconP; if (beacon > 3 || beacon < 0) { Log_error(ctx->logger, "interfaces.ETHInterface.beacon may only be 0, 1,or 2"); } else { // We can cast beacon to an int here because we know it's small enough Log_info(ctx->logger, "Setting beacon mode on ETHInterface to [%d].", (int) beacon); Dict d = Dict_CONST(String_CONST("interfaceNumber"), Int_OBJ(ifNum), Dict_CONST(String_CONST("state"), Int_OBJ(beacon), NULL)); rpcCall(String_CONST("ETHInterface_beacon"), &d, ctx, ctx->alloc); } } }
/* * Send a ping packet to one of the endpoints. */ static void sendPing(struct Peer* ep) { struct InterfaceController_pvt* ic = Identity_check(ep->ici->ic); ep->pingCount++; struct SwitchPinger_Ping* ping = SwitchPinger_newPing(ep->addr.path, String_CONST(""), ic->timeoutMilliseconds, onPingResponse, ep->alloc, ic->switchPinger); if (Defined(Log_DEBUG)) { uint8_t key[56]; Base32_encode(key, 56, ep->caSession->herPublicKey, 32); if (!ping) { Log_debug(ic->logger, "Failed to ping [%s.k], out of ping slots", key); } else { Log_debug(ic->logger, "SwitchPing [%s.k]", key); } } if (ping) { ping->onResponseContext = ep; } }
static void authorizedPasswords(List* list, struct Context* ctx) { uint32_t count = List_size(list); for (uint32_t i = 0; i < count; i++) { Dict* d = List_getDict(list, i); Log_info(ctx->logger, "Checking authorized password %d.", i); if (!d) { Log_critical(ctx->logger, "Not a dictionary type %d.", i); exit(-1); } String* passwd = Dict_getString(d, String_CONST("password")); if (!passwd) { Log_critical(ctx->logger, "Must specify a password %d.", i); exit(-1); } } for (uint32_t i = 0; i < count; i++) { struct Allocator* child = Allocator_child(ctx->alloc); Dict* d = List_getDict(list, i); String* passwd = Dict_getString(d, String_CONST("password")); String* user = Dict_getString(d, String_CONST("user")); String* displayName = user; if (!displayName) { displayName = String_printf(child, "password [%d]", i); } //String* publicKey = Dict_getString(d, String_CONST("publicKey")); String* ipv6 = Dict_getString(d, String_CONST("ipv6")); Log_info(ctx->logger, "Adding authorized password #[%d] for user [%s].", i, displayName->bytes); Dict *args = Dict_new(child); uint32_t i = 1; Dict_putInt(args, String_CONST("authType"), i, child); Dict_putString(args, String_CONST("password"), passwd, child); if (user) { Dict_putString(args, String_CONST("user"), user, child); } Dict_putString(args, String_CONST("displayName"), displayName, child); if (ipv6) { Log_info(ctx->logger, " This connection password restricted to [%s] only.", ipv6->bytes); Dict_putString(args, String_CONST("ipv6"), ipv6, child); } rpcCall(String_CONST("AuthorizedPasswords_add"), args, ctx, child); Allocator_free(child); } }
/** @return a string representing the address and port to connect to. */ static void initAngel(struct Pipe* asClientPipe, struct Interface* asCoreIface, char* asCorePipeName, struct EventBase* eventBase, struct Log* logger, struct Allocator* alloc, struct Random* rand) { Dict admin = Dict_CONST( String_CONST("bind"), String_OBJ(String_CONST("127.0.0.1")), Dict_CONST( String_CONST("corePipeName"), String_OBJ(String_CONST(asCorePipeName)), Dict_CONST( String_CONST("pass"), String_OBJ(String_CONST("abcd")), NULL ))); Dict message = Dict_CONST( String_CONST("admin"), Dict_OBJ(&admin), NULL ); struct Allocator* tempAlloc = Allocator_child(alloc); struct Message* toAngel = Message_new(0, 1024, tempAlloc); BencMessageWriter_write(&message, toAngel, NULL); Log_info(logger, "Writing intial configuration to angel on [%s]", asClientPipe->name); Interface_sendMessage(&asClientPipe->iface, toAngel); // This is client->angel->core data, we can throw this away. //struct Message* angelToCore = InterfaceWaiter_waitForData(asCoreIface, eventBase, tempAlloc, NULL); // unterminated string //Log_info(logger, "Init message from angel to core: [%s]", angelToCore->bytes); // Send response on behalf of core. Dict* coreToAngelResp = Dict_new(tempAlloc); Dict_putString(coreToAngelResp, String_CONST("error"), String_CONST("none"), tempAlloc); struct Message* coreToAngelMsg = Message_new(0, 256, tempAlloc); BencMessageWriter_write(coreToAngelResp, coreToAngelMsg, NULL); Interface_sendMessage(asCoreIface, coreToAngelMsg); // This is angel->client data, it will tell us which port was bound. struct Message* angelToClient = InterfaceWaiter_waitForData(&asClientPipe->iface, eventBase, tempAlloc, NULL); uint8_t lastByte = angelToClient->bytes[angelToClient->length-1]; angelToClient->bytes[angelToClient->length-1] = '\0'; printf("Response from angel to client: [%s%c]\n", angelToClient->bytes, (char)lastByte); Allocator_free(tempAlloc); return; }
static void adminMemory(Dict* input, void* vcontext, String* txid) { struct MemoryContext* context = vcontext; Dict d = Dict_CONST( String_CONST("bytes"), Int_OBJ(MallocAllocator_bytesAllocated(context->allocator)), NULL ); Admin_sendMessage(&d, txid, context->admin); }
static void list(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* context = (struct Context*) vcontext; struct Allocator* child = Allocator_child(context->allocator); List* users = CryptoAuth_getUsers(context->ca, child); uint32_t count = List_size(users); Dict response = Dict_CONST( String_CONST("total"), Int_OBJ(count), Dict_CONST( String_CONST("users"), List_OBJ(users), NULL )); Admin_sendMessage(&response, txid, context->admin); Allocator_free(child); }
static void adminPingOnResponse(struct SwitchPinger_Response* resp, void* vping) { struct Allocator* pingAlloc = resp->ping->pingAlloc; struct Ping* ping = vping; Dict* rd = Dict_new(pingAlloc); if (resp->res == SwitchPinger_Result_LABEL_MISMATCH) { uint8_t path[20] = {0}; AddrTools_printPath(path, resp->label); String* pathStr = String_new(path, pingAlloc); Dict_putString(rd, String_CONST("rpath"), pathStr, pingAlloc); } Dict_putInt(rd, String_CONST("version"), resp->version, pingAlloc); Dict_putInt(rd, String_CONST("ms"), resp->milliseconds, pingAlloc); Dict_putString(rd, String_CONST("result"), SwitchPinger_resultString(resp->res), pingAlloc); Dict_putString(rd, String_CONST("path"), ping->path, pingAlloc); if (resp->data) { Dict_putString(rd, String_CONST("data"), resp->data, pingAlloc); } if (!Bits_isZero(resp->key, 32)) { Dict_putString(rd, String_CONST("key"), Key_stringify(resp->key, pingAlloc), pingAlloc); } Admin_sendMessage(rd, ping->txid, ping->context->admin); }
static void sendFirstMessageToCore(void* vcontext) { struct NodeContext* ctx = Identity_check((struct NodeContext*) vcontext); struct Allocator* alloc = Allocator_child(ctx->alloc); struct Message* msg = Message_new(0, 512, alloc); Dict* d = Dict_new(alloc); Dict_putString(d, String_CONST("privateKey"), String_new(ctx->privateKeyHex, alloc), alloc); Dict* logging = Dict_new(alloc); { Dict_putString(logging, String_CONST("logTo"), String_CONST("stdout"), alloc); } Dict_putDict(d, String_CONST("logging"), logging, alloc); Dict* admin = Dict_new(alloc); { Dict_putString(admin, String_CONST("bind"), ctx->bind, alloc); Dict_putString(admin, String_CONST("pass"), ctx->pass, alloc); } Dict_putDict(d, String_CONST("admin"), admin, alloc); BencMessageWriter_write(d, msg, NULL); Iface_send(&ctx->angelIface, msg); Allocator_free(alloc); }
static void sendResponse(String* msg, struct Admin* admin, String* txid) { #define BUFFERSZ 1024 uint8_t buffer[BUFFERSZ]; struct Allocator* alloc = BufferAllocator_new(buffer, BUFFERSZ); Dict* output = Dict_new(alloc); Dict_putString(output, String_CONST("error"), msg, alloc); Admin_sendMessage(output, txid, admin); }
static void sendResponse(String* error, struct Admin* admin, String* txid, struct Allocator* tempAlloc) { Dict* output = Dict_new(tempAlloc); Dict_putString(output, String_CONST("error"), error, tempAlloc); Admin_sendMessage(output, txid, admin); }
static int rpcCall0(String* function, Dict* args, struct Context* ctx, struct Allocator* alloc, bool exitIfError) { ctx->currentReqAlloc = Allocator_child(alloc); ctx->currentResult = NULL; struct AdminClient_Promise* promise = AdminClient_rpcCall(function, args, ctx->client, alloc); promise->callback = rpcCallback; promise->userData = ctx; EventBase_beginLoop(ctx->base); struct AdminClient_Result* res = ctx->currentResult; Assert_always(res); if (res->err) { Log_critical(ctx->logger, "Failed to make function call [%s], error: [%s]", AdminClient_errorString(res->err), function->bytes); die(res, ctx, alloc); } String* error = Dict_getString(res->responseDict, String_CONST("error")); int ret = 0; if (error && !String_equals(error, String_CONST("none"))) { if (exitIfError) { Log_critical(ctx->logger, "Got error [%s] calling [%s]", error->bytes, function->bytes); die(res, ctx, alloc); } Log_warn(ctx->logger, "Got error [%s] calling [%s], ignoring.", error->bytes, function->bytes); ret = 1; } Allocator_free(ctx->currentReqAlloc); ctx->currentReqAlloc = NULL; return ret; }
static void minSinatures(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* context = vcontext; struct Allocator* alloc = Allocator_child(context->alloc); int64_t* count = Dict_getInt(args, String_CONST("count")); char* err = "none"; if (*count < 0 || *count > INT32_MAX) { err = "count cannot be less than zero or more than INT32_MAX"; } else { context->rainfly->minSignatures = *count; } Dict* response = Dict_new(alloc); Dict_putString(response, String_CONST("error"), String_CONST(err), alloc); Admin_sendMessage(response, txid, context->admin); Allocator_free(alloc); }
static void standardClientCallback(struct AdminClient_Promise* p, struct AdminClient_Result* res) { struct Context* ctx = p->userData; //printf("%d\n", res->err); Assert_always(!res->err); Assert_always(Dict_getInt(res->responseDict, String_CONST("called!"))); Assert_always(ctx->called); EventBase_endLoop(ctx->framework->eventBase); }
static void getRouteLabel(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* ctx = Identity_check((struct Context*) vcontext); char* err = NULL; String* pathToParentS = Dict_getString(args, String_CONST("pathToParent")); uint64_t pathToParent = 0; if (pathToParentS->len != 19 || AddrTools_parsePath(&pathToParent, pathToParentS->bytes)) { err = "parse_pathToParent"; } String* pathParentToChildS = Dict_getString(args, String_CONST("pathParentToChild")); uint64_t pathParentToChild = 0; if (pathParentToChildS->len != 19 || AddrTools_parsePath(&pathParentToChild, pathParentToChildS->bytes)) { err = "parse_pathParentToChild"; } uint64_t label = UINT64_MAX; if (!err) { label = NodeStore_getRouteLabel(ctx->store, pathToParent, pathParentToChild); err = NodeStore_getRouteLabel_strerror(label); } Dict* response = Dict_new(requestAlloc); if (!err) { String* printedPath = String_newBinary(NULL, 19, requestAlloc); AddrTools_printPath(printedPath->bytes, label); Dict_putString(response, String_new("result", requestAlloc), printedPath, requestAlloc); Dict_putString(response, String_new("error", requestAlloc), String_new("none", requestAlloc), requestAlloc); Admin_sendMessage(response, txid, ctx->admin); } else { Dict_putString(response, String_new("error", requestAlloc), String_new(err, requestAlloc), requestAlloc); Admin_sendMessage(response, txid, ctx->admin); } }
static void allowConnection(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* context = (struct Context*) vcontext; String* publicKeyOfAuthorizedNode = Dict_getString(args, String_CONST("publicKeyOfAuthorizedNode")); String* ip6Address = Dict_getString(args, String_CONST("ip6Address")); String* ip4Address = Dict_getString(args, String_CONST("ip4Address")); uint8_t pubKey[32]; uint8_t ip6Addr[16]; struct Sockaddr_storage ip6ToGive; struct Sockaddr_storage ip4ToGive; char* error; int ret; if (!ip6Address && !ip4Address) { error = "Must specify ip6Address or ip4Address"; } else if ((ret = Key_parse(publicKeyOfAuthorizedNode, pubKey, ip6Addr)) != 0) { error = Key_parse_strerror(ret); } else if (ip6Address && (Sockaddr_parse(ip6Address->bytes, &ip6ToGive) || Sockaddr_getFamily(&ip6ToGive.addr) != Sockaddr_AF_INET6)) { error = "malformed ip6Address"; } else if (ip4Address && (Sockaddr_parse(ip4Address->bytes, &ip4ToGive) || Sockaddr_getFamily(&ip4ToGive.addr) != Sockaddr_AF_INET)) { error = "malformed ip4Address"; } else { int conn = IpTunnel_allowConnection(pubKey, (ip6Address) ? &ip6ToGive.addr : NULL, (ip4Address) ? &ip4ToGive.addr : NULL, context->ipTun); sendResponse(conn, txid, context->admin); return; } sendError(error, txid, context->admin); }
void Configurator_config(Dict* config, struct Sockaddr* sockAddr, String* adminPassword, struct EventBase* eventBase, struct Log* logger, struct Allocator* alloc) { struct Allocator* tempAlloc = Allocator_child(alloc); struct UDPAddrIface* udp = UDPAddrIface_new(eventBase, NULL, alloc, NULL, logger); struct AdminClient* client = AdminClient_new(&udp->generic, sockAddr, adminPassword, eventBase, logger, tempAlloc); struct Context ctx = { .logger = logger, .alloc = tempAlloc, .client = client, .base = eventBase, }; waitUntilPong(&ctx); List* authedPasswords = Dict_getList(config, String_CONST("authorizedPasswords")); if (authedPasswords) { authorizedPasswords(authedPasswords, &ctx); } Dict* ifaces = Dict_getDict(config, String_CONST("interfaces")); udpInterface(ifaces, &ctx); if (Defined(HAS_ETH_INTERFACE)) { ethInterface(ifaces, &ctx); } Dict* routerConf = Dict_getDict(config, String_CONST("router")); routerConfig(routerConf, tempAlloc, &ctx); List* secList = Dict_getList(config, String_CONST("security")); security(tempAlloc, secList, logger, &ctx); Log_debug(logger, "Cjdns started in the background"); Allocator_free(tempAlloc); }
void Configurator_config(Dict* config, struct Sockaddr* sockAddr, String* adminPassword, struct EventBase* eventBase, struct Log* logger, struct Allocator* alloc) { struct Except* eh = NULL; struct Allocator* tempAlloc = Allocator_child(alloc); struct AdminClient* client = AdminClient_new(sockAddr, adminPassword, eventBase, logger, tempAlloc); struct Context ctx = { .logger = logger, .alloc = tempAlloc, .client = client, .base = eventBase, }; List* authedPasswords = Dict_getList(config, String_CONST("authorizedPasswords")); if (authedPasswords) { authorizedPasswords(authedPasswords, &ctx); } Dict* ifaces = Dict_getDict(config, String_CONST("interfaces")); udpInterface(ifaces, &ctx); #ifdef HAS_ETH_INTERFACE ethInterface(ifaces, &ctx); #endif Dict* routerConf = Dict_getDict(config, String_CONST("router")); routerConfig(routerConf, tempAlloc, &ctx); List* securityList = Dict_getList(config, String_CONST("security")); security(securityList, tempAlloc, &ctx); Dict* dnsConf = Dict_getDict(config, String_CONST("dns")); dns(dnsConf, &ctx, eh); Allocator_free(tempAlloc); }
static void addRemoveSomething(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc, enum addRemoveSomething_What what) { struct RouteGen_admin_Ctx* ctx = Identity_check((struct RouteGen_admin_Ctx*) vcontext); String* route = Dict_getString(args, String_CONST("route")); char* error = NULL; struct Sockaddr_storage ss; if (route->len > 63) { error = "parse_failed"; } if (!error) { if (Sockaddr_parse(route->bytes, &ss)) { error = "parse_failed"; } else { int family = Sockaddr_getFamily(&ss.addr); if (family != Sockaddr_AF_INET && family != Sockaddr_AF_INET6) { error = "unexpected_af"; } } } int retVal = -1; Dict* out = Dict_new(requestAlloc); if (!error) { switch (what) { case addRemoveSomething_What_ADD_EXCEPTION: RouteGen_addException(ctx->rg, &ss.addr); break; case addRemoveSomething_What_ADD_PREFIX: RouteGen_addPrefix(ctx->rg, &ss.addr); break; case addRemoveSomething_What_ADD_LOCALPREFIX: RouteGen_addLocalPrefix(ctx->rg, &ss.addr); break; case addRemoveSomething_What_RM_EXCEPTION: retVal = RouteGen_removeException(ctx->rg, &ss.addr); break; case addRemoveSomething_What_RM_PREFIX: retVal = RouteGen_removePrefix(ctx->rg, &ss.addr); break; case addRemoveSomething_What_RM_LOCALPREFIX: retVal = RouteGen_removeLocalPrefix(ctx->rg, &ss.addr); break; default: Assert_failure("invalid op"); } if (!retVal) { error = "no_such_route"; } else { error = "none"; } } Dict_putString(out, String_new("error", requestAlloc), String_new(error, requestAlloc), requestAlloc); Admin_sendMessage(out, txid, ctx->admin); }
static void removeConnection(Dict* args, void* vcontext, String* txid) { struct Context* context = vcontext; int conn = (int) *(Dict_getInt(args, String_CONST("connection"))); char* error = "none"; if (IpTunnel_removeConnection_NOT_FOUND == IpTunnel_removeConnection(conn, context->ipTun)) { error = "not found"; } sendError(error, txid, context->admin); }
static void security(List* securityConf, struct Allocator* tempAlloc, struct Context* ctx) { bool noFiles = false; for (int i = 0; i < List_size(securityConf); i++) { if (String_equals(String_CONST("nofiles"), List_getString(securityConf, i))) { noFiles = true; } else { Dict* userDict = List_getDict(securityConf, i); String* userName = Dict_getString(userDict, String_CONST("setuser")); if (userName) { Dict d = Dict_CONST(String_CONST("user"), String_OBJ(userName), NULL); // If this call returns an error, it is ok. rpcCall0(String_CONST("Security_setUser"), &d, ctx, tempAlloc, false); } } } if (noFiles) { Dict d = NULL; rpcCall(String_CONST("Security_noFiles"), &d, ctx, tempAlloc); } }
static void rpcCall(String* function, Dict* args, struct Context* ctx, struct Allocator* alloc) { struct AdminClient_Result* res = AdminClient_rpcCall(function, args, ctx->client, alloc); if (res->err) { Log_critical2(ctx->logger, "Failed to make function call [%s], error: [%s]", AdminClient_errorString(res->err), function->bytes); showMsg(res, ctx); exit(-1); } String* error = Dict_getString(res->responseDict, String_CONST("error")); if (error && !String_equals(error, String_CONST("none"))) { Log_critical2(ctx->logger, "Router responses with error: [%s]\nCalling function: [%s]", error->bytes, function->bytes); showMsg(res, ctx); exit(-1); } }
static void adminPing(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* context = vcontext; String* pathStr = Dict_getString(args, String_CONST("path")); int64_t* timeoutPtr = Dict_getInt(args, String_CONST("timeout")); String* data = Dict_getString(args, String_CONST("data")); int64_t* keyPing = Dict_getInt(args, String_CONST("keyPing")); uint32_t timeout = (timeoutPtr) ? *timeoutPtr : DEFAULT_TIMEOUT; uint64_t path; String* err = NULL; if (pathStr->len != 19 || AddrTools_parsePath(&path, (uint8_t*) pathStr->bytes)) { err = String_CONST("path was not parsable."); } else { struct SwitchPinger_Ping* ping = SwitchPinger_newPing(path, data, timeout, adminPingOnResponse, context->alloc, context->switchPinger); if (keyPing && *keyPing) { ping->keyPing = true; } if (!ping) { err = String_CONST("no open slots to store ping, try later."); } else { ping->onResponseContext = Allocator_clone(ping->pingAlloc, (&(struct Ping) { .context = context, .txid = String_clone(txid, ping->pingAlloc), .path = String_clone(pathStr, ping->pingAlloc) })); } }
static void authorizedPasswords(List* list, struct Context* ctx) { uint32_t count = List_size(list); for (uint32_t i = 0; i < count; i++) { Dict* d = List_getDict(list, i); Log_info(ctx->logger, "Checking authorized password %d.", i); if (!d) { Log_critical(ctx->logger, "Not a dictionary type %d.", i); exit(-1); } String* passwd = Dict_getString(d, String_CONST("password")); if (!passwd) { Log_critical(ctx->logger, "Must specify a password %d.", i); exit(-1); } } Log_info(ctx->logger, "Flushing existing authorized passwords"); rpcCall(String_CONST("AuthorizedPasswords_flush"), NULL, ctx, ctx->alloc); for (uint32_t i = 0; i < count; i++) { Dict* d = List_getDict(list, i); String* passwd = Dict_getString(d, String_CONST("password")); Log_info(ctx->logger, "Adding authorized password #[%d].", i); Dict args = Dict_CONST( String_CONST("authType"), Int_OBJ(1), Dict_CONST( String_CONST("password"), String_OBJ(passwd), NULL )); struct Allocator* child = ctx->alloc->child(ctx->alloc); rpcCall(String_CONST("AuthorizedPasswords_add"), &args, ctx, child); child->free(child); } }
static void dumpRumorMill(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* ctx = Identity_check((struct Context*) vcontext); Dict* out = Dict_new(requestAlloc); struct RumorMill* rm = getRumorMill(ctx, Dict_getString(args, String_CONST("mill"))); if (!rm) { Dict_putString(out, String_CONST("error"), String_CONST("mill must be one of " "[externalMill,linkMill,nodeMill,dhtMill,splitMill]"), requestAlloc); Admin_sendMessage(out, txid, ctx->admin); return; } int64_t* page = Dict_getInt(args, String_CONST("page")); int ctr = (page) ? *page * ENTRIES_PER_PAGE : 0; List* table = List_new(requestAlloc); for (int i = 0; i < ENTRIES_PER_PAGE && ctr < rm->count; i++) { String* addr = Address_toString(&rm->addresses[ctr++], requestAlloc); List_addString(table, addr, requestAlloc); } Dict_putList(out, String_CONST("addresses"), table, requestAlloc); Dict_putInt(out, String_CONST("total"), rm->count, requestAlloc); Admin_sendMessage(out, txid, ctx->admin); }
static void showConnection(Dict* args, void* vcontext, String* txid) { struct Context* context = vcontext; int connNum = (int) *(Dict_getInt(args, String_CONST("connection"))); for (int i = 0; i < (int)context->ipTun->connectionList.count; i++) { if (connNum == context->ipTun->connectionList.connections[i].number) { showConn(&context->ipTun->connectionList.connections[i], txid, context->admin); return; } } sendError("connection not found", txid, context->admin); }
static void setUser(Dict* args, void* vcontext, String* txid) { struct Context* const ctx = (struct Context*) vcontext; struct Jmp jmp; Jmp_try(jmp) { String* user = Dict_getString(args, String_CONST("user")); Security_setUser(user->bytes, ctx->logger, &jmp.handler); } Jmp_catch { sendError(jmp.message, txid, ctx->admin); return; } sendError("none", txid, ctx->admin); }
static char* setUser(List* config) { for (int i = 0; i < List_size(config); i++) { Dict* d = List_getDict(config, i); if (d) { String* uname = Dict_getString(d, String_CONST("setuser")); if (uname) { return uname->bytes; } } } return NULL; }