chiark / gitweb /
shared/conf-parser: add config_parse_many which takes strv with dirs
[elogind.git] / src / shared / conf-parser.c
1 /***
2   This file is part of systemd.
3
4   Copyright 2010 Lennart Poettering
5
6   systemd is free software; you can redistribute it and/or modify it
7   under the terms of the GNU Lesser General Public License as published by
8   the Free Software Foundation; either version 2.1 of the License, or
9   (at your option) any later version.
10
11   systemd is distributed in the hope that it will be useful, but
12   WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14   Lesser General Public License for more details.
15
16   You should have received a copy of the GNU Lesser General Public License
17   along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <errno.h>
21 #include <limits.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
27
28 #include "alloc-util.h"
29 #include "conf-files.h"
30 #include "conf-parser.h"
31 #include "extract-word.h"
32 #include "fd-util.h"
33 #include "fs-util.h"
34 #include "log.h"
35 #include "macro.h"
36 #include "parse-util.h"
37 #include "path-util.h"
38 #include "process-util.h"
39 #include "signal-util.h"
40 #include "string-util.h"
41 #include "strv.h"
42 #include "syslog-util.h"
43 #include "time-util.h"
44 #include "utf8.h"
45
46 int config_item_table_lookup(
47                 const void *table,
48                 const char *section,
49                 const char *lvalue,
50                 ConfigParserCallback *func,
51                 int *ltype,
52                 void **data,
53                 void *userdata) {
54
55         const ConfigTableItem *t;
56
57         assert(table);
58         assert(lvalue);
59         assert(func);
60         assert(ltype);
61         assert(data);
62
63         for (t = table; t->lvalue; t++) {
64
65                 if (!streq(lvalue, t->lvalue))
66                         continue;
67
68                 if (!streq_ptr(section, t->section))
69                         continue;
70
71                 *func = t->parse;
72                 *ltype = t->ltype;
73                 *data = t->data;
74                 return 1;
75         }
76
77         return 0;
78 }
79
80 int config_item_perf_lookup(
81                 const void *table,
82                 const char *section,
83                 const char *lvalue,
84                 ConfigParserCallback *func,
85                 int *ltype,
86                 void **data,
87                 void *userdata) {
88
89         ConfigPerfItemLookup lookup = (ConfigPerfItemLookup) table;
90         const ConfigPerfItem *p;
91
92         assert(table);
93         assert(lvalue);
94         assert(func);
95         assert(ltype);
96         assert(data);
97
98         if (!section)
99                 p = lookup(lvalue, strlen(lvalue));
100         else {
101                 char *key;
102
103                 key = strjoin(section, ".", lvalue, NULL);
104                 if (!key)
105                         return -ENOMEM;
106
107                 p = lookup(key, strlen(key));
108                 free(key);
109         }
110
111         if (!p)
112                 return 0;
113
114         *func = p->parse;
115         *ltype = p->ltype;
116         *data = (uint8_t*) userdata + p->offset;
117         return 1;
118 }
119
120 /* Run the user supplied parser for an assignment */
121 static int next_assignment(const char *unit,
122                            const char *filename,
123                            unsigned line,
124                            ConfigItemLookup lookup,
125                            const void *table,
126                            const char *section,
127                            unsigned section_line,
128                            const char *lvalue,
129                            const char *rvalue,
130                            bool relaxed,
131                            void *userdata) {
132
133         ConfigParserCallback func = NULL;
134         int ltype = 0;
135         void *data = NULL;
136         int r;
137
138         assert(filename);
139         assert(line > 0);
140         assert(lookup);
141         assert(lvalue);
142         assert(rvalue);
143
144         r = lookup(table, section, lvalue, &func, &ltype, &data, userdata);
145         if (r < 0)
146                 return r;
147
148         if (r > 0) {
149                 if (func)
150                         return func(unit, filename, line, section, section_line,
151                                     lvalue, ltype, rvalue, data, userdata);
152
153                 return 0;
154         }
155
156         /* Warn about unknown non-extension fields. */
157         if (!relaxed && !startswith(lvalue, "X-"))
158                 log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown lvalue '%s' in section '%s'", lvalue, section);
159
160         return 0;
161 }
162
163 /* Parse a variable assignment line */
164 static int parse_line(const char* unit,
165                       const char *filename,
166                       unsigned line,
167                       const char *sections,
168                       ConfigItemLookup lookup,
169                       const void *table,
170                       bool relaxed,
171                       bool allow_include,
172                       char **section,
173                       unsigned *section_line,
174                       bool *section_ignored,
175                       char *l,
176                       void *userdata) {
177
178         char *e;
179
180         assert(filename);
181         assert(line > 0);
182         assert(lookup);
183         assert(l);
184
185         l = strstrip(l);
186
187         if (!*l)
188                 return 0;
189
190         if (strchr(COMMENTS "\n", *l))
191                 return 0;
192
193         if (startswith(l, ".include ")) {
194                 _cleanup_free_ char *fn = NULL;
195
196                 /* .includes are a bad idea, we only support them here
197                  * for historical reasons. They create cyclic include
198                  * problems and make it difficult to detect
199                  * configuration file changes with an easy
200                  * stat(). Better approaches, such as .d/ drop-in
201                  * snippets exist.
202                  *
203                  * Support for them should be eventually removed. */
204
205                 if (!allow_include) {
206                         log_syntax(unit, LOG_ERR, filename, line, 0, ".include not allowed here. Ignoring.");
207                         return 0;
208                 }
209
210                 fn = file_in_same_dir(filename, strstrip(l+9));
211                 if (!fn)
212                         return -ENOMEM;
213
214                 return config_parse(unit, fn, NULL, sections, lookup, table, relaxed, false, false, userdata);
215         }
216
217         if (*l == '[') {
218                 size_t k;
219                 char *n;
220
221                 k = strlen(l);
222                 assert(k > 0);
223
224                 if (l[k-1] != ']') {
225                         log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid section header '%s'", l);
226                         return -EBADMSG;
227                 }
228
229                 n = strndup(l+1, k-2);
230                 if (!n)
231                         return -ENOMEM;
232
233                 if (sections && !nulstr_contains(sections, n)) {
234
235                         if (!relaxed && !startswith(n, "X-"))
236                                 log_syntax(unit, LOG_WARNING, filename, line, 0, "Unknown section '%s'. Ignoring.", n);
237
238                         free(n);
239                         *section = mfree(*section);
240                         *section_line = 0;
241                         *section_ignored = true;
242                 } else {
243                         free(*section);
244                         *section = n;
245                         *section_line = line;
246                         *section_ignored = false;
247                 }
248
249                 return 0;
250         }
251
252         if (sections && !*section) {
253
254                 if (!relaxed && !*section_ignored)
255                         log_syntax(unit, LOG_WARNING, filename, line, 0, "Assignment outside of section. Ignoring.");
256
257                 return 0;
258         }
259
260         e = strchr(l, '=');
261         if (!e) {
262                 log_syntax(unit, LOG_WARNING, filename, line, 0, "Missing '='.");
263                 return -EINVAL;
264         }
265
266         *e = 0;
267         e++;
268
269         return next_assignment(unit,
270                                filename,
271                                line,
272                                lookup,
273                                table,
274                                *section,
275                                *section_line,
276                                strstrip(l),
277                                strstrip(e),
278                                relaxed,
279                                userdata);
280 }
281
282 /* Go through the file and parse each line */
283 int config_parse(const char *unit,
284                  const char *filename,
285                  FILE *f,
286                  const char *sections,
287                  ConfigItemLookup lookup,
288                  const void *table,
289                  bool relaxed,
290                  bool allow_include,
291                  bool warn,
292                  void *userdata) {
293
294         _cleanup_free_ char *section = NULL, *continuation = NULL;
295         _cleanup_fclose_ FILE *ours = NULL;
296         unsigned line = 0, section_line = 0;
297         bool section_ignored = false, allow_bom = true;
298         int r;
299
300         assert(filename);
301         assert(lookup);
302
303         if (!f) {
304                 f = ours = fopen(filename, "re");
305                 if (!f) {
306                         /* Only log on request, except for ENOENT,
307                          * since we return 0 to the caller. */
308                         if (warn || errno == ENOENT)
309                                 log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
310                                          "Failed to open configuration file '%s': %m", filename);
311                         return errno == ENOENT ? 0 : -errno;
312                 }
313         }
314
315         fd_warn_permissions(filename, fileno(f));
316
317         for (;;) {
318                 char buf[LINE_MAX], *l, *p, *c = NULL, *e;
319                 bool escaped = false;
320
321                 if (!fgets(buf, sizeof buf, f)) {
322                         if (feof(f))
323                                 break;
324
325                         return log_error_errno(errno, "Failed to read configuration file '%s': %m", filename);
326                 }
327
328                 l = buf;
329                 if (allow_bom && startswith(l, UTF8_BYTE_ORDER_MARK))
330                         l += strlen(UTF8_BYTE_ORDER_MARK);
331                 allow_bom = false;
332
333                 truncate_nl(l);
334
335                 if (continuation) {
336                         c = strappend(continuation, l);
337                         if (!c) {
338                                 if (warn)
339                                         log_oom();
340                                 return -ENOMEM;
341                         }
342
343                         continuation = mfree(continuation);
344                         p = c;
345                 } else
346                         p = l;
347
348                 for (e = p; *e; e++) {
349                         if (escaped)
350                                 escaped = false;
351                         else if (*e == '\\')
352                                 escaped = true;
353                 }
354
355                 if (escaped) {
356                         *(e-1) = ' ';
357
358                         if (c)
359                                 continuation = c;
360                         else {
361                                 continuation = strdup(l);
362                                 if (!continuation) {
363                                         if (warn)
364                                                 log_oom();
365                                         return -ENOMEM;
366                                 }
367                         }
368
369                         continue;
370                 }
371
372                 r = parse_line(unit,
373                                filename,
374                                ++line,
375                                sections,
376                                lookup,
377                                table,
378                                relaxed,
379                                allow_include,
380                                &section,
381                                &section_line,
382                                &section_ignored,
383                                p,
384                                userdata);
385                 free(c);
386
387                 if (r < 0) {
388                         if (warn)
389                                 log_warning_errno(r, "Failed to parse file '%s': %m",
390                                                   filename);
391                         return r;
392                 }
393         }
394
395         return 0;
396 }
397
398 static int config_parse_many_files(
399                 const char *conf_file,
400                 char **files,
401                 const char *sections,
402                 ConfigItemLookup lookup,
403                 const void *table,
404                 bool relaxed,
405                 void *userdata) {
406
407         char **fn;
408         int r;
409
410         if (conf_file) {
411                 r = config_parse(NULL, conf_file, NULL, sections, lookup, table, relaxed, false, true, userdata);
412                 if (r < 0)
413                         return r;
414         }
415
416         STRV_FOREACH(fn, files) {
417                 r = config_parse(NULL, *fn, NULL, sections, lookup, table, relaxed, false, true, userdata);
418                 if (r < 0)
419                         return r;
420         }
421
422         return 0;
423 }
424
425 /* Parse each config file in the directories specified as nulstr. */
426 int config_parse_many_nulstr(
427                 const char *conf_file,
428                 const char *conf_file_dirs,
429                 const char *sections,
430                 ConfigItemLookup lookup,
431                 const void *table,
432                 bool relaxed,
433                 void *userdata) {
434
435         _cleanup_strv_free_ char **files = NULL;
436         int r;
437
438         r = conf_files_list_nulstr(&files, ".conf", NULL, conf_file_dirs);
439         if (r < 0)
440                 return r;
441
442         return config_parse_many_files(conf_file, files,
443                                        sections, lookup, table, relaxed, userdata);
444 }
445
446 /* Parse each config file in the directories specified as strv. */
447 int config_parse_many(
448                 const char *conf_file,
449                 const char* const* conf_file_dirs,
450                 const char *dropin_dirname,
451                 const char *sections,
452                 ConfigItemLookup lookup,
453                 const void *table,
454                 bool relaxed,
455                 void *userdata) {
456
457         _cleanup_strv_free_ char **dropin_dirs = NULL;
458         _cleanup_strv_free_ char **files = NULL;
459         const char *suffix;
460         int r;
461
462         suffix = strjoina("/", dropin_dirname);
463         r = strv_extend_strv_concat(&dropin_dirs, (char**) conf_file_dirs, suffix);
464         if (r < 0)
465                 return r;
466
467         r = conf_files_list_strv(&files, ".conf", NULL, (const char* const*) dropin_dirs);
468         if (r < 0)
469                 return r;
470
471         return config_parse_many_files(conf_file, files,
472                                        sections, lookup, table, relaxed, userdata);
473 }
474
475 #define DEFINE_PARSER(type, vartype, conv_func)                         \
476         int config_parse_##type(                                        \
477                         const char *unit,                               \
478                         const char *filename,                           \
479                         unsigned line,                                  \
480                         const char *section,                            \
481                         unsigned section_line,                          \
482                         const char *lvalue,                             \
483                         int ltype,                                      \
484                         const char *rvalue,                             \
485                         void *data,                                     \
486                         void *userdata) {                               \
487                                                                         \
488                 vartype *i = data;                                      \
489                 int r;                                                  \
490                                                                         \
491                 assert(filename);                                       \
492                 assert(lvalue);                                         \
493                 assert(rvalue);                                         \
494                 assert(data);                                           \
495                                                                         \
496                 r = conv_func(rvalue, i);                               \
497                 if (r < 0)                                              \
498                         log_syntax(unit, LOG_ERR, filename, line, r,    \
499                                    "Failed to parse %s value, ignoring: %s", \
500                                    #type, rvalue);                      \
501                                                                         \
502                 return 0;                                               \
503         }                                                               \
504         struct __useless_struct_to_allow_trailing_semicolon__
505
506 DEFINE_PARSER(int, int, safe_atoi);
507 DEFINE_PARSER(long, long, safe_atoli);
508 DEFINE_PARSER(uint16, uint16_t, safe_atou16);
509 DEFINE_PARSER(uint32, uint32_t, safe_atou32);
510 DEFINE_PARSER(uint64, uint64_t, safe_atou64);
511 DEFINE_PARSER(unsigned, unsigned, safe_atou);
512 DEFINE_PARSER(double, double, safe_atod);
513 #if 0 /// UNNEEDED by elogind
514 DEFINE_PARSER(nsec, nsec_t, parse_nsec);
515 #endif // 0
516 DEFINE_PARSER(sec, usec_t, parse_sec);
517 DEFINE_PARSER(mode, mode_t, parse_mode);
518
519 int config_parse_iec_size(const char* unit,
520                             const char *filename,
521                             unsigned line,
522                             const char *section,
523                             unsigned section_line,
524                             const char *lvalue,
525                             int ltype,
526                             const char *rvalue,
527                             void *data,
528                             void *userdata) {
529
530         size_t *sz = data;
531         uint64_t v;
532         int r;
533
534         assert(filename);
535         assert(lvalue);
536         assert(rvalue);
537         assert(data);
538
539         r = parse_size(rvalue, 1024, &v);
540         if (r < 0 || (uint64_t) (size_t) v != v) {
541                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue);
542                 return 0;
543         }
544
545         *sz = (size_t) v;
546         return 0;
547 }
548
549 #if 0 /// UNNEEDED by elogind
550 int config_parse_si_size(const char* unit,
551                             const char *filename,
552                             unsigned line,
553                             const char *section,
554                             unsigned section_line,
555                             const char *lvalue,
556                             int ltype,
557                             const char *rvalue,
558                             void *data,
559                             void *userdata) {
560
561         size_t *sz = data;
562         uint64_t v;
563         int r;
564
565         assert(filename);
566         assert(lvalue);
567         assert(rvalue);
568         assert(data);
569
570         r = parse_size(rvalue, 1000, &v);
571         if (r < 0 || (uint64_t) (size_t) v != v) {
572                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue);
573                 return 0;
574         }
575
576         *sz = (size_t) v;
577         return 0;
578 }
579
580 int config_parse_iec_uint64(const char* unit,
581                            const char *filename,
582                            unsigned line,
583                            const char *section,
584                            unsigned section_line,
585                            const char *lvalue,
586                            int ltype,
587                            const char *rvalue,
588                            void *data,
589                            void *userdata) {
590
591         uint64_t *bytes = data;
592         int r;
593
594         assert(filename);
595         assert(lvalue);
596         assert(rvalue);
597         assert(data);
598
599         r = parse_size(rvalue, 1024, bytes);
600         if (r < 0)
601                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue);
602
603         return 0;
604 }
605 #endif // 0
606
607 int config_parse_bool(const char* unit,
608                       const char *filename,
609                       unsigned line,
610                       const char *section,
611                       unsigned section_line,
612                       const char *lvalue,
613                       int ltype,
614                       const char *rvalue,
615                       void *data,
616                       void *userdata) {
617
618         int k;
619         bool *b = data;
620
621         assert(filename);
622         assert(lvalue);
623         assert(rvalue);
624         assert(data);
625
626         k = parse_boolean(rvalue);
627         if (k < 0) {
628                 log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse boolean value, ignoring: %s", rvalue);
629                 return 0;
630         }
631
632         *b = !!k;
633         return 0;
634 }
635
636 #if 0 /// UNNEEDED by elogind
637 int config_parse_tristate(
638                 const char* unit,
639                 const char *filename,
640                 unsigned line,
641                 const char *section,
642                 unsigned section_line,
643                 const char *lvalue,
644                 int ltype,
645                 const char *rvalue,
646                 void *data,
647                 void *userdata) {
648
649         int k, *t = data;
650
651         assert(filename);
652         assert(lvalue);
653         assert(rvalue);
654         assert(data);
655
656         /* A tristate is pretty much a boolean, except that it can
657          * also take the special value -1, indicating "uninitialized",
658          * much like NULL is for a pointer type. */
659
660         k = parse_boolean(rvalue);
661         if (k < 0) {
662                 log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse boolean value, ignoring: %s", rvalue);
663                 return 0;
664         }
665
666         *t = !!k;
667         return 0;
668 }
669 #endif // 0
670
671 int config_parse_string(
672                 const char *unit,
673                 const char *filename,
674                 unsigned line,
675                 const char *section,
676                 unsigned section_line,
677                 const char *lvalue,
678                 int ltype,
679                 const char *rvalue,
680                 void *data,
681                 void *userdata) {
682
683         char **s = data, *n;
684
685         assert(filename);
686         assert(lvalue);
687         assert(rvalue);
688         assert(data);
689
690         if (!utf8_is_valid(rvalue)) {
691                 log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
692                 return 0;
693         }
694
695         if (isempty(rvalue))
696                 n = NULL;
697         else {
698                 n = strdup(rvalue);
699                 if (!n)
700                         return log_oom();
701         }
702
703         free(*s);
704         *s = n;
705
706         return 0;
707 }
708
709 int config_parse_path(
710                 const char *unit,
711                 const char *filename,
712                 unsigned line,
713                 const char *section,
714                 unsigned section_line,
715                 const char *lvalue,
716                 int ltype,
717                 const char *rvalue,
718                 void *data,
719                 void *userdata) {
720
721         char **s = data, *n;
722
723         assert(filename);
724         assert(lvalue);
725         assert(rvalue);
726         assert(data);
727
728         if (!utf8_is_valid(rvalue)) {
729                 log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
730                 return 0;
731         }
732
733         if (!path_is_absolute(rvalue)) {
734                 log_syntax(unit, LOG_ERR, filename, line, 0, "Not an absolute path, ignoring: %s", rvalue);
735                 return 0;
736         }
737
738         n = strdup(rvalue);
739         if (!n)
740                 return log_oom();
741
742         path_kill_slashes(n);
743
744         free(*s);
745         *s = n;
746
747         return 0;
748 }
749
750 int config_parse_strv(const char *unit,
751                       const char *filename,
752                       unsigned line,
753                       const char *section,
754                       unsigned section_line,
755                       const char *lvalue,
756                       int ltype,
757                       const char *rvalue,
758                       void *data,
759                       void *userdata) {
760
761         char ***sv = data;
762         int r;
763
764         assert(filename);
765         assert(lvalue);
766         assert(rvalue);
767         assert(data);
768
769         if (isempty(rvalue)) {
770                 char **empty;
771
772                 /* Empty assignment resets the list. As a special rule
773                  * we actually fill in a real empty array here rather
774                  * than NULL, since some code wants to know if
775                  * something was set at all... */
776                 empty = new0(char*, 1);
777                 if (!empty)
778                         return log_oom();
779
780                 strv_free(*sv);
781                 *sv = empty;
782
783                 return 0;
784         }
785
786         for (;;) {
787                 char *word = NULL;
788
789                 r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES|EXTRACT_RETAIN_ESCAPE);
790                 if (r == 0)
791                         break;
792                 if (r == -ENOMEM)
793                         return log_oom();
794                 if (r < 0) {
795                         log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
796                         break;
797                 }
798
799                 if (!utf8_is_valid(word)) {
800                         log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
801                         free(word);
802                         continue;
803                 }
804                 r = strv_consume(sv, word);
805                 if (r < 0)
806                         return log_oom();
807         }
808
809         return 0;
810 }
811
812 #if 0 /// UNNEEDED by elogind
813 int config_parse_log_facility(
814                 const char *unit,
815                 const char *filename,
816                 unsigned line,
817                 const char *section,
818                 unsigned section_line,
819                 const char *lvalue,
820                 int ltype,
821                 const char *rvalue,
822                 void *data,
823                 void *userdata) {
824
825
826         int *o = data, x;
827
828         assert(filename);
829         assert(lvalue);
830         assert(rvalue);
831         assert(data);
832
833         x = log_facility_unshifted_from_string(rvalue);
834         if (x < 0) {
835                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse log facility, ignoring: %s", rvalue);
836                 return 0;
837         }
838
839         *o = (x << 3) | LOG_PRI(*o);
840
841         return 0;
842 }
843 #endif // 0
844
845 int config_parse_log_level(
846                 const char *unit,
847                 const char *filename,
848                 unsigned line,
849                 const char *section,
850                 unsigned section_line,
851                 const char *lvalue,
852                 int ltype,
853                 const char *rvalue,
854                 void *data,
855                 void *userdata) {
856
857
858         int *o = data, x;
859
860         assert(filename);
861         assert(lvalue);
862         assert(rvalue);
863         assert(data);
864
865         x = log_level_from_string(rvalue);
866         if (x < 0) {
867                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse log level, ignoring: %s", rvalue);
868                 return 0;
869         }
870
871         *o = (*o & LOG_FACMASK) | x;
872         return 0;
873 }
874
875 int config_parse_signal(
876                 const char *unit,
877                 const char *filename,
878                 unsigned line,
879                 const char *section,
880                 unsigned section_line,
881                 const char *lvalue,
882                 int ltype,
883                 const char *rvalue,
884                 void *data,
885                 void *userdata) {
886
887         int *sig = data, r;
888
889         assert(filename);
890         assert(lvalue);
891         assert(rvalue);
892         assert(sig);
893
894         r = signal_from_string_try_harder(rvalue);
895         if (r <= 0) {
896                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse signal name, ignoring: %s", rvalue);
897                 return 0;
898         }
899
900         *sig = r;
901         return 0;
902 }
903
904 #if 0 /// UNNEEDED by elogind
905 int config_parse_personality(
906                 const char *unit,
907                 const char *filename,
908                 unsigned line,
909                 const char *section,
910                 unsigned section_line,
911                 const char *lvalue,
912                 int ltype,
913                 const char *rvalue,
914                 void *data,
915                 void *userdata) {
916
917         unsigned long *personality = data, p;
918
919         assert(filename);
920         assert(lvalue);
921         assert(rvalue);
922         assert(personality);
923
924         p = personality_from_string(rvalue);
925         if (p == PERSONALITY_INVALID) {
926                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse personality, ignoring: %s", rvalue);
927                 return 0;
928         }
929
930         *personality = p;
931         return 0;
932 }
933
934 int config_parse_ifname(
935                 const char *unit,
936                 const char *filename,
937                 unsigned line,
938                 const char *section,
939                 unsigned section_line,
940                 const char *lvalue,
941                 int ltype,
942                 const char *rvalue,
943                 void *data,
944                 void *userdata) {
945
946         char **s = data;
947         int r;
948
949         assert(filename);
950         assert(lvalue);
951         assert(rvalue);
952         assert(data);
953
954         if (isempty(rvalue)) {
955                 *s = mfree(*s);
956                 return 0;
957         }
958
959         if (!ifname_valid(rvalue)) {
960                 log_syntax(unit, LOG_ERR, filename, line, 0, "Interface name is not valid or too long, ignoring assignment: %s", rvalue);
961                 return 0;
962         }
963
964         r = free_and_strdup(s, rvalue);
965         if (r < 0)
966                 return log_oom();
967
968         return 0;
969 }
970 #endif // 0