LCOV - code coverage report
Current view: top level - shared - securebits-util.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 0 39 0.0 %
Date: 2019-08-22 15:41:25 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <errno.h>
       4             : #include <stdio.h>
       5             : 
       6             : #include "alloc-util.h"
       7             : #include "extract-word.h"
       8             : #include "securebits-util.h"
       9             : #include "string-util.h"
      10             : 
      11           0 : int secure_bits_to_string_alloc(int i, char **s) {
      12           0 :         _cleanup_free_ char *str = NULL;
      13             :         size_t len;
      14             :         int r;
      15             : 
      16           0 :         assert(s);
      17             : 
      18           0 :         r = asprintf(&str, "%s%s%s%s%s%s",
      19           0 :                      (i & (1 << SECURE_KEEP_CAPS)) ? "keep-caps " : "",
      20           0 :                      (i & (1 << SECURE_KEEP_CAPS_LOCKED)) ? "keep-caps-locked " : "",
      21           0 :                      (i & (1 << SECURE_NO_SETUID_FIXUP)) ? "no-setuid-fixup " : "",
      22           0 :                      (i & (1 << SECURE_NO_SETUID_FIXUP_LOCKED)) ? "no-setuid-fixup-locked " : "",
      23           0 :                      (i & (1 << SECURE_NOROOT)) ? "noroot " : "",
      24           0 :                      (i & (1 << SECURE_NOROOT_LOCKED)) ? "noroot-locked " : "");
      25           0 :         if (r < 0)
      26           0 :                 return -ENOMEM;
      27             : 
      28           0 :         len = strlen(str);
      29           0 :         if (len != 0)
      30           0 :                 str[len - 1] = '\0';
      31             : 
      32           0 :         *s = TAKE_PTR(str);
      33             : 
      34           0 :         return 0;
      35             : }
      36             : 
      37           0 : int secure_bits_from_string(const char *s) {
      38           0 :         int secure_bits = 0;
      39             :         const char *p;
      40             :         int r;
      41             : 
      42           0 :         for (p = s;;) {
      43           0 :                 _cleanup_free_ char *word = NULL;
      44             : 
      45           0 :                 r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
      46           0 :                 if (r == -ENOMEM)
      47           0 :                         return r;
      48           0 :                 if (r <= 0)
      49           0 :                         break;
      50             : 
      51           0 :                 if (streq(word, "keep-caps"))
      52           0 :                         secure_bits |= 1 << SECURE_KEEP_CAPS;
      53           0 :                 else if (streq(word, "keep-caps-locked"))
      54           0 :                         secure_bits |= 1 << SECURE_KEEP_CAPS_LOCKED;
      55           0 :                 else if (streq(word, "no-setuid-fixup"))
      56           0 :                         secure_bits |= 1 << SECURE_NO_SETUID_FIXUP;
      57           0 :                 else if (streq(word, "no-setuid-fixup-locked"))
      58           0 :                         secure_bits |= 1 << SECURE_NO_SETUID_FIXUP_LOCKED;
      59           0 :                 else if (streq(word, "noroot"))
      60           0 :                         secure_bits |= 1 << SECURE_NOROOT;
      61           0 :                 else if (streq(word, "noroot-locked"))
      62           0 :                         secure_bits |= 1 << SECURE_NOROOT_LOCKED;
      63             :         }
      64             : 
      65           0 :         return secure_bits;
      66             : }

Generated by: LCOV version 1.14