PERFORCE change 164719 for review

Jonathan Anderson jona at FreeBSD.org
Fri Jun 19 17:24:45 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=164719

Change 164719 by jona at jona-trustedbsd-kentvm on 2009/06/19 17:24:26

	Use libuserangel instead of 'protocol.[hc]'

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/Makefile#7 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/dbus.cpp#2 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.c#7 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.h#7 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#13 delete
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.h#11 delete
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#9 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/test_client.c#10 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/Makefile#7 (text+ko) ====

@@ -7,27 +7,27 @@
 
 CFLAGS=--std=c99 ${DEBUG} ${WARNINGS} ${INCLUDE} -DVERSION='"${VERSION}"'
 CXXFLAGS=${DEBUG} -Wall ${QDBUS_INCLUDE} -DVERSION='"${VERSION}"'
+LIBS=-luserangel
 
 BIN=user_angel test_client
-AGENT_OBJ = user_angel.o server.o cap.o protocol.o powerbox.o dbus.o
-CLIENT_OBJ = test_client.o protocol.o
+AGENT_OBJ = user_angel.o server.o cap.o powerbox.o dbus.o
+CLIENT_OBJ = test_client.o
 
 
 all: ${BIN}
 
 user_angel: ${AGENT_OBJ}
-	${CXX} ${QDBUS_LIBS} -o $@ ${AGENT_OBJ}
+	${CXX} ${LIBS} ${QDBUS_LIBS} -o $@ ${AGENT_OBJ}
 
 test_client: ${CLIENT_OBJ}
-	${CC} -o $@ ${CLIENT_OBJ}
+	${CC} ${LIBS} -o $@ ${CLIENT_OBJ}
 
 
 cap.o: cap.c cap.h
 dbus.o: dbus.cpp dbus.h
 powerbox.o: powerbox.c powerbox.h dbus.h
-protocol.o: protocol.c protocol.h powerbox.h
-server.o: server.c protocol.h server.h
-user_angel.o: user_angel.c protocol.h server.h
+server.o: server.c server.h
+user_angel.o: user_angel.c server.h
 
 clean:
 	rm -f ${BIN} *.o

==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/dbus.cpp#2 (text+ko) ====

@@ -10,17 +10,17 @@
 using namespace std;
 
 
-extern "C" int dbus_powerbox(struct capbox_options *options, char *names[], int *len)
+extern "C" int dbus_powerbox(struct ua_powerbox_options *options, char *names[], int *len)
 {
 	QString serviceName;
 
 	switch(options->ui)
 	{
-		case KDE:     serviceName = "org.freebsd.capsicum.kde";  break;
-		case QT:      serviceName = "org.freebsd.capsicum.qt";   break;
+		case UA_KDE:     serviceName = "org.freebsd.capsicum.kde";  break;
+		case UA_QT:      serviceName = "org.freebsd.capsicum.qt";   break;
 		default:
 			cerr << "Unknown UI " << options->ui << "; expected KDE ("
-			     << KDE << ") or QT (" << QT << ")" << endl;
+			     << UA_KDE << ") or QT (" << UA_QT << ")" << endl;
 		return -1;
 	}
 

==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.c#7 (text+ko) ====

@@ -34,6 +34,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/capability.h>
+
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -43,14 +45,14 @@
 #include "powerbox.h"
 
 
-int capbox_display(struct capbox_options *options,
+int capbox_display(struct ua_powerbox_options *options,
                    int fds[], char *names[], int *len)
 {
 	// get the filenames from the user
 	switch(options->ui)
 	{
-		case QT:
-		case KDE:
+		case UA_QT:
+		case UA_KDE:
 			if(dbus_powerbox(options, names, len))
 			{
 				fprintf(stderr, "Error opening DBus powerbox\n");

==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.h#7 (text+ko) ====

@@ -35,9 +35,11 @@
 #ifndef POWERBOX_H
 #define POWERBOX_H
 
+#include <libuserangel-powerbox.h>
+
 #include "cap.h"
 
-
+#if 0
 enum capbox_ui_t { QT, KDE /* TODO, GNOME, NCURSES*/ };
 
 enum capbox_op_t
@@ -62,6 +64,7 @@
 	int			flags;         /* open() flags, e.g. O_RDONLY */
 	cap_rights_t		rights;        /* capabilities, e.g. CAP_SEEK */
 };
+#endif
 
 
 /**
@@ -74,7 +77,7 @@
  *
  * @return  0 on success
  */
-int capbox_display(struct capbox_options *options,
+int capbox_display(struct ua_powerbox_options *options,
                    int fds[], char *names[], int *len);
 
 #endif

==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#9 (text+ko) ====

@@ -37,6 +37,8 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#include <libuserangel.h>
+
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
@@ -45,7 +47,7 @@
 #include <unistd.h>
 
 #include "cap.h"
-#include "protocol.h"
+#include "powerbox.h"
 #include "server.h"
 
 
@@ -75,7 +77,7 @@
 void	serve(int fd_server, struct fd_set *clients);
 void	accept_client(int fd_server);
 int	service_client(int client);
-int	handle_request(int client, enum capangel_req_t req);
+int	handle_request(int client, enum ua_request_t req);
 int	handle_path_request(int client);
 int	handle_powerbox_request(int client);
 void	close_client(int client, int errnum, const char *msg);
@@ -197,9 +199,9 @@
 
 	char hello[80];
 	sprintf(hello, "user_angel v%s", VERSION);
-	struct cap_wire_datum *d = cap_marshall_string(hello, strlen(hello));
+	struct ua_datum *d = ua_marshall_string(hello, strlen(hello));
 
-	cap_send(client, d);
+	ua_send(client, d, NULL, 0);
 	free(d);
 }
 
@@ -238,8 +240,8 @@
 
 int service_client(int client)
 {
-	enum capangel_req_t req;
-	struct cap_wire_datum *d = cap_recv(client);
+	enum ua_request_t req;
+	struct ua_datum *d = ua_recv(client, NULL, NULL);
 
 	if(!d)
 	{
@@ -253,19 +255,19 @@
 
 
 	int bytes = 0;
-	if(sizeof(enum capangel_req_t) == sizeof(int32_t))
-		bytes = cap_unmarshall_int(d, (int32_t*) &req);
+	if(sizeof(enum ua_request_t) == sizeof(int32_t))
+		bytes = ua_unmarshall_int(d, (int32_t*) &req);
 
 	else
 	{
 		sprintf(current_error, "enum size is %iB",
-		                       sizeof(enum capangel_req_t));
+		                       sizeof(enum ua_request_t));
 		return -1;
 	}
 
 	if(bytes < 0)
 	{
-		strcpy(current_error, cap_protocol_error());
+		strcpy(current_error, ua_protocol_error());
 		return -1;
 	}
 
@@ -279,17 +281,19 @@
 }
 
 
-int handle_request(int client, enum capangel_req_t req)
+int handle_request(int client, enum ua_request_t req)
 {
 	printf("Client %4i: ", client);
 
 	switch(req)
 	{
-		case FD_FROM_PATH:
+//		case FD_FROM_PATH:
+		case UA_OPEN_PATH:
 			puts("FD_FROM_PATH");
 			return handle_path_request(client);
 
-		case FD_POWERBOX:
+//		case FD_POWERBOX:
+		case UA_POWERBOX:
 			puts("FD_POWERBOX");
 			return handle_powerbox_request(client);
 
@@ -304,28 +308,28 @@
 
 int handle_path_request(int client)
 {
-	int fdlen = 0;
+	unsigned int fdlen = 0;
 	char path[256] = "";
-	int pathlen = 256;
+	unsigned int pathlen = 256;
 
-	struct cap_wire_datum *d = cap_recv_fds(client, NULL, &fdlen);
-	if(cap_unmarshall_string(d, path, &pathlen) < 0)
+	struct ua_datum *d = ua_recv(client, NULL, &fdlen);
+	if(ua_unmarshall_string(d, path, &pathlen) < 0)
 	{
-		strcpy(current_error, cap_protocol_error());
+		strcpy(current_error, ua_protocol_error());
 		return -1;
 	}
 	free(d);
 
 	int32_t flags, rights;
-	if(cap_unmarshall_int(cap_recv(client), &flags) < 0)
+	if(ua_unmarshall_int(ua_recv(client, NULL, NULL), &flags) < 0)
 	{
-		fprintf(stderr, "Error unmarshalling flags: %s\n", cap_protocol_error());
+		fprintf(stderr, "Error unmarshalling flags: %s\n", ua_protocol_error());
 		return -1;
 	}
 
-	if(cap_unmarshall_int(cap_recv(client), &rights) < 0)
+	if(ua_unmarshall_int(ua_recv(client, NULL, NULL), &rights) < 0)
 	{
-		fprintf(stderr, "Error unmarshalling rights: %s\n", cap_protocol_error());
+		fprintf(stderr, "Error unmarshalling rights: %s\n", ua_protocol_error());
 		return -1;
 	}
 
@@ -337,28 +341,28 @@
 		return -1;
 	}
 
-	d = cap_marshall_int(1);
+	d = ua_marshall_int(1);
 	if(!d)
 	{
-		strcpy(current_error, cap_protocol_error());
+		strcpy(current_error, ua_protocol_error());
 		return -1;
 	}
 
-	if(cap_send(client, d) < 0)
+	if(ua_send(client, d, NULL, 0) < 0)
 	{
 		sprintf(current_error, "Error sending FD count: %s", strerror(errno));
 		return -1;
 	}
 	free(d);
 
-	d = cap_marshall_string(path, pathlen);
+	d = ua_marshall_string(path, pathlen);
 	if(!d)
 	{
-		strcpy(current_error, cap_protocol_error());
+		strcpy(current_error, ua_protocol_error());
 		return -1;
 	}
 
-	if(cap_send_fd(client, d, &cap, 1) < 0)
+	if(ua_send(client, d, &cap, 1) < 0)
 	{
 		sprintf(current_error, "Error sending FD: %i (%s)",
 		                        errno, strerror(errno));
@@ -373,19 +377,19 @@
 
 int handle_powerbox_request(int client)
 {
-	struct capbox_options options;
-	int fdlen = 1;
+	struct ua_powerbox_options options;
+	unsigned int fdlen = 1;
 
-	struct cap_wire_datum *d = cap_recv_fds(client, &options.start_fd, &fdlen);
+	struct ua_datum *d = ua_recv(client, &options.start_fd, &fdlen);
 	if(!d)
 	{
 		perror("Error receiving powerbox options");
 		return -1;
 	}
 
-	if(cap_unmarshall_capbox(d, &options) < 0)
+	if(ua_unmarshall_powerbox(d, &options) < 0)
 	{
-		strcpy(current_error, cap_protocol_error());
+		strcpy(current_error, ua_protocol_error());
 		return -1;
 	}
 
@@ -408,8 +412,8 @@
 	free(options.window_title);
 
 
-	struct cap_wire_datum *fdcount = cap_marshall_int(len);
-	if(cap_send(client, fdcount) < 0)
+	struct ua_datum *fdcount = ua_marshall_int(len);
+	if(ua_send(client, fdcount, NULL, 0) < 0)
 	{
 		perror("Error sending FD count");
 		return -1;
@@ -418,10 +422,10 @@
 	for(int i = 0; i < len; i++)
 	{
 		const char *name = names[i];
-		struct cap_wire_datum *d
-			= cap_marshall_string(name, strlen(name));
+		struct ua_datum *d
+			= ua_marshall_string(name, strlen(name));
 
-		if(cap_send_fd(client, d, fds + i, 1) < 0)
+		if(ua_send(client, d, fds + i, 1) < 0)
 		{
 			printf("Error sending file descriptor");
 			return -1;
@@ -439,11 +443,11 @@
 	if((errnum == ECONNRESET) || (errnum == EAGAIN))
 		printf(" (client connection closed)");
 	else
-       		printf(" (errno: %i/'%s', reason: '%s')",
-		        errnum, strerror(errnum), reason);
+       		printf(" (reason: '%s', errno: %i/'%s')",
+		        reason, errnum, strerror(errnum));
 	printf("\n");
 
-	cap_send(client, cap_marshall_error(errnum, reason, strlen(reason)));
+	ua_send(client, ua_marshall_error(errnum, reason, strlen(reason)), NULL, 0);
 
 	close(client);
 	FD_CLR(client, &clients);

==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/test_client.c#10 (text+ko) ====

@@ -3,6 +3,8 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#include <libuserangel.h>
+
 #include <err.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -11,9 +13,7 @@
 #include <sysexits.h>
 #include <unistd.h>
 
-#include "protocol.h"
 
-
 int connect_to_user_angel(void);
 void open_file(int fd_angel, const char *path, int flags, cap_rights_t rights);
 void open_powerbox(int fd_angel, const char *path, const char *filter, int parent);
@@ -48,12 +48,12 @@
 
 
 	// receive server 'hello'
-	struct cap_wire_datum *hello_datum = cap_recv(fd_angel);
+	struct ua_datum *hello_datum = ua_recv(fd_angel, NULL, NULL);
 	if(!hello_datum) err(EX_IOERR, "Error receiving server 'hello'");
 
-	int hellolen = 80;
+	unsigned int hellolen = 80;
 	char hello[hellolen];
-	if(cap_unmarshall_string(hello_datum, hello, &hellolen) < 0)
+	if(ua_unmarshall_string(hello_datum, hello, &hellolen) < 0)
 		err(EX_SOFTWARE, "Error unmarshalling server 'hello'");
 
 	free(hello_datum);
@@ -97,15 +97,16 @@
 void open_file(int fd_angel, const char *path, int flags, cap_rights_t rights)
 {
 	// get the user angel to open the file for us
-	struct cap_wire_datum *data[4];
-	data[0] = cap_marshall_int(FD_FROM_PATH);
-	data[1] = cap_marshall_string(path, strlen(path));
-	data[2] = cap_marshall_int(flags);
-	data[3] = cap_marshall_int(rights);
+	struct ua_datum *data[4];
+	data[0] = ua_marshall_int(UA_OPEN_PATH);
+	data[1] = ua_marshall_string(path, strlen(path));
+	data[2] = ua_marshall_int(flags);
+	data[3] = ua_marshall_int(rights);
 
 
-	if(cap_send_message(fd_angel, data, 4) < 0)
-		err(EX_IOERR, "Error sending request message");
+	for(int i = 0; i < 4; i++)
+		if(ua_send(fd_angel, data[i], NULL, 0) < 0)
+			err(EX_IOERR, "Error sending request message");
 
 	free(data[0]);
 	free(data[1]);
@@ -115,27 +116,27 @@
 
 
 	// retrieve the file descriptor(s)
-	struct cap_wire_datum *fdcountd = cap_recv(fd_angel);
+	struct ua_datum *fdcountd = ua_recv(fd_angel, NULL, NULL);
 	if(!fdcountd) err(EX_IOERR, "Error receiving FD count");
 
 	int fdcount;
-	if(cap_unmarshall_int(fdcountd, &fdcount) < 0)
+	if(ua_unmarshall_int(fdcountd, &fdcount) < 0)
 	{
 		fprintf(stderr, "Error unmarshalling FD count: %s\n",
-		                 cap_protocol_error());
+		                 ua_protocol_error());
 		return;
 	}
 
 	for(int i = 0; i < fdcount; i++)
 	{
 		int32_t fd;
-		int fdlen = 1;
-		struct cap_wire_datum *fd_datum = cap_recv_fds(fd_angel, &fd, &fdlen);
+		unsigned int fdlen = 1;
+		struct ua_datum *fd_datum = ua_recv(fd_angel, &fd, &fdlen);
 		if(!fd_datum) err(EX_IOERR, "Error receiving FD %i of %i", i, fdcount);
 
-		int namelen = 80;
+		unsigned int namelen = 80;
 		char name[namelen];
-		if(cap_unmarshall_string(fd_datum, name, &namelen) < 0)
+		if(ua_unmarshall_string(fd_datum, name, &namelen) < 0)
 			err(EX_SOFTWARE, "Error unmarshalling FD name");
 
 		if(fdlen != 1)
@@ -152,9 +153,9 @@
 
 void open_powerbox(int fd_angel, const char *path, const char *filter, int parent)
 {
-	struct capbox_options options;
-	options.ui = KDE;
-	options.operation = OPEN_FILE;
+	struct ua_powerbox_options options;
+	options.ui = UA_KDE;
+	options.operation = UA_OPEN_FILE;
 	options.parent_window = parent;
 	options.start_path = path;
 	options.pathlen = strlen(path);
@@ -166,13 +167,14 @@
 	options.rights = CAP_FSTAT | CAP_READ | CAP_SEEK;
 
 
-	struct cap_wire_datum *data[2];
-	data[0] = cap_marshall_int(FD_POWERBOX);
-	data[1] = cap_marshall_capbox(&options);
+	struct ua_datum *data[2];
+	data[0] = ua_marshall_int(UA_POWERBOX);
+	data[1] = ua_marshall_powerbox(&options);
 
 
-	if(cap_send_message(fd_angel, data, 2) < 0)
-		err(EX_IOERR, "Error sending request message");
+	for(int i = 0; i < 2; i++)
+		if(ua_send(fd_angel, data[i], NULL, 0) < 0)
+			err(EX_IOERR, "Error sending request message");
 
 	free(data[0]);
 	free(data[1]);
@@ -180,27 +182,27 @@
 
 
 	// retrieve the file descriptor(s)
-	struct cap_wire_datum *fdcountd = cap_recv(fd_angel);
+	struct ua_datum *fdcountd = ua_recv(fd_angel, NULL, NULL);
 	if(!fdcountd) err(EX_IOERR, "Error receiving FD count");
 
 	int fdcount;
-	if(cap_unmarshall_int(fdcountd, &fdcount) < 0)
+	if(ua_unmarshall_int(fdcountd, &fdcount) < 0)
 	{
 		fprintf(stderr, "Error unmarshalling FD count: %s\n",
-		                 cap_protocol_error());
+		                 ua_protocol_error());
 		return;
 	}
 
 	for(int i = 0; i < fdcount; i++)
 	{
 		int32_t fd;
-		int fdlen = 1;
-		struct cap_wire_datum *fd_datum = cap_recv_fds(fd_angel, &fd, &fdlen);
+		unsigned int fdlen = 1;
+		struct ua_datum *fd_datum = ua_recv(fd_angel, &fd, &fdlen);
 		if(!fd_datum) err(EX_IOERR, "Error receiving FD %i of %i", i, fdcount);
 
-		int namelen = 80;
+		unsigned int namelen = 80;
 		char name[namelen];
-		if(cap_unmarshall_string(fd_datum, name, &namelen) < 0)
+		if(ua_unmarshall_string(fd_datum, name, &namelen) < 0)
 			err(EX_SOFTWARE, "Error unmarshalling FD name");
 
 		if(fdlen != 1)


More information about the p4-projects mailing list