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=488ce3ba6dc27181449e2e3efa8bc556820276b2;hpb=4ff4ebb1fbb7296f67b89b66d2d7f720b49b51c5;p=elogind.git diff --git a/src/shared/util.h b/src/shared/util.h index 488ce3ba6..57667ef89 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -40,6 +40,7 @@ #include #include #include +#include #include "macro.h" #include "time-util.h" @@ -249,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) \ @@ -800,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);