chiark / gitweb /
tree-wide: make bus_map_all_properties return a proper sd_bus_error
[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);
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 #if 0 /// UNNEEDED by elogind
447 /* Parse each config file in the directories specified as strv. */
448 int config_parse_many(
449                 const char *conf_file,
450                 const char* const* conf_file_dirs,
451                 const char *dropin_dirname,
452                 const char *sections,
453                 ConfigItemLookup lookup,
454                 const void *table,
455                 bool relaxed,
456                 void *userdata) {
457
458         _cleanup_strv_free_ char **dropin_dirs = NULL;
459         _cleanup_strv_free_ char **files = NULL;
460         const char *suffix;
461         int r;
462
463         suffix = strjoina("/", dropin_dirname);
464         r = strv_extend_strv_concat(&dropin_dirs, (char**) conf_file_dirs, suffix);
465         if (r < 0)
466                 return r;
467
468         r = conf_files_list_strv(&files, ".conf", NULL, (const char* const*) dropin_dirs);
469         if (r < 0)
470                 return r;
471
472         return config_parse_many_files(conf_file, files,
473                                        sections, lookup, table, relaxed, userdata);
474 }
475 #endif // 0
476
477 #define DEFINE_PARSER(type, vartype, conv_func)                         \
478         int config_parse_##type(                                        \
479                         const char *unit,                               \
480                         const char *filename,                           \
481                         unsigned line,                                  \
482                         const char *section,                            \
483                         unsigned section_line,                          \
484                         const char *lvalue,                             \
485                         int ltype,                                      \
486                         const char *rvalue,                             \
487                         void *data,                                     \
488                         void *userdata) {                               \
489                                                                         \
490                 vartype *i = data;                                      \
491                 int r;                                                  \
492                                                                         \
493                 assert(filename);                                       \
494                 assert(lvalue);                                         \
495                 assert(rvalue);                                         \
496                 assert(data);                                           \
497                                                                         \
498                 r = conv_func(rvalue, i);                               \
499                 if (r < 0)                                              \
500                         log_syntax(unit, LOG_ERR, filename, line, r,    \
501                                    "Failed to parse %s value, ignoring: %s", \
502                                    #type, rvalue);                      \
503                                                                         \
504                 return 0;                                               \
505         }                                                               \
506         struct __useless_struct_to_allow_trailing_semicolon__
507
508 DEFINE_PARSER(int, int, safe_atoi);
509 DEFINE_PARSER(long, long, safe_atoli);
510 #if 0 /// UNNEEDED by elogind
511 DEFINE_PARSER(uint16, uint16_t, safe_atou16);
512 DEFINE_PARSER(uint32, uint32_t, safe_atou32);
513 #endif // 0
514 DEFINE_PARSER(uint64, uint64_t, safe_atou64);
515 DEFINE_PARSER(unsigned, unsigned, safe_atou);
516 DEFINE_PARSER(double, double, safe_atod);
517 #if 0 /// UNNEEDED by elogind
518 DEFINE_PARSER(nsec, nsec_t, parse_nsec);
519 #endif // 0
520 DEFINE_PARSER(sec, usec_t, parse_sec);
521 DEFINE_PARSER(mode, mode_t, parse_mode);
522
523 int config_parse_iec_size(const char* unit,
524                             const char *filename,
525                             unsigned line,
526                             const char *section,
527                             unsigned section_line,
528                             const char *lvalue,
529                             int ltype,
530                             const char *rvalue,
531                             void *data,
532                             void *userdata) {
533
534         size_t *sz = data;
535         uint64_t v;
536         int r;
537
538         assert(filename);
539         assert(lvalue);
540         assert(rvalue);
541         assert(data);
542
543         r = parse_size(rvalue, 1024, &v);
544         if (r < 0 || (uint64_t) (size_t) v != v) {
545                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue);
546                 return 0;
547         }
548
549         *sz = (size_t) v;
550         return 0;
551 }
552
553 #if 0 /// UNNEEDED by elogind
554 int config_parse_si_size(const char* unit,
555                             const char *filename,
556                             unsigned line,
557                             const char *section,
558                             unsigned section_line,
559                             const char *lvalue,
560                             int ltype,
561                             const char *rvalue,
562                             void *data,
563                             void *userdata) {
564
565         size_t *sz = data;
566         uint64_t v;
567         int r;
568
569         assert(filename);
570         assert(lvalue);
571         assert(rvalue);
572         assert(data);
573
574         r = parse_size(rvalue, 1000, &v);
575         if (r < 0 || (uint64_t) (size_t) v != v) {
576                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue);
577                 return 0;
578         }
579
580         *sz = (size_t) v;
581         return 0;
582 }
583
584 int config_parse_iec_uint64(const char* unit,
585                            const char *filename,
586                            unsigned line,
587                            const char *section,
588                            unsigned section_line,
589                            const char *lvalue,
590                            int ltype,
591                            const char *rvalue,
592                            void *data,
593                            void *userdata) {
594
595         uint64_t *bytes = data;
596         int r;
597
598         assert(filename);
599         assert(lvalue);
600         assert(rvalue);
601         assert(data);
602
603         r = parse_size(rvalue, 1024, bytes);
604         if (r < 0)
605                 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse size value, ignoring: %s", rvalue);
606
607         return 0;
608 }
609 #endif // 0
610
611 int config_parse_bool(const char* unit,
612                       const char *filename,
613                       unsigned line,
614                       const char *section,
615                       unsigned section_line,
616                       const char *lvalue,
617                       int ltype,
618                       const char *rvalue,
619                       void *data,
620                       void *userdata) {
621
622         int k;
623         bool *b = data;
624
625         assert(filename);
626         assert(lvalue);
627         assert(rvalue);
628         assert(data);
629
630         k = parse_boolean(rvalue);
631         if (k < 0) {
632                 log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse boolean value, ignoring: %s", rvalue);
633                 return 0;
634         }
635
636         *b = !!k;
637         return 0;
638 }
639
640 #if 0 /// UNNEEDED by elogind
641 int config_parse_tristate(
642                 const char* unit,
643                 const char *filename,
644                 unsigned line,
645                 const char *section,
646                 unsigned section_line,
647                 const char *lvalue,
648                 int ltype,
649                 const char *rvalue,
650                 void *data,
651                 void *userdata) {
652
653         int k, *t = data;
654
655         assert(filename);
656         assert(lvalue);
657         assert(rvalue);
658         assert(data);
659
660         /* A tristate is pretty much a boolean, except that it can
661          * also take the special value -1, indicating "uninitialized",
662          * much like NULL is for a pointer type. */
663
664         k = parse_boolean(rvalue);
665         if (k < 0) {
666                 log_syntax(unit, LOG_ERR, filename, line, k, "Failed to parse boolean value, ignoring: %s", rvalue);
667                 return 0;
668         }
669
670         *t = !!k;
671         return 0;
672 }
673 #endif // 0
674
675 int config_parse_string(
676                 const char *unit,
677                 const char *filename,
678                 unsigned line,
679                 const char *section,
680                 unsigned section_line,
681                 const char *lvalue,
682                 int ltype,
683                 const char *rvalue,
684                 void *data,
685                 void *userdata) {
686
687         char **s = data, *n;
688
689         assert(filename);
690         assert(lvalue);
691         assert(rvalue);
692         assert(data);
693
694         if (!utf8_is_valid(rvalue)) {
695                 log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
696                 return 0;
697         }
698
699         if (isempty(rvalue))
700                 n = NULL;
701         else {
702                 n = strdup(rvalue);
703                 if (!n)
704                         return log_oom();
705         }
706
707         free(*s);
708         *s = n;
709
710         return 0;
711 }
712
713 int config_parse_path(
714                 const char *unit,
715                 const char *filename,
716                 unsigned line,
717                 const char *section,
718                 unsigned section_line,
719                 const char *lvalue,
720                 int ltype,
721                 const char *rvalue,
722                 void *data,
723                 void *userdata) {
724
725         char **s = data, *n;
726
727         assert(filename);
728         assert(lvalue);
729         assert(rvalue);
730         assert(data);
731
732         if (!utf8_is_valid(rvalue)) {
733                 log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
734                 return 0;
735         }
736
737         if (!path_is_absolute(rvalue)) {
738                 log_syntax(unit, LOG_ERR, filename, line, 0, "Not an absolute path, ignoring: %s", rvalue);
739                 return 0;
740         }
741
742         n = strdup(rvalue);
743         if (!n)
744                 return log_oom();
745
746         path_kill_slashes(n);
747
748         free(*s);
749         *s = n;
750
751         return 0;
752 }
753
754 int config_parse_strv(const char *unit,
755                       const char *filename,
756                       unsigned line,
757                       const char *section,
758                       unsigned section_line,
759                       const char *lvalue,
760                       int ltype,
761                       const char *rvalue,
762                       void *data,
763                       void *userdata) {
764
765         char ***sv = data;
766         int r;
767
768         assert(filename);
769         assert(lvalue);
770         assert(rvalue);
771         assert(data);
772
773         if (isempty(rvalue)) {
774                 char **empty;
775
776                 /* Empty assignment resets the list. As a special rule
777                  * we actually fill in a real empty array here rather
778                  * than NULL, since some code wants to know if
779                  * something was set at all... */
780                 empty = new0(char*, 1);
781                 if (!empty)
782                         return log_oom();
783
784                 strv_free(*sv);
785                 *sv = empty;
786
787                 return 0;
788         }
789
790         for (;;) {
791                 char *word = NULL;
792
793                 r = extract_first_word(&rvalue, &word, NULL, EXTRACT_QUOTES|EXTRACT_RETAIN_ESCAPE);
794                 if (r == 0)
795                         break;
796                 if (r == -ENOMEM)
797                         return log_oom();
798                 if (r < 0) {
799                         log_syntax(unit, LOG_ERR, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
800                         break;
801                 }
802
803                 if (!utf8_is_valid(word)) {
804                         log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
805                         free(word);
806                         continue;
807                 }
808                 r = strv_consume(sv, word);
809                 if (r < 0)
810                         return log_oom();
811         }
812
813         return 0;
814 }
815
816 #if 0 /// UNNEEDED by elogind
817 int config_parse_log_facility(
818                 const char *unit,
819                 const char *filename,
820                 unsigned line,
821                 const char *section,
822                 unsigned section_line,
823                 const char *lvalue,
824                 int ltype,
825                 const char *rvalue,
826                 void *data,
827                 void *userdata) {
828
829
830         int *o = data, x;
831
832         assert(filename);
833         assert(lvalue);
834         assert(rvalue);
835         assert(data);
836
837         x = log_facility_unshifted_from_string(rvalue);
838         if (x < 0) {
839                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse log facility, ignoring: %s", rvalue);
840                 return 0;
841         }
842
843         *o = (x << 3) | LOG_PRI(*o);
844
845         return 0;
846 }
847 #endif // 0
848
849 int config_parse_log_level(
850                 const char *unit,
851                 const char *filename,
852                 unsigned line,
853                 const char *section,
854                 unsigned section_line,
855                 const char *lvalue,
856                 int ltype,
857                 const char *rvalue,
858                 void *data,
859                 void *userdata) {
860
861
862         int *o = data, x;
863
864         assert(filename);
865         assert(lvalue);
866         assert(rvalue);
867         assert(data);
868
869         x = log_level_from_string(rvalue);
870         if (x < 0) {
871                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse log level, ignoring: %s", rvalue);
872                 return 0;
873         }
874
875         *o = (*o & LOG_FACMASK) | x;
876         return 0;
877 }
878
879 int config_parse_signal(
880                 const char *unit,
881                 const char *filename,
882                 unsigned line,
883                 const char *section,
884                 unsigned section_line,
885                 const char *lvalue,
886                 int ltype,
887                 const char *rvalue,
888                 void *data,
889                 void *userdata) {
890
891         int *sig = data, r;
892
893         assert(filename);
894         assert(lvalue);
895         assert(rvalue);
896         assert(sig);
897
898         r = signal_from_string_try_harder(rvalue);
899         if (r <= 0) {
900                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse signal name, ignoring: %s", rvalue);
901                 return 0;
902         }
903
904         *sig = r;
905         return 0;
906 }
907
908 #if 0 /// UNNEEDED by elogind
909 int config_parse_personality(
910                 const char *unit,
911                 const char *filename,
912                 unsigned line,
913                 const char *section,
914                 unsigned section_line,
915                 const char *lvalue,
916                 int ltype,
917                 const char *rvalue,
918                 void *data,
919                 void *userdata) {
920
921         unsigned long *personality = data, p;
922
923         assert(filename);
924         assert(lvalue);
925         assert(rvalue);
926         assert(personality);
927
928         p = personality_from_string(rvalue);
929         if (p == PERSONALITY_INVALID) {
930                 log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse personality, ignoring: %s", rvalue);
931                 return 0;
932         }
933
934         *personality = p;
935         return 0;
936 }
937
938 int config_parse_ifname(
939                 const char *unit,
940                 const char *filename,
941                 unsigned line,
942                 const char *section,
943                 unsigned section_line,
944                 const char *lvalue,
945                 int ltype,
946                 const char *rvalue,
947                 void *data,
948                 void *userdata) {
949
950         char **s = data;
951         int r;
952
953         assert(filename);
954         assert(lvalue);
955         assert(rvalue);
956         assert(data);
957
958         if (isempty(rvalue)) {
959                 *s = mfree(*s);
960                 return 0;
961         }
962
963         if (!ifname_valid(rvalue)) {
964                 log_syntax(unit, LOG_ERR, filename, line, 0, "Interface name is not valid or too long, ignoring assignment: %s", rvalue);
965                 return 0;
966         }
967
968         r = free_and_strdup(s, rvalue);
969         if (r < 0)
970                 return log_oom();
971
972         return 0;
973 }
974 #endif // 0