From d69d5c4f19dde14b3c4a81878eea1edd415057f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 17 Jan 2012 12:32:28 +0100
Subject: [PATCH 4/5] SUDO Integration - SUDO API can request only cn=defaults
 record

https://fedorahosted.org/sssd/ticket/1143
---
 src/sss_client/sss_sudo.exports |    1 +
 src/sss_client/sudo/sss_sudo.c  |   69 ++++++++++++++++++++++++--------------
 src/sss_client/sudo/sss_sudo.h  |    2 +
 3 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/src/sss_client/sss_sudo.exports b/src/sss_client/sss_sudo.exports
index 3f6bea3..644e012 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 01fdee0..68205c9 100644
--- a/src/sss_client/sudo/sss_sudo.c
+++ b/src/sss_client/sudo/sss_sudo.c
@@ -36,18 +36,43 @@ 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 recieve 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);
+    if (ret != EOK) {
+        return ret;
+    }
+
+    return EOK;
+}
+
 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 +87,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 1b55467..082c801 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,
-- 
1.7.6.5
