diff options
-rw-r--r-- | src/sss_client/sss_sudo.exports | 1 | ||||
-rw-r--r-- | src/sss_client/sudo/sss_sudo.c | 67 | ||||
-rw-r--r-- | src/sss_client/sudo/sss_sudo.h | 2 |
3 files changed, 44 insertions, 26 deletions
diff --git a/src/sss_client/sss_sudo.exports b/src/sss_client/sss_sudo.exports index 3f6bea30c..644e0125d 100644 --- a/src/sss_client/sss_sudo.exports +++ b/src/sss_client/sss_sudo.exports @@ -4,6 +4,7 @@ EXPORTED { global: sss_sudo_send_recv; + sss_sudo_send_recv_defaults; sss_sudo_free_result; sss_sudo_get_values; sss_sudo_free_values; diff --git a/src/sss_client/sudo/sss_sudo.c b/src/sss_client/sudo/sss_sudo.c index 01fdee05c..3277d9f8a 100644 --- a/src/sss_client/sudo/sss_sudo.c +++ b/src/sss_client/sudo/sss_sudo.c @@ -36,18 +36,41 @@ static void sss_sudo_free_rules(unsigned int num_rules, static void sss_sudo_free_attrs(unsigned int num_attrs, struct sss_attr *attrs); +static int sss_sudo_send_recv_generic(enum sss_cli_command command, + struct sss_cli_req_data *request, + uint32_t *_error, + struct sss_result **_result) +{ + uint8_t *reply_buf = NULL; + size_t reply_len = 0; + int errnop = 0; + int ret = 0; + + /* send query and receive response */ + + errnop = 0; + ret = sss_sudo_make_request(command, request, + &reply_buf, &reply_len, &errnop); + if (errnop != EOK) { + return errnop; + } + + /* parse structure */ + + ret = sss_sudo_parse_response((const char*)reply_buf, reply_len, + _result, _error); + + free(reply_buf); + return ret; +} + int sss_sudo_send_recv(const char *username, uint32_t *_error, struct sss_result **_result) { - struct sss_result *result = NULL; struct sss_cli_req_data request; char *query = NULL; int query_len = 0; - uint8_t *reply_buf = NULL; - size_t reply_len = 0; - uint32_t responder_error = 0; - int errnop = 0; int ret = 0; /* create query */ @@ -62,33 +85,25 @@ int sss_sudo_send_recv(const char *username, /* send query and recieve response */ - errnop = 0; - ret = sss_sudo_make_request(SSS_SUDO_GET_SUDORULES, &request, - &reply_buf, &reply_len, &errnop); - if (errnop != EOK) { - ret = errnop; - goto done; - } - - /* parse and print structure */ - - ret = sss_sudo_parse_response((const char*)reply_buf, reply_len, - &result, &responder_error); - if (ret != EOK) { - goto done; - } - - *_error = responder_error; - *_result = result; - - ret = EOK; + ret = sss_sudo_send_recv_generic(SSS_SUDO_GET_SUDORULES, &request, + _error, _result); done: free(query); - return ret; } +int sss_sudo_send_recv_defaults(uint32_t *_error, struct sss_result **_result) +{ + struct sss_cli_req_data request; + + request.len = 0; + request.data = (const void*)NULL; + + return sss_sudo_send_recv_generic(SSS_SUDO_GET_DEFAULTS, &request, + _error, _result); +} + int sss_sudo_create_query(const char *username, char **_query, int *_query_len) { char *data = NULL; diff --git a/src/sss_client/sudo/sss_sudo.h b/src/sss_client/sudo/sss_sudo.h index 1b5546786..082c8015a 100644 --- a/src/sss_client/sudo/sss_sudo.h +++ b/src/sss_client/sudo/sss_sudo.h @@ -49,6 +49,8 @@ int sss_sudo_send_recv(const char *username, uint32_t *_error, struct sss_result **_result); +int sss_sudo_send_recv_defaults(uint32_t *_error, struct sss_result **_result); + void sss_sudo_free_result(struct sss_result *result); int sss_sudo_get_values(struct sss_rule *e, |