X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Futil.h;h=57667ef895a4629164a05afe152d2fbc869a39d3;hb=db69869f264af2d1afcdd3e573e0e9fdd5bef065;hp=3e0a6d5c1cd15a19f1af7ec8d69de649940f5b61;hpb=bf108e5541e2a3cbc6f0c59e93665eceb7a5ce05;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 3e0a6d5c1..57667ef89 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -40,16 +40,11 @@ #include #include #include +#include #include "macro.h" #include "time-util.h" -union dirent_storage { - struct dirent de; - uint8_t storage[offsetof(struct dirent, d_name) + - ((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))]; -}; - /* What is interpreted as whitespace? */ #define WHITESPACE " \t\n\r" #define NEWLINE "\n\r" @@ -255,8 +250,19 @@ int make_stdio(int fd); int make_null_stdio(void); int make_console_stdio(void); -unsigned long long random_ull(void); -unsigned random_u(void); +void random_bytes(void *p, size_t n); + +static inline uint64_t random_u64(void) { + uint64_t u; + random_bytes(&u, sizeof(u)); + return u; +} + +static inline uint32_t random_u32(void) { + uint32_t u; + random_bytes(&u, sizeof(u)); + return u; +} /* For basic lookup tables with strictly enumerated entries */ #define __DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ @@ -806,3 +812,6 @@ int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *root_fd); int namespace_enter(int pidns_fd, int mntns_fd, int root_fd); bool pid_valid(pid_t pid); + +int getpeercred(int fd, struct ucred *ucred); +int getpeersec(int fd, char **ret);