sudo_testcli.c revision f8c829e72968b574e1c9bda96f4d5f206622358f
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen Pavel Březina <pbrezina@redhat.com>
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen Copyright (C) 2011 Red Hat
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen This program is free software; you can redistribute it and/or modify
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen it under the terms of the GNU General Public License as published by
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen the Free Software Foundation; either version 3 of the License, or
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen (at your option) any later version.
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen This program is distributed in the hope that it will be useful,
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen GNU General Public License for more details.
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen You should have received a copy of the GNU General Public License
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenint create_query(const char *username, char **_query, int *_query_len);
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainenvoid print_sss_result(struct sss_result *result);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen fprintf(stderr, "Usage: sss_sudo_cli username\n");
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen /* create query */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen ret = create_query(username, &query, &query_len);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen fprintf(stderr, "Unable to create query: %s\n", strerror(ret));
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen /* send query and recieve response */
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen ret = sss_sudo_make_request(SSS_SUDO_GET_SUDORULES, &request, &reply_buf,
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen fprintf(stderr, "Unable to contact SSSD responder: %s\n", strerror(errnop));
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen for (i = 0; i < reply_len; i++) {
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen /* get sss_result - it will send new query to responder */
dee43975a70bcdb9dc83d34d6a2b177d37bb7194Timo Sirainen ret = sss_sudo_get_result(username, &error, &result);
24e5e4526d8f5cbc056ab97fd0d154d0936d7a5eTimo Sirainen fprintf(stderr, "Usss_sudo_get_result() failed: %s\n", strerror(ret));
c9dea5c23355dea35c6fa423de69f6507852efe4Timo Sirainenint create_query(const char *username, char **_query, int *_query_len)
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen data = (char*)malloc(data_len * sizeof(char));
4cf5f0934a25f1fd58f2780108f9d6498c455a1fTimo Sirainenvoid print_sss_result(struct sss_result *result)
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen printf("Number of rules: %d\n", result->num_rules);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen printf("=== Rule %d has %d attributes\n", i, rule->num_attrs);
4ece61edd7c266a4b8f3b290a7f0a3cb3d13ca0fTimo Sirainen printf(" === Attribute named %s has %d values:\n", attr->name,