mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-21 16:05:02 +02:00
Make getpeerid re-useable
This commit is contained in:
@@ -360,19 +360,25 @@ locale_is_valid(PyObject *self UNUSED, PyObject *args) {
|
|||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
getpeerid(int fd, uid_t *euid, gid_t *egid) {
|
||||||
|
#ifdef __linux__
|
||||||
|
struct ucred cr;
|
||||||
|
socklen_t sz = sizeof(cr);
|
||||||
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &sz) != 0) return false;
|
||||||
|
*euid = cr.uid; *egid = cr.gid;
|
||||||
|
#else
|
||||||
|
if (getpeereid(fd, euid, egid) != 0) return false;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
py_getpeereid(PyObject *self UNUSED, PyObject *args) {
|
py_getpeereid(PyObject *self UNUSED, PyObject *args) {
|
||||||
int fd;
|
int fd;
|
||||||
if (!PyArg_ParseTuple(args, "i", &fd)) return NULL;
|
if (!PyArg_ParseTuple(args, "i", &fd)) return NULL;
|
||||||
uid_t euid = 0; gid_t egid = 0;
|
uid_t euid = 0; gid_t egid = 0;
|
||||||
#ifdef __linux__
|
if (!getpeerid(fd, &euid, &egid)) { PyErr_SetFromErrno(PyExc_OSError); return NULL; }
|
||||||
struct ucred cr;
|
|
||||||
socklen_t sz = sizeof(cr);
|
|
||||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &sz) != 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; }
|
|
||||||
euid = cr.uid; egid = cr.gid;
|
|
||||||
#else
|
|
||||||
if (getpeereid(fd, &euid, &egid) != 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; }
|
|
||||||
#endif
|
|
||||||
int u = euid, g = egid;
|
int u = euid, g = egid;
|
||||||
return Py_BuildValue("ii", u, g);
|
return Py_BuildValue("ii", u, g);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,6 +423,7 @@ void play_canberra_sound(const char *which_sound, const char *event_id, bool is_
|
|||||||
SPRITE_MAP_HANDLE alloc_sprite_map(unsigned int, unsigned int);
|
SPRITE_MAP_HANDLE alloc_sprite_map(unsigned int, unsigned int);
|
||||||
SPRITE_MAP_HANDLE free_sprite_map(SPRITE_MAP_HANDLE);
|
SPRITE_MAP_HANDLE free_sprite_map(SPRITE_MAP_HANDLE);
|
||||||
const char* get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE, hyperlink_id_type id, bool only_url);
|
const char* get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE, hyperlink_id_type id, bool only_url);
|
||||||
|
bool getpeerid(int fd, uid_t *euid, gid_t *egid);
|
||||||
|
|
||||||
#define memset_array(array, val, count) if ((count) > 0) { \
|
#define memset_array(array, val, count) if ((count) > 0) { \
|
||||||
(array)[0] = (val); \
|
(array)[0] = (val); \
|
||||||
|
|||||||
Reference in New Issue
Block a user