6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina Pavel Březina <pbrezina@redhat.com>
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina Copyright (C) 2011 Red Hat
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina This program is free software; you can redistribute it and/or modify
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina it under the terms of the GNU General Public License as published by
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina the Free Software Foundation; either version 3 of the License, or
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina (at your option) any later version.
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina This program is distributed in the hope that it will be useful,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina GNU General Public License for more details.
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina You should have received a copy of the GNU General Public License
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březinastatic void sss_sudo_free_rules(unsigned int num_rules,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březinastatic void sss_sudo_free_attrs(unsigned int num_attrs,
9c6b680e55e00642bc3e644fd63e18e6c09ff110Pavel Březinastatic int sss_sudo_send_recv_generic(enum sss_cli_command command,
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina /* create query */
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina ret = sss_sudo_create_query(uid, username, &query_buf, &query_len);
9c6b680e55e00642bc3e644fd63e18e6c09ff110Pavel Březina /* send query and receive response */
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina ret = sss_sudo_make_request(command, &request,
9c6b680e55e00642bc3e644fd63e18e6c09ff110Pavel Březina /* parse structure */
9c6b680e55e00642bc3e644fd63e18e6c09ff110Pavel Březina ret = sss_sudo_parse_response((const char*)reply_buf, reply_len,
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina if (username == NULL || strlen(username) == 0) {
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina /* send query and receive response */
7379170a0860790f2739e07fffe3d6ec85264566Pavel Březina ret = sss_sudo_send_recv_generic(SSS_SUDO_GET_SUDORULES, uid, username,
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina if (username == NULL || strlen(username) == 0) {
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina return sss_sudo_send_recv_generic(SSS_SUDO_GET_DEFAULTS, uid, username,
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březinaint sss_sudo_create_query(uid_t uid, const char *username,
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina size_t username_len = strlen(username) * sizeof(char) + 1;
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina size_t data_len = sizeof(uid_t) + username_len;
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina data = (uint8_t*)malloc(data_len * sizeof(uint8_t));
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina SAFEALIGN_SET_VALUE(data, uid, uid_t, &offset);
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina memcpy(data + offset, username, username_len);
968e2bc3bb28458b25c3b19868ea50f0325d8b0aPavel Březinaint sss_sudo_get_values(struct sss_sudo_rule *e,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina for (i = 0; i < e->num_attrs; i++) {
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina values = calloc(attr->num_values + 1, sizeof(char*));
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina for (value = values; *value != NULL; value++) {
968e2bc3bb28458b25c3b19868ea50f0325d8b0aPavel Březinavoid sss_sudo_free_result(struct sss_sudo_result *result)
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina sss_sudo_free_rules(result->num_rules, result->rules);
968e2bc3bb28458b25c3b19868ea50f0325d8b0aPavel Březinavoid sss_sudo_free_rules(unsigned int num_rules, struct sss_sudo_rule *rules)
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina for (i = 0; i < num_rules; i++) {
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina sss_sudo_free_attrs(rule->num_attrs, rule->attrs);
968e2bc3bb28458b25c3b19868ea50f0325d8b0aPavel Březinavoid sss_sudo_free_attrs(unsigned int num_attrs, struct sss_sudo_attr *attrs)
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina for (i = 0; i < num_attrs; i++) {