a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina Pavel Březina <pbrezina@redhat.com>
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina Copyright (C) 2015 Red Hat
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina This program is free software; you can redistribute it and/or modify
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina it under the terms of the GNU General Public License as published by
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina the Free Software Foundation; either version 3 of the License, or
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina (at your option) any later version.
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina This program is distributed in the hope that it will be useful,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina GNU General Public License for more details.
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina You should have received a copy of the GNU General Public License
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina#define IS_STD_FILE(db) ((db)->file == stdin || (db)->file == stdout)
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina const char **_value)
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina if (line == NULL || *line == '\n' || *line == '\0') {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* There is nothing else to read. */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* Special case for empty value. */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* Value starts at current position. */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* Find next field delimiter. */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* There is no more field. Remove \n from the end. */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* Remove it and step one character further. */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse number [%d]: %s\n",
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaerrno_t sss_colondb_readline(TALLOC_CTX *mem_ctx,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina readchars = getline(&line, &linelen, db->file);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* Nothing was read. */
de1131abe5ba7aaeb59f81fc3a9cd2a71c0b52ddLukas Slebodnik DEBUG(SSSDBG_CRIT_FAILURE, "Unable to read line [%d]: %s\n",
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* Copy line to mem_ctx. */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina for (i = 0; table[i].type != SSS_COLONDB_SENTINEL; i++) {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina rest = read_field_as_uint32(rest, table[i].data.uint32);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina rest = read_field_as_string(rest, table[i].data.str);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Trying to process sentinel?!\n");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina if (rest == NULL && table[i + 1].type != SSS_COLONDB_SENTINEL) {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina "Line contains less values than expected!\n");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina } else if (rest != NULL && table[i + 1].type == SSS_COLONDB_SENTINEL) {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina "Line contains more values than expected!\n");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinaerrno_t sss_colondb_writeline(struct sss_colondb *db,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed.\n");
6977d7c84145ac69195be58b3330861b9b8a3b72Lukas Slebodnik DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed.\n");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina for (i = 0; table[i].type != SSS_COLONDB_SENTINEL; i++) {
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina line = talloc_asprintf_append(line, ":%u", table[i].data.uint32);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina line = talloc_asprintf_append(line, ":%s", table[i].data.str);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Trying to process sentinel?!\n");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina /* Remove starting : */
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina struct sss_colondb *db = talloc_get_type(pvt, struct sss_colondb);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinastatic FILE *open_db(const char *filename, enum sss_colondb_mode mode)
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina fp = filename == NULL ? stdin : fopen(filename, "r");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina fp = filename == NULL ? stdout : fopen(filename, "w");
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to open file %s [%d]: %s\n",
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březinastruct sss_colondb *sss_colondb_open(TALLOC_CTX *mem_ctx,
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina db = talloc_zero(mem_ctx, struct sss_colondb);
a76f63544533f0404f7711a10c1a621c6045df17Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero() failed\n");