diff --git a/libipm/scp.c b/libipm/scp.c index c090bc50..0e96a192 100644 --- a/libipm/scp.c +++ b/libipm/scp.c @@ -649,6 +649,46 @@ scp_get_list_sessions_response( /*****************************************************************************/ +int +scp_send_create_sockdir_request(struct trans *trans) +{ + return libipm_msg_out_simple_send( + trans, + (int)E_SCP_CREATE_SOCKDIR_REQUEST, + NULL); +} + + +/*****************************************************************************/ + +int +scp_send_create_sockdir_response(struct trans *trans, + enum scp_create_sockdir_status status) +{ + return libipm_msg_out_simple_send( + trans, + (int)E_SCP_CREATE_SOCKDIR_RESPONSE, + "i", status); +} + +/*****************************************************************************/ + +int +scp_get_create_sockdir_response(struct trans *trans, + enum scp_create_sockdir_status *status) +{ + int32_t i_status = 0; + int rv = libipm_msg_in_parse(trans, "i", &i_status); + if (rv == 0) + { + *status = (enum scp_create_sockdir_status)i_status; + } + + return rv; +} + +/*****************************************************************************/ + int scp_send_close_connection_request(struct trans *trans) { diff --git a/libipm/scp.h b/libipm/scp.h index 386493a0..1ec51e82 100644 --- a/libipm/scp.h +++ b/libipm/scp.h @@ -59,6 +59,9 @@ enum scp_msg_code E_SCP_LIST_SESSIONS_REQUEST, E_SCP_LIST_SESSIONS_RESPONSE, + E_SCP_CREATE_SOCKDIR_REQUEST, + E_SCP_CREATE_SOCKDIR_RESPONSE, + E_SCP_CLOSE_CONNECTION_REQUEST // No E_SCP_CLOSE_CONNECTION_RESPONSE }; @@ -456,6 +459,43 @@ scp_get_list_sessions_response( enum scp_list_sessions_status *status, struct scp_session_info **info); +/** + * Send an E_SCP_CREATE_SOCKDIR_REQUEST (SCP client) + * + * @param trans SCP transport + * @return != 0 for error + * + * In some configurations, chansrv is not started by sesman. In this + * instance, it may be necessary for the unprivileged sesman process to + * ask sesman to create the sockets dir so sesman can populate it. + * + * Server replies with E_SCP_CREATE_SOCKDIR_RESPONSE + */ +int +scp_send_create_sockdir_request(struct trans *trans); + +/** + * Send an E_SCP_CREATE_SOCKDIR_RESPONSE (SCP server) + * + * @param trans SCP transport + * @param status Status of request + * @return != 0 for error + */ +int +scp_send_create_sockdir_response(struct trans *trans, + enum scp_create_sockdir_status status); + +/** + * Parse an incoming E_SCP_CREATE_SOCKDIR_RESPONSE (SCP client) + * + * @param trans SCP transport + * @param[out] status Status of request + * @return != 0 for error + */ +int +scp_get_create_sockdir_response(struct trans *trans, + enum scp_create_sockdir_status *status); + /** * Send an E_CLOSE_CONNECTION_REQUEST (SCP client) * diff --git a/libipm/scp_application_types.h b/libipm/scp_application_types.h index 89c7ca8a..ab6e8e0e 100644 --- a/libipm/scp_application_types.h +++ b/libipm/scp_application_types.h @@ -136,5 +136,23 @@ enum scp_list_sessions_status E_SCP_LS_NO_MEMORY }; +/** + * Status of a create sockdir message + */ +enum scp_create_sockdir_status +{ + E_SCP_CS_OK = 0, + + /** + * Client hasn't logged in yet + */ + E_SCP_CS_NOT_LOGGED_IN = 100, + + /** + * sesman failed to create the directory + */ + E_SCP_CS_OTHER_ERROR +}; + #endif /* SCP_APPLICATION_TYPES_H */ diff --git a/libipm/scp_sync.c b/libipm/scp_sync.c index 8312e9cb..cf565335 100644 --- a/libipm/scp_sync.c +++ b/libipm/scp_sync.c @@ -166,3 +166,45 @@ scp_sync_list_sessions_request(struct trans *t) return sessions; } + +/*****************************************************************************/ +int +scp_sync_create_sockdir_request(struct trans *t) +{ + int rv = scp_send_create_sockdir_request(t); + if (rv == 0) + { + rv = scp_sync_wait_specific(t, E_SCP_CREATE_SOCKDIR_RESPONSE); + if (rv == 0) + { + enum scp_create_sockdir_status status; + rv = scp_get_create_sockdir_response(t, &status); + if (rv == 0) + { + switch (status) + { + case E_SCP_CS_OK: + break; + + case E_SCP_CS_NOT_LOGGED_IN: + LOG(LOG_LEVEL_ERROR, "sesman reported not-logged-in"); + rv = 1; + break; + + case E_SCP_CS_OTHER_ERROR: + LOG(LOG_LEVEL_ERROR, + "sesman reported fail on create directory"); + rv = 1; + break; + } + } + scp_msg_in_reset(t); // Done with this message + if (!rv) + { + (void)scp_send_close_connection_request(t); + } + } + + } + return rv; +} diff --git a/libipm/scp_sync.h b/libipm/scp_sync.h index b99d3b99..9b36ce85 100644 --- a/libipm/scp_sync.h +++ b/libipm/scp_sync.h @@ -86,4 +86,16 @@ scp_sync_uds_login_request(struct trans *t); struct list * scp_sync_list_sessions_request(struct trans *t); +/** + * Send sockdir creation request to sesman and wait for answer + * + * @param t SCP transport + * @return 0 for successful response from sesman + * + * If non-zero is returned, the scp_connection has been closed (if + * appropriate) and simply remains to be deleted. + */ +int +scp_sync_create_sockdir_request(struct trans *t); + #endif /* SCP_SYNC_H */