Welcome to Level 3 (不容易啊...记下啦^_@)

博客欢迎用户进入Level 3,恭喜clin003,提醒查看Mod - X排名并登录Level 3论坛与其他人员交流,还给出Level 2和Level 3论坛的登录提示,以及Level 3简报相关内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Welcome to Level 3


Hey clin003, Congratulations! Don't forget to check your Mod-X ranking and access the level 3 forum to chat to other agents. Good luck with the next challenge. If you have any problems/comments mail me.


View your Mod-X ranking

Login to the level 2 Forum
Login to the level 3 Forum

Level 3 Briefing

继续努力中ing


pgbouncer/src/proto.c 里的部分源码如下: #include "bouncer.h" #include "scram.h" /* * parse protocol header from struct MBuf */ /* parses pkt header from buffer, returns false if failed */ bool get_header(struct MBuf *data, PktHdr *pkt) { unsigned type; uint32_t len; unsigned got; unsigned avail; uint16_t len16; uint8_t type8; uint32_t code; struct MBuf hdr; const uint8_t *ptr; mbuf_copy(data, &hdr); if (mbuf_avail_for_read(&hdr) < NEW_HEADER_LEN) { log_noise("get_header: less than 5 bytes available"); return false; } if (!mbuf_get_byte(&hdr, &type8)) return false; type = type8; if (type != 0) { /* wire length does not include type byte */ if (!mbuf_get_uint32be(&hdr, &len)) return false; len++; got = NEW_HEADER_LEN; } else { if (!mbuf_get_byte(&hdr, &type8)) return false; if (type8 != 0) { log_noise("get_header: unknown special pkt"); return false; } /* don&#39;t tolerate partial pkt */ if (mbuf_avail_for_read(&hdr) < OLD_HEADER_LEN - 2) { log_noise("get_header: less than 8 bytes for special pkt"); return false; } if (!mbuf_get_uint16be(&hdr, &len16)) return false; len = len16; if (!mbuf_get_uint32be(&hdr, &code)) return false; if (code == PKT_CANCEL) { type = PKT_CANCEL; } else if (code == PKT_SSLREQ) { type = PKT_SSLREQ; } else if (code == PKT_GSSENCREQ) { type = PKT_GSSENCREQ; } else if ((code >> 16) == 3 && (code & 0xFFFF) < 2) { type = PKT_STARTUP; } else if (code == PKT_STARTUP_V2) { type = PKT_STARTUP_V2; } else { log_noise("get_header: unknown special pkt: len=%u code=%u", len, code); return false; } got = OLD_HEADER_LEN; } /* don&#39;t believe nonsense */ if (len < got || len > cf_max_packet_size) return false; /* store pkt info */ pkt->type = type; pkt->len = len; /* fill pkt with only data for this packet */ if (len > mbuf_avail_for_read(data)) { avail = mbuf_avail_for_read(data); } else { avail = len; } if (!mbuf_slice(data, avail, &pkt->data)) return false; /* tag header as read */ return mbuf_get_bytes(&pkt->data, got, &ptr); } /* * Send error message packet to client. */ bool send_pooler_error(PgSocket *client, bool send_ready, const char *msg) { uint8_t tmpbuf[512]; PktBuf buf; if (cf_log_pooler_errors) slog_warning(client, "pooler error: %s", msg); pktbuf_static(&buf, tmpbuf, sizeof(tmpbuf)); pktbuf_write_generic(&buf, &#39;E&#39;, "cscscsc", &#39;S&#39;, "ERROR", &#39;C&#39;, "08P01", &#39;M&#39;, msg, 0); if (send_ready) pktbuf_write_ReadyForQuery(&buf); return pktbuf_send_immediate(&buf, client); } /* * Parse server error message and log it. */ void parse_server_error(PktHdr *pkt, const char **level_p, const char **msg_p) { const char *level = NULL, *msg = NULL, *val; uint8_t type; while (mbuf_avail_for_read(&pkt->data)) { if (!mbuf_get_byte(&pkt->data, &type)) break; if (type == 0) break; if (!mbuf_get_string(&pkt->data, &val)) break; if (type == &#39;S&#39;) { level = val; } else if (type == &#39;M&#39;) { msg = val; } } *level_p = level; *msg_p = msg; } void log_server_error(const char *note, PktHdr *pkt) { const char *level = NULL, *msg = NULL; parse_server_error(pkt, &level, &msg); if (!msg || !level) { log_error("%s: partial error message, cannot log", note); } else { log_error("%s: %s: %s", note, level, msg); } } /* * Preparation of welcome message for client connection. */ /* add another server parameter packet to cache */ bool add_welcome_parameter(PgPool *pool, const char *key, const char *val) { PktBuf *msg = pool->welcome_msg; if (pool->welcome_msg_ready) return true; if (!msg) { msg = pktbuf_dynamic(128); if (!msg) return false; pool->welcome_msg = msg; } /* first packet must be AuthOk */ if (msg->write_pos == 0) pktbuf_write_AuthenticationOk(msg); /* if not stored in ->orig_vars, write full packet */ if (!varcache_set(&pool->orig_vars, key, val)) pktbuf_write_ParameterStatus(msg, key, val); return !msg->failed; } /* all parameters processed */ void finish_welcome_msg(PgSocket *server) { PgPool *pool = server->pool; if (pool->welcome_msg_ready) return; pool->welcome_msg_ready = 1; } bool welcome_client(PgSocket *client) { int res; PgPool *pool = client->pool; const PktBuf *pmsg = pool->welcome_msg; PktBuf *msg; slog_noise(client, "P: welcome_client"); /* copy prepared stuff around */ msg = pktbuf_temp(); pktbuf_put_bytes(msg, pmsg->buf, pmsg->write_pos); /* fill vars */ varcache_fill_unset(&pool->orig_vars, client); varcache_add_params(msg, &client->vars); /* give each client its own cancel key */ get_random_bytes(client->cancel_key, 8); pktbuf_write_BackendKeyData(msg, client->cancel_key); /* finish */ pktbuf_write_ReadyForQuery(msg); if (msg->failed) { disconnect_client(client, true, "failed to prepare welcome message"); return false; } /* send all together */ res = pktbuf_send_immediate(msg, client); if (!res) { disconnect_client(client, true, "failed to send welcome message"); return false; } return true; } 大致讲解下
07-17
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值