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 int sss_sudo_parse_rule(const char *message,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březinastatic int sss_sudo_parse_attr(const char *message,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březinastatic int sss_sudo_parse_uint32(const char *message,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březinastatic int sss_sudo_parse_string(const char *message,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březinaint sss_sudo_parse_response(const char *message,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina /* error code */
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_uint32(message, message_len, &cursor, _error);
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina if (ret != EOK || *_error != SSS_SUDO_ERROR_OK) {
7379170a0860790f2739e07fffe3d6ec85264566Pavel Březina /* domain name - deprecated
7379170a0860790f2739e07fffe3d6ec85264566Pavel Březina * it won't be used, but we will read it anyway to ease parsing
7379170a0860790f2739e07fffe3d6ec85264566Pavel Březina * TODO: when possible change the protocol */
46d3d2c731e8c7e138462e5b60a39a279dc77d81Pavel Březina ret = sss_sudo_parse_string(message, message_len, &cursor, &domainname);
968e2bc3bb28458b25c3b19868ea50f0325d8b0aPavel Březina result = malloc(sizeof(struct sss_sudo_result));
a24f7f1275b3bd9cf4adbb0b4ed7ab86357e66faPavel Březina memset(result, 0, sizeof(struct sss_sudo_result));
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina /* rules_num */
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_uint32(message, message_len,
968e2bc3bb28458b25c3b19868ea50f0325d8b0aPavel Březina result->rules = calloc(result->num_rules, sizeof(struct sss_sudo_rule));
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_rule(message, message_len,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina /* attrs_num */
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_uint32(message, message_len,
968e2bc3bb28458b25c3b19868ea50f0325d8b0aPavel Březina _rule->attrs = calloc(_rule->num_attrs, sizeof(struct sss_sudo_attr));
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_attr(message, message_len,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_string(message, message_len, _cursor, &str);
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina /* values_num */
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_uint32(message, message_len,
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina _attr->values = calloc(_attr->num_values, sizeof(const char*));
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina ret = sss_sudo_parse_string(message, message_len, _cursor, &str);
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina if (start_pos + sizeof(uint32_t) > message_len) {
f643754db81eeade60485bbe3d80324d889cc4f3Pavel Březina /* expanded SAFEALIGN_COPY_UINT32 macro from util.h */
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina memcpy(_number, message + start_pos, sizeof(uint32_t));
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina /* the string exceeds message length */
6f701a4dc295ddc997ba5190a3cd72d948d799dcPavel Březina /* go after \0 */