@wastedcode/memex 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +13 -0
- package/package.json +4 -2
- package/src/daemon/peercred.c +57 -0
package/binding.gyp
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wastedcode/memex",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Isolated, queued claude -p runtime for persistent knowledge bases",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -46,7 +46,9 @@
|
|
|
46
46
|
},
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"files": [
|
|
49
|
-
"dist"
|
|
49
|
+
"dist",
|
|
50
|
+
"binding.gyp",
|
|
51
|
+
"src/daemon/peercred.c"
|
|
50
52
|
],
|
|
51
53
|
"dependencies": {
|
|
52
54
|
"better-sqlite3": "^12.8.0",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#include <node_api.h>
|
|
2
|
+
#include <sys/socket.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* getPeerCred(fd: number): { uid: number, gid: number, pid: number }
|
|
7
|
+
*
|
|
8
|
+
* Calls getsockopt(fd, SOL_SOCKET, SO_PEERCRED) to retrieve the
|
|
9
|
+
* kernel-verified credentials of the process on the other end
|
|
10
|
+
* of a Unix domain socket.
|
|
11
|
+
*
|
|
12
|
+
* Linux only. This is the same mechanism used by systemd, D-Bus,
|
|
13
|
+
* and other privilege-aware daemons.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
static napi_value get_peer_cred(napi_env env, napi_callback_info info) {
|
|
17
|
+
size_t argc = 1;
|
|
18
|
+
napi_value argv[1];
|
|
19
|
+
napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
|
|
20
|
+
|
|
21
|
+
if (argc < 1) {
|
|
22
|
+
napi_throw_error(env, NULL, "getPeerCred requires a file descriptor argument");
|
|
23
|
+
return NULL;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
int fd;
|
|
27
|
+
napi_get_value_int32(env, argv[0], &fd);
|
|
28
|
+
|
|
29
|
+
struct ucred cred;
|
|
30
|
+
socklen_t len = sizeof(cred);
|
|
31
|
+
memset(&cred, 0, sizeof(cred));
|
|
32
|
+
|
|
33
|
+
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) {
|
|
34
|
+
napi_throw_error(env, NULL, "getsockopt(SO_PEERCRED) failed");
|
|
35
|
+
return NULL;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
napi_value result, uid_val, gid_val, pid_val;
|
|
39
|
+
napi_create_object(env, &result);
|
|
40
|
+
napi_create_uint32(env, (uint32_t)cred.uid, &uid_val);
|
|
41
|
+
napi_create_uint32(env, (uint32_t)cred.gid, &gid_val);
|
|
42
|
+
napi_create_int32(env, cred.pid, &pid_val);
|
|
43
|
+
napi_set_named_property(env, result, "uid", uid_val);
|
|
44
|
+
napi_set_named_property(env, result, "gid", gid_val);
|
|
45
|
+
napi_set_named_property(env, result, "pid", pid_val);
|
|
46
|
+
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static napi_value init(napi_env env, napi_value exports) {
|
|
51
|
+
napi_value fn;
|
|
52
|
+
napi_create_function(env, "getPeerCred", NAPI_AUTO_LENGTH, get_peer_cred, NULL, &fn);
|
|
53
|
+
napi_set_named_property(env, exports, "getPeerCred", fn);
|
|
54
|
+
return exports;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
NAPI_MODULE(NODE_GYP_MODULE_NAME, init)
|