Skip to content

Commit 6d197e1

Browse files
legacy appsock should not handle admin
Signed-off-by: Akshat Sikarwar <[email protected]>
1 parent beac015 commit 6d197e1

File tree

1 file changed

+29
-52
lines changed

1 file changed

+29
-52
lines changed

net/net.c

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,64 +2644,41 @@ int is_connection_local(SBUF2 *sb) {
26442644
int do_appsock(netinfo_type *netinfo_ptr, struct sockaddr_in *cliaddr,
26452645
SBUF2 *sb, uint8_t firstbyte)
26462646
{
2647-
watchlist_node_type *watchlist_node;
2648-
int new_fd = sbuf2fileno(sb);
2649-
char paddr[64];
2650-
2651-
int admin = 0;
2652-
APPSOCKFP *rtn = NULL;
2653-
2654-
if (firstbyte == '@') {
2655-
findpeer(new_fd, paddr, sizeof(paddr));
2656-
if (!gbl_forbid_remote_admin ||
2657-
(cliaddr->sin_addr.s_addr == htonl(INADDR_LOOPBACK))) {
2658-
admin = 1;
2659-
} else {
2660-
logmsg(LOGMSG_INFO, "Rejecting non-local admin user from %s\n", paddr);
2661-
sbuf2close(sb);
2662-
return -1;
2663-
}
2647+
if (firstbyte == '@' || gbl_server_admin_mode) {
2648+
/* admin connections are handled by exclusively by newsql - should never get here */
2649+
goto err;
26642650
} else if (firstbyte != sbuf2ungetc(firstbyte, sb)) {
2665-
logmsg(LOGMSG_ERROR, "sbuf2ungetc failed %s:%d\n", __FILE__, __LINE__);
2666-
sbuf2close(sb);
2667-
return -1;
2651+
logmsg(LOGMSG_ERROR, "sbuf2ungetc failed %s\n", __func__);
2652+
goto err;
26682653
}
26692654

2670-
2671-
if (gbl_server_admin_mode && !admin) {
2672-
sbuf2close(sb);
2673-
return -1;
2655+
if (!netinfo_ptr->appsock_rtn) {
2656+
goto err;
26742657
}
26752658

2659+
/* set up the watchlist system for this node */
2660+
watchlist_node_type *watchlist_node;
2661+
watchlist_node = calloc(1, sizeof(watchlist_node_type));
2662+
if (!watchlist_node) {
2663+
logmsg(LOGMSG_ERROR, "%s: malloc watchlist_node failed\n", __func__);
2664+
goto err;
2665+
}
2666+
memcpy(watchlist_node->magic, "WLST", 4);
2667+
watchlist_node->in_watchlist = 0;
2668+
watchlist_node->netinfo_ptr = netinfo_ptr;
2669+
watchlist_node->sb = sb;
2670+
watchlist_node->readfn = sbuf2getr(sb);
2671+
watchlist_node->writefn = sbuf2getw(sb);
2672+
watchlist_node->addr = *cliaddr;
2673+
sbuf2setrw(sb, net_reads, net_writes);
2674+
sbuf2setuserptr(sb, watchlist_node);
2675+
26762676
/* call user specified app routine */
2677-
if (admin && netinfo_ptr->admin_appsock_rtn) {
2678-
rtn = netinfo_ptr->admin_appsock_rtn;
2679-
} else if (netinfo_ptr->appsock_rtn) {
2680-
rtn = netinfo_ptr->appsock_rtn;
2681-
}
2682-
2683-
if (rtn) {
2684-
/* set up the watchlist system for this node */
2685-
watchlist_node = calloc(1, sizeof(watchlist_node_type));
2686-
if (!watchlist_node) {
2687-
logmsg(LOGMSG_ERROR, "%s: malloc watchlist_node failed\n", __func__);
2688-
sbuf2close(sb);
2689-
return -1;
2690-
}
2691-
memcpy(watchlist_node->magic, "WLST", 4);
2692-
watchlist_node->in_watchlist = 0;
2693-
watchlist_node->netinfo_ptr = netinfo_ptr;
2694-
watchlist_node->sb = sb;
2695-
watchlist_node->readfn = sbuf2getr(sb);
2696-
watchlist_node->writefn = sbuf2getw(sb);
2697-
watchlist_node->addr = *cliaddr;
2698-
sbuf2setrw(sb, net_reads, net_writes);
2699-
sbuf2setuserptr(sb, watchlist_node);
2700-
2701-
/* this doesn't read- it just farms this off to a thread */
2702-
rtn(netinfo_ptr, sb);
2703-
return 0;
2704-
}
2677+
/* this doesn't read- it just farms this off to a thread */
2678+
netinfo_ptr->appsock_rtn(netinfo_ptr, sb);
2679+
return 0;
2680+
2681+
err:
27052682
sbuf2close(sb);
27062683
return -1;
27072684
}

0 commit comments

Comments
 (0)