Changeset View
Standalone View
monitor_wrap.c
Show First 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | mm_key_sign(struct sshkey *key, u_char **sigp, u_int *lenp, | ||||
debug3("%s: waiting for MONITOR_ANS_SIGN", __func__); | debug3("%s: waiting for MONITOR_ANS_SIGN", __func__); | ||||
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m); | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_SIGN, &m); | ||||
*sigp = buffer_get_string(&m, lenp); | *sigp = buffer_get_string(&m, lenp); | ||||
buffer_free(&m); | buffer_free(&m); | ||||
return (0); | return (0); | ||||
} | } | ||||
login_cap_t * | |||||
mm_login_getpwclass(const struct passwd *pwent) | |||||
{ | |||||
Buffer m; | |||||
login_cap_t *lc; | |||||
debug3("%s entering", __func__); | |||||
buffer_init(&m); | |||||
buffer_put_passwd(&m, pwent); | |||||
cem: This can be `sizeof(*pwent)` | |||||
Not Done Inline ActionsI'll fix this. naito.yuichiro_gmail.com: I'll fix this. | |||||
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GETPWCLASS, &m); | |||||
debug3("%s: waiting for MONITOR_ANS_GETPWCLASS", __func__); | |||||
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GETPWCLASS, &m); | |||||
if (buffer_get_char(&m) == 0) { | |||||
lc = NULL; | |||||
goto out; | |||||
} | |||||
Not Done Inline ActionsI have two comments about serialization of struct passwd.
cem: I have two comments about serialization of `struct passwd`.
1. It could be moved to a… | |||||
Not Done Inline ActionsI will make new functions to share all struct passwd operations. In these functions, I will get avoid to send pointer values by sending all member values. If a new pointer member is added, it will be NULL in the receive function. Because mm_answer_pwnamallow has same risk. We can fix both of them. naito.yuichiro_gmail.com: I will make new functions to share all `struct passwd` operations. In these functions, I will… | |||||
lc = malloc(sizeof(*lc)); | |||||
Not Done Inline ActionsCast is not needed in C :-) cem: Cast is not needed in C :-) | |||||
Not Done Inline ActionsYeah. I'll fix too. naito.yuichiro_gmail.com: Yeah. I'll fix too. | |||||
if (lc == NULL) | |||||
fatal("%s: fail to allocate memory", __func__); | |||||
lc->lc_class = buffer_get_string(&m, NULL); | |||||
lc->lc_cap = buffer_get_string(&m, NULL); | |||||
lc->lc_style = buffer_get_string(&m, NULL); | |||||
out: | |||||
buffer_free(&m); | |||||
return (lc); | |||||
} | |||||
Not Done Inline ActionsCan be sizeof(*lc) cem: Can be `sizeof(*lc)` | |||||
Not Done Inline ActionsI'll fix this. naito.yuichiro_gmail.com: I'll fix this. | |||||
void | |||||
Not Done Inline Actionslogin_cap_t is composed only of string pointers — I don't think it makes sense to send the struct at all. cem: login_cap_t is composed only of string pointers — I don't think it makes sense to send the… | |||||
Not Done Inline ActionsAh, there is no meaning sending pointers. I'll remove the sending login_cap_t code. naito.yuichiro_gmail.com: Ah, there is no meaning sending pointers. I'll remove the sending `login_cap_t` code. | |||||
mm_login_close(login_cap_t *lc) | |||||
{ | |||||
if (lc != NULL) { | |||||
Not Done Inline ActionsI don't know about openssh style. But FreeBSD style suggests comparing pointers against NULL instead of treating them as boolean values. So e.g. if (lc != NULL) {. I don't feel strongly about this — current code is quite clear to me. cem: I don't know about openssh style. But FreeBSD style suggests comparing pointers against NULL… | |||||
Not Done Inline ActionsI referred to source code of login_close(3). https://svnweb.freebsd.org/base/head/lib/libutil/login_cap.c?view=markup#l155 In this function, if (lc) { is written for checking pointer. naito.yuichiro_gmail.com: I referred to source code of `login_close(3)`.
https://svnweb.freebsd. | |||||
free(lc->lc_style); | |||||
free(lc->lc_class); | |||||
free(lc->lc_cap); | |||||
free(lc); | |||||
} | |||||
} | |||||
struct passwd * | struct passwd * | ||||
mm_getpwnamallow(const char *username) | mm_getpwnamallow(const char *username) | ||||
{ | { | ||||
struct ssh *ssh = active_state; /* XXX */ | struct ssh *ssh = active_state; /* XXX */ | ||||
Buffer m; | Buffer m; | ||||
struct passwd *pw; | struct passwd *pw; | ||||
u_int len, i; | u_int len, i; | ||||
ServerOptions *newopts; | ServerOptions *newopts; | ||||
debug3("%s entering", __func__); | debug3("%s entering", __func__); | ||||
buffer_init(&m); | buffer_init(&m); | ||||
buffer_put_cstring(&m, username); | buffer_put_cstring(&m, username); | ||||
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m); | mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_PWNAM, &m); | ||||
debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__); | debug3("%s: waiting for MONITOR_ANS_PWNAM", __func__); | ||||
mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m); | mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_PWNAM, &m); | ||||
if (buffer_get_char(&m) == 0) { | if (buffer_get_char(&m) == 0) { | ||||
pw = NULL; | pw = NULL; | ||||
goto out; | goto out; | ||||
} | } | ||||
pw = buffer_get_string(&m, &len); | pw = buffer_get_passwd(&m); | ||||
if (len != sizeof(struct passwd)) | if (pw == NULL) | ||||
fatal("%s: struct passwd size mismatch", __func__); | fatal("%s: receive struct passwd failed", __func__); | ||||
Not Done Inline ActionsMessage may be too specific now. cem: Message may be too specific now. | |||||
Not Done Inline ActionsI'll fix this too. naito.yuichiro_gmail.com: I'll fix this too. | |||||
pw->pw_name = buffer_get_string(&m, NULL); | |||||
pw->pw_passwd = buffer_get_string(&m, NULL); | |||||
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS | |||||
pw->pw_gecos = buffer_get_string(&m, NULL); | |||||
#endif | |||||
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS | |||||
pw->pw_class = buffer_get_string(&m, NULL); | |||||
#endif | |||||
pw->pw_dir = buffer_get_string(&m, NULL); | |||||
pw->pw_shell = buffer_get_string(&m, NULL); | |||||
out: | out: | ||||
/* copy options block as a Match directive may have changed some */ | /* copy options block as a Match directive may have changed some */ | ||||
newopts = buffer_get_string(&m, &len); | newopts = buffer_get_string(&m, &len); | ||||
if (len != sizeof(*newopts)) | if (len != sizeof(*newopts)) | ||||
fatal("%s: option block size mismatch", __func__); | fatal("%s: option block size mismatch", __func__); | ||||
#define M_CP_STROPT(x) do { \ | #define M_CP_STROPT(x) do { \ | ||||
▲ Show 20 Lines • Show All 680 Lines • Show Last 20 Lines |
This can be sizeof(*pwent)