#include <string.h>
#include "alloc-util.h"
+#include "def.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
_cleanup_close_ int load2_fd = -1, change_fd = -1;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *entry;
- char buf[NAME_MAX];
int dfd = -1;
int r = 0;
}
/* load2 write rules in the kernel require a line buffered stream */
- FOREACH_LINE(buf, policy,
- log_error_errno(errno, "Failed to read line from '%s': %m",
- entry->d_name)) {
+ for (;;) {
+ _cleanup_free_ char *buf = NULL, *sbj = NULL, *obj = NULL, *acc1 = NULL, *acc2 = NULL;
+ int q;
- _cleanup_free_ char *sbj = NULL, *obj = NULL, *acc1 = NULL, *acc2 = NULL;
+ q = read_line(policy, NAME_MAX, &buf);
+ if (q < 0)
+ return log_error_errno(q, "Failed to read line from '%s': %m", entry->d_name);
+ if (q == 0)
+ break;
- if (isempty(truncate_nl(buf)) || strchr(COMMENTS, *buf))
+ if (isempty(buf) || strchr(COMMENTS, buf[0]))
continue;
/* if 3 args -> load rule : subject object access1 */
_cleanup_close_ int cipso2_fd = -1;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *entry;
- char buf[NAME_MAX];
int dfd = -1;
int r = 0;
}
/* cipso2 write rules in the kernel require a line buffered stream */
- FOREACH_LINE(buf, policy,
- log_error_errno(errno, "Failed to read line from '%s': %m",
- entry->d_name)) {
+ for (;;) {
+ _cleanup_free_ char *buf = NULL;
+ int q;
+
+ q = read_line(policy, NAME_MAX, &buf);
+ if (q < 0)
+ return log_error_errno(q, "Failed to read line from '%s': %m", entry->d_name);
+ if (q == 0)
+ break;
- if (isempty(truncate_nl(buf)) || strchr(COMMENTS, *buf))
+ if (isempty(buf) || strchr(COMMENTS, buf[0]))
continue;
if (write(cipso2_fd, buf, strlen(buf)) < 0) {
_cleanup_fclose_ FILE *dst = NULL;
_cleanup_closedir_ DIR *dir = NULL;
struct dirent *entry;
- char buf[NAME_MAX];
int dfd = -1;
int r = 0;
(void) __fsetlocking(policy, FSETLOCKING_BYCALLER);
/* load2 write rules in the kernel require a line buffered stream */
- FOREACH_LINE(buf, policy,
- log_error_errno(errno, "Failed to read line from %s: %m", entry->d_name)) {
-
+ for (;;) {
+ _cleanup_free_ char *buf = NULL;
int q;
+ q = read_line(policy, NAME_MAX, &buf);
+ if (q < 0)
+ return log_error_errno(q, "Failed to read line from %s: %m", entry->d_name);
+ if (q == 0)
+ break;
+
if (!fputs(buf, dst)) {
if (r == 0)
r = -EINVAL;
_cleanup_free_ char *list = NULL;
_cleanup_fclose_ FILE *f = NULL;
size_t len = 0, allocated = 0;
- char buf[LINE_MAX];
int r;
f = fopen("/etc/smack/onlycap", "re");
return errno == ENOENT ? ENOENT : -errno;
}
- FOREACH_LINE(buf, f, return -errno) {
+ for (;;) {
+ _cleanup_free_ char *buf = NULL;
size_t l;
- if (isempty(truncate_nl(buf)) || strchr(COMMENTS, *buf))
+ r = read_line(f, LONG_LINE_MAX, &buf);
+ if (r < 0)
+ return log_error_errno(r, "Failed to read line from /etc/smack/onlycap: %m");
+ if (r == 0)
+ break;
+
+ if (isempty(buf) || strchr(COMMENTS, *buf))
continue;
l = strlen(buf);