diff --git a/src/common/request.c b/src/common/request.c --- a/src/common/request.c +++ b/src/common/request.c @@ -69,6 +69,35 @@ int distren_request_parse_version(struct return 0; } +int distren_request_pass(struct distren_request **req, void **data, const char *username, const char *pass) +{ + struct distren_request_pass *request_pass; + + distren_request_new(req, sizeof(struct distren_request_pass), DISTREN_REQUEST_PASS); + request_pass = malloc(sizeof(struct distren_request_pass)); + if(!request_pass || !*req) + { + if(*req) + distren_request_free(*req); + free(request_pass); + + return 1; + } + + /* + * The packet itself doesn't need the string's NULL terminator + * _unless_ if the string is shorter than the maximum length of the + * username or password. Thus, strncpy()'s behavior (not strlcpy()'s + * behavior) is _exactly_ what we want for this case. + */ + strncpy(request_pass->username, username, DISTREN_REQUEST_PASS_USERNAME_LEN); + strncpy(request_pass->pass, pass, DISTREN_REQUEST_PASS_PASS_LEN); + + *data = request_pass; + + return 0; +} + int distren_request_poing(struct distren_request **req, void **data, short is_ping, const void *poing_cookie, size_t poing_data_len) { enum distren_request_type type;