PERFORCE change 166443 for review
Jonathan Anderson
jona at FreeBSD.org
Thu Jul 23 13:59:51 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166443
Change 166443 by jona at jona-trustedbsd-belle-vmware on 2009/07/23 13:59:40
Handle ua_access() and ua_stat() requests in the user_angel
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#16 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#16 (text+ko) ====
@@ -33,6 +33,7 @@
#include <sys/capability.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/un.h>
#include <libuserangel.h>
@@ -80,6 +81,8 @@
void accept_client(int fd_server);
int service_client(struct client*);
int handle_request(struct client*, enum ua_request_t);
+int handle_stat_request(struct client *client, struct ua_datum *d);
+int handle_check_access(struct client *client, struct ua_datum *d);
int handle_path_request(struct client*, struct ua_datum*);
int handle_powerbox_request(struct client*, struct ua_datum*);
void client_error(struct client*, const char *message, int errnum,
@@ -207,9 +210,9 @@
for(struct client *c = clients; ; c = c->next)
if(c->next == NULL)
{
- c->next = client;
client->prev = c;
client->next = NULL;
+ c->next = client;
break;
}
@@ -246,21 +249,27 @@
if(FD_ISSET(fd_server, &selected))
{
+ printf("server socket selected\n"); /* TODO: tmp */
accept_client(fd_server);
FD_CLR(fd_server, &selected);
ready--;
}
- for(struct client *c = clients; c && ready; c = c->next)
+ for(struct client *c = clients; c && ready; )
if(FD_ISSET(c->socket, &selected))
{
int sock = c->socket;
+ struct client *next = c->next;
+
service_client(c);
FD_CLR(sock, &selected);
ready--;
+
+ c = next;
}
+ else c = c->next;
}
@@ -327,12 +336,23 @@
int retval;
switch(req)
{
+ case UA_CHECK_ACCESS:
+ printf("%20s", "UA_CHECK_ACCESS");
+ retval = handle_check_access(client, datum);
+ break;
+
+ case UA_STAT:
+ printf("%20s", "UA_STAT");
+ retval = handle_stat_request(client, datum);
+ break;
+
case UA_OPEN_PATH:
+ printf("%20s", "UA_OPEN_PATH");
retval = handle_path_request(client, datum);
break;
case UA_POWERBOX:
- puts("UA_POWERBOX");
+ printf("%20s", "UA_POWERBOX");
retval = handle_powerbox_request(client, datum);
break;
@@ -346,14 +366,65 @@
}
+int handle_check_access(struct client *client, struct ua_datum *d)
+{
+ char path[256] = "";
+ unsigned int pathlen = 256;
+
+ int sock = client->socket;
+
+ if(ua_unmarshall_string(d, path, &pathlen) < 0) return -1;
+
+ printf(": %s\n", path);
+
+ int32_t mode;
+ if(ua_unmarshall_int(ua_recv(sock, NULL, NULL), &mode) < 0) return -1;
+
+
+ int retval = access(path, mode);
+ d = ua_marshall_int(retval);
+ if(!d) return -1;
+
+ if(ua_send(sock, d, NULL, 0) < 0) return -1;
+ free(d);
+
+
+ return 0;
+}
+
+
+int handle_stat_request(struct client *client, struct ua_datum *d)
+{
+ char path[256] = "";
+ unsigned int pathlen = 256;
+
+ int sock = client->socket;
+
+ if(ua_unmarshall_string(d, path, &pathlen) < 0) return -1;
+ printf(": %s\n", path);
+
+ struct stat s;
+ if(stat(path, &s)) return 1;
+
+
+ d = ua_marshall_string((char*) &s, sizeof(s));
+ if(!d) return -1;
+
+ if(ua_send(sock, d, NULL, 0) < 0) return -1;
+ free(d);
+
+
+ return 0;
+}
+
+
+
int handle_path_request(struct client *client, struct ua_datum *d)
{
// unsigned int fdlen = 0;
char path[256] = "";
unsigned int pathlen = 256;
- printf("UA_OPEN_PATH");
-
int sock = client->socket;
// struct ua_datum *d = ua_recv(sock, NULL, &fdlen);
More information about the p4-projects
mailing list