#define _GNU_SOURCE #include "admin.h" #include #include #include #include #include #include #include #include static json_object *failure(const char *s){json_object *o=json_object_new_object();addstr(o,"error",s);return o;} json_object *bindery_call(json_object *req){ int fd=socket(AF_UNIX,SOCK_SEQPACKET|SOCK_CLOEXEC,0); if(fd<0)return failure("IPC nicht verfügbar"); struct timeval t={3,0};setsockopt(fd,SOL_SOCKET,SO_RCVTIMEO,&t,sizeof t);setsockopt(fd,SOL_SOCKET,SO_SNDTIMEO,&t,sizeof t); struct sockaddr_un a={.sun_family=AF_UNIX,.sun_path=ADMIN_SOCK}; if(connect(fd,(struct sockaddr*)&a,sizeof a)){close(fd);return failure("nwbind-Live-Schnittstelle nicht erreichbar. Server starten oder Build prüfen.");} struct ucred peer; socklen_t z=sizeof peer;if(getsockopt(fd,SOL_SOCKET,SO_PEERCRED,&peer,&z)||peer.uid!=0){close(fd);return failure("Ungültiger IPC-Prozess");} const char *s=json_object_to_json_string_ext(req,JSON_C_TO_STRING_PLAIN);size_t n=strlen(s);if(n>32768||send(fd,s,n,MSG_NOSIGNAL)!=(ssize_t)n){close(fd);return failure("IPC-Senden fehlgeschlagen");} char *buf=malloc(200001);if(!buf){close(fd);return failure("Speicherfehler");}ssize_t r=recv(fd,buf,200000,MSG_TRUNC);close(fd);json_object *o=NULL;if(r>0&&r<200000){buf[r]=0;o=json_tokener_parse(buf);}free(buf);return o?o:failure("Keine gültige Antwort; bei Schreiboperationen Zustand neu prüfen."); }