PERFORCE change 164652 for review
Jonathan Anderson
jona at FreeBSD.org
Thu Jun 18 10:28:49 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164652
Change 164652 by jona at jona-trustedbsd-kentvm on 2009/06/18 10:28:26
capbox_options should include flags and rights requested
Affected files ...
.. //depot/projects/trustedbsd/capabilities/cap-support/kpowerboxserver/kpowerboxserver.cpp#3 edit
.. //depot/projects/trustedbsd/capabilities/cap-support/kpowerboxserver/test.cpp#2 edit
.. //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#17 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/Makefile#6 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.c#4 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.h#4 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#9 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#5 edit
.. //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/test_client.c#6 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/cap-support/kpowerboxserver/kpowerboxserver.cpp#3 (text+ko) ====
@@ -18,6 +18,8 @@
KPowerBoxServer::showKDEPowerbox(int operation, QString title, QString parent,
QString startDir, QString filter, bool allowMultipleSelections)
{
+ std::cout << "Parent window: " << parent.toStdString() << std::endl;
+
if(allowMultipleSelections)
{
// TODO: get KDE to support WId for multi-select dialogs
==== //depot/projects/trustedbsd/capabilities/cap-support/kpowerboxserver/test.cpp#2 (text+ko) ====
@@ -57,11 +57,17 @@
// try opening a file
- QDBusReply<QStringList> reply =
- pboxServer.call("showKDEPowerbox", OPEN_FILE, "Powerbox - open file",
- winid, "~/Desktop/tmp/", "*.py", true);
+ /*
+ QDBusPendingReply<QStringList> reply
+ = pboxServer.asyncCall("showKDEPowerbox", OPEN_FILE, "Powerbox - open file",
+ winid, "~/Desktop/tmp/", "*.py", true);
+ */
+ QDBusReply<QStringList> reply
+ = pboxServer.call("showKDEPowerbox", OPEN_FILE, "Powerbox - open file",
+ winid, "~/Desktop/tmp/", "*.py", true);
- if(reply.isValid())
+// reply.waitForFinished();
+ if(reply.isValid())//isError())
{
cout << "Received the following paths: " << endl;
for(int i = 0; i < reply.value().size(); i++)
@@ -76,19 +82,20 @@
// try opening a directory
reply = pboxServer.call("showKDEPowerbox", SELECT_DIR,
- "Powerbox - select directory", winid, "~/", "", false);
+ "Powerbox - select directory", winid,
+ "~/", "", false);
- if(reply.isValid())
+ if(reply.isValid())//.isError())
+ {
+ cerr << "Invalid reply: " << reply.error().message().toStdString() << endl;
+ return 1;
+ }
+ else
{
cout << "Received the following paths: " << endl;
for(int i = 0; i < reply.value().size(); i++)
cout << " - " << reply.value().at(i).toStdString() << endl;
}
- else
- {
- cerr << "Invalid reply: " << reply.error().message().toStdString() << endl;
- return 1;
- }
return 0;
}
==== //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#17 (text+ko) ====
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#16 $
+ * $P4: //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#17 $
*/
#include <sys/param.h>
@@ -62,13 +62,11 @@
#define LIBCAPABILITY_CAPMASK_LDSO LIBCAPABILITY_CAPMASK_BIN
#define LIBCAPABILITY_CAPMASK_LIBC LIBCAPABILITY_CAPMASK_BIN
#define LIBCAPABILITY_CAPMASK_LIBCAPABILITY LIBCAPABILITY_CAPMASK_BIN
-#define LIBCAPABILITY_CAPMASK_LIBZ LIBCAPABILITY_CAPMASK_BIN
#define LIBCAPABILITY_CAPMASK_LIBBZ2 LIBCAPABILITY_CAPMASK_BIN
#define _PATH_LIB "/lib"
#define _PATH_USR_LIB "/usr/lib"
#define LIBC_SO "libc.so.7"
-#define LIBZ_SO "libz.so.4"
#define LIBBZ2_SO "libbz2.so.3"
#define LIBCAPABILITY_SO "libcapability.so.1"
@@ -168,8 +166,6 @@
return;
if (lc_limitfd(fd_libc, LIBCAPABILITY_CAPMASK_LIBC) < 0)
return;
- if (lc_limitfd(fd_libz, LIBCAPABILITY_CAPMASK_LIBZ) < 0)
- return;
if (lc_limitfd(fd_libbz2, LIBCAPABILITY_CAPMASK_LIBBZ2) < 0)
return;
if (lc_limitfd(fd_libcapability,
@@ -201,8 +197,8 @@
*/
if (asprintf(&env_caplibindex,
"%d:%s,%d:%s,%d:%s,%d:%s,%d:%s,%d:%s,%d:%s",
- 3, binname, 5, LD_ELF_CAP_SO, 6, LIBC_SO, 7, LIBZ_SO, 8,
- LIBBZ2_SO, 9, LIBCAPABILITY_SO, 10, _PATH_DEVNULL) == -1)
+ 3, binname, 5, LD_ELF_CAP_SO, 6, LIBC_SO, 7,
+ LIBBZ2_SO, 8, LIBCAPABILITY_SO, 9, _PATH_DEVNULL) == -1)
return;
if (setenv("LD_CAPLIBINDEX", env_caplibindex, 1) == -1)
return;
@@ -250,8 +246,6 @@
goto out_error;
if (ld_caplibindex_lookup(LIBC_SO, &fd_libc) < 0)
goto out_error;
- if (ld_caplibindex_lookup(LIBZ_SO, &fd_libz) < 0)
- goto out_error;
if (ld_caplibindex_lookup(LIBBZ2_SO, &fd_libbz2) < 0)
goto out_error;
if (ld_caplibindex_lookup(LIBCAPABILITY_SO,
@@ -267,9 +261,6 @@
fd_libc = open(_PATH_LIB "/" LIBC_SO, O_RDONLY);
if (fd_libc < 0)
goto out_error;
- fd_libz = open(_PATH_LIB "/" LIBZ_SO, O_RDONLY);
- if (fd_libz < 0)
- goto out_error;
fd_libbz2 = open(_PATH_USR_LIB "/" LIBBZ2_SO, O_RDONLY);
if (fd_libbz2 < 0)
goto out_error;
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/Makefile#6 (text+ko) ====
@@ -1,23 +1,30 @@
VERSION=dev-pre1
-CFLAGS=-g -ggdb --std=c99 -Wall -Werror -pedantic-errors -DVERSION='"${VERSION}"'
-LDFLAGS=-L/usr/local/lib -lefence
+DEBUG=-g -ggdb
+WARNINGS=-Wall -Werror -pedantic-errors
+
+QDBUS_INCLUDE=-I/usr/local/include/qt4
+QDBUS_LIBS=-L /usr/local/lib/qt4 -lQtDBus
+
+CFLAGS=--std=c99 ${DEBUG} ${WARNINGS} ${INCLUDE} -DVERSION='"${VERSION}"'
+CXXFLAGS=${DEBUG} -Wall ${QDBUS_INCLUDE} -DVERSION='"${VERSION}"'
BIN=user_angel test_client
-AGENT_OBJ = user_angel.o server.o cap.o protocol.o powerbox.o
+AGENT_OBJ = user_angel.o server.o cap.o protocol.o powerbox.o dbus.o
CLIENT_OBJ = test_client.o protocol.o
all: ${BIN}
user_angel: ${AGENT_OBJ}
- ${CC} ${LDFLAGS} -o $@ ${AGENT_OBJ}
+ ${CXX} ${QDBUS_LIBS} -o $@ ${AGENT_OBJ}
test_client: ${CLIENT_OBJ}
- ${CC} ${LDFLAGS} -o $@ ${CLIENT_OBJ}
+ ${CC} -o $@ ${CLIENT_OBJ}
cap.o: cap.c cap.h
-powerbox.o: powerbox.c powerbox.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
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.c#4 (text+ko) ====
@@ -39,11 +39,12 @@
#include <stdlib.h>
#include <string.h>
+#include "dbus.h"
#include "powerbox.h"
-int capbox_display(struct capbox_options *options, int fds[], char *names[],
- int *len)
+int capbox_display(struct capbox_options *options,
+ int fds[], char *names[], int *len)
{
printf("capbox_display()\n");
printf(" options:\n");
@@ -77,6 +78,26 @@
if(options->filterlen > 0) printf("%s\n", options->filter);
else printf("<none>\n");
+ if(dbus_powerbox(options, names, len))
+ {
+ fprintf(stderr, "Error opening powerbox via DBus\n");
+ return -1;
+ }
+
+ printf("File names:\n");
+ for(int i = 0; i < *len; i++)
+ {
+ printf(" %s\n", names[i]);
+ fds[i] = cap_open(names[i], options->flags, options->rights);
+ if(fds[i] < 0)
+ {
+ perror("Error opening file capability");
+ return -1;
+ }
+ }
+
+ return 0;
+
fprintf(stderr, "powerbox not implemented, faking it\n");
if(*len > 0)
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/powerbox.h#4 (text+ko) ====
@@ -32,6 +32,11 @@
*/
+#ifndef POWERBOX_H
+#define POWERBOX_H
+
+#include "cap.h"
+
enum capbox_ui_t { KDE /* TODO, GNOME, NCURSES*/ };
@@ -54,14 +59,25 @@
int mult; /* allow multiple selection */
const char* filter; /* filter expression (or NULL) */
int filterlen; /* length of filter expression */
+ int flags; /* open() flags, e.g. O_RDONLY */
+ cap_rights_t rights; /* capabilities, e.g. CAP_SEEK */
};
/**
* Open a powerbox.
*
+ * @param options powerbox options
+ * @param flags open() flags (e.g. O_RDONLY)
+ * @param rights capabilities requested (e.g. CAP_SEEK)
+ * @param fds an array for file descriptors (size len)
+ * @param names an array for file names (size len)
+ * @param len the length of the above arrays (modified by this call)
+ *
* @return 0 on success
*/
-int capbox_display(struct capbox_options *options, int fds[], char *names[],
- int *len);
+int capbox_display(struct capbox_options *options,
+ int fds[], char *names[], int *len);
+
+#endif
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/protocol.c#9 (text+ko) ====
@@ -164,16 +164,18 @@
wire_datum* cap_marshall_capbox(const struct capbox_options *options)
{
- wire_datum *data[6];
+ wire_datum *data[8];
data[0] = cap_marshall_int(options->ui);
data[1] = cap_marshall_int(options->operation);
data[2] = cap_marshall_int(options->parent_window);
data[3] = cap_marshall_string(options->start_path, options->pathlen);
data[4] = cap_marshall_int(options->mult);
data[5] = cap_marshall_string(options->filter, options->filterlen);
+ data[6] = cap_marshall_int(options->flags);
+ data[7] = cap_marshall_int(options->rights);
int total_size = 0;
- for(int i = 0; i < 6; i++)
+ for(int i = 0; i < 8; i++)
if(data[i] == NULL)
{
sprintf(errmsg, "Capbox datum %i is NULL", i);
@@ -187,7 +189,7 @@
char *buffer = ((char*) d) + sizeof(wire_datum);
char *head = buffer;
- for(int i = 0; i < 6; i++)
+ for(int i = 0; i < 8; i++)
{
memcpy(head, data[i], sizeof(wire_datum) + data[i]->length);
head += sizeof(wire_datum) + data[i]->length;
@@ -290,6 +292,26 @@
strcpy(errmsg, error);
return -1;
}
+ d = (wire_datum*) (((char*) d) + sizeof(wire_datum) + d->length);
+
+ if(cap_unmarshall_int(d, &tmp_int) < 0)
+ {
+ char error[128];
+ sprintf(error, "Error unmarshalling 'flags': %s", cap_error());
+ strcpy(errmsg, error);
+ return -1;
+ }
+ options->flags = tmp_int;
+ d = (wire_datum*) (((char*) d) + sizeof(wire_datum) + d->length);
+
+ if(cap_unmarshall_int(d, &tmp_int) < 0)
+ {
+ char error[128];
+ sprintf(error, "Error unmarshalling 'rights': %s", cap_error());
+ strcpy(errmsg, error);
+ return -1;
+ }
+ options->rights = tmp_int;
return sizeof(wire_datum) + datum->length;
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/server.c#5 (text+ko) ====
@@ -20,7 +20,9 @@
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * IMPLIED WARRANT#
+#
+IES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
@@ -51,7 +53,7 @@
int shutting_down = 0;
char control_socket_name[256] = "";
-struct fd_set sockets;
+struct fd_set clients;
int highest_fd;
@@ -67,12 +69,12 @@
-int handle_request(int client, enum capangel_req_t req);
-int bind_to_path(const char *path);
-void accept_client(int fd_server);
-void service_clients(void);
-void serve(int fd_server, struct fd_set *sockets);
-void client_closed(int client);
+int handle_request(int client, enum capangel_req_t req);
+int bind_to_path(const char *path);
+void serve(int fd_server, struct fd_set *clients);
+void accept_client(int fd_server);
+int service_client(int client);
+void client_closed(int client);
@@ -90,7 +92,7 @@
}
- while(fd_control) serve(fd_control, &sockets);
+ while(fd_control) serve(fd_control, &clients);
user_angel_server_shutdown();
return 0;
@@ -99,7 +101,7 @@
int bind_to_path(const char *path)
{
- FD_ZERO(&sockets);
+ FD_ZERO(&clients);
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
@@ -157,7 +159,7 @@
return -1;
}*/
- FD_SET(fd, &sockets);
+ FD_SET(fd, &clients);
@@ -186,7 +188,7 @@
printf("Client %4i: Accepted\n", client);
- FD_SET(client, &sockets);
+ FD_SET(client, &clients);
if(client > highest_fd) highest_fd = client;
char hello[80];
@@ -199,10 +201,10 @@
-void serve(int fd_server, struct fd_set *sockets)
+void serve(int fd_server, struct fd_set *clients)
{
struct fd_set selected;
- memcpy(&selected, sockets, sizeof(*sockets));
+ memcpy(&selected, clients, sizeof(*clients));
int ready = select(highest_fd + 1, &selected, NULL, NULL, NULL);
@@ -222,46 +224,54 @@
if(FD_ISSET(i, &selected))
{
if(i == fd_server) accept_client(i);
- else
- {
- enum capangel_req_t req;
- struct cap_wire_datum *d = cap_recv(i);
+ else if FD_ISSET(i, clients) service_client(i);
+
+ ready--;
+ }
+ }
+}
+
+
+int service_client(int client)
+{
+ enum capangel_req_t req;
+ struct cap_wire_datum *d = cap_recv(client);
- if(!d)
- {
- if((errno == ENOENT) || (errno == ECONNRESET)) client_closed(i);
- else perror("Error receiving from client");
+ if(!d)
+ {
+ if((errno == ENOENT) || (errno == ECONNRESET))
+ client_closed(client);
- continue;
- }
+ else perror("Error receiving from client");
+ return -1;
+ }
- int bytes = 0;
- if(sizeof(enum capangel_req_t) == sizeof(int32_t))
- bytes = cap_unmarshall_int(d, (int32_t*) &req);
- else
- {
- fprintf(stderr, "enum size is %iB\n", sizeof(enum capangel_req_t));
- return;
- }
+ int bytes = 0;
+ if(sizeof(enum capangel_req_t) == sizeof(int32_t))
+ bytes = cap_unmarshall_int(d, (int32_t*) &req);
- if(bytes < 0)
- {
- fprintf(stderr, "Error unmarshalling request: %s\n", cap_error());
- continue;
- }
+ else
+ {
+ fprintf(stderr, "enum size is %iB\n", sizeof(enum capangel_req_t));
+ return -1;
+ }
- if(handle_request(i, req))
- {
- perror("Error handling client request");
- client_closed(i);
- }
- }
+ if(bytes < 0)
+ {
+ fprintf(stderr, "Error unmarshalling request: %s\n", cap_error());
+ return -1;
+ }
- ready--;
- }
+ if(handle_request(client, req))
+ {
+ perror("Error handling client request");
+ client_closed(client);
+ return 0;
}
+
+ return 0;
}
@@ -400,10 +410,10 @@
{
printf("Client %4i: Closed\n", client);
close(client);
- FD_CLR(client, &sockets);
+ FD_CLR(client, &clients);
if(client == highest_fd)
- while(!FD_ISSET(highest_fd, &sockets))
+ while(!FD_ISSET(highest_fd, &clients))
highest_fd--;
}
==== //depot/projects/trustedbsd/capabilities/src/tools/cap/user_angel/test_client.c#6 (text+ko) ====
@@ -16,7 +16,7 @@
int connect_to_user_angel(void);
void open_file(int fd_angel, const char *path);
-void open_powerbox(int fd_angel, const char *path, const char *filter);
+void open_powerbox(int fd_angel, const char *path, const char *filter, int parent);
int main(int argc, char *argv[])
@@ -62,7 +62,7 @@
open_file(fd_angel, "/etc/group");
open_file(fd_angel, "/etc/passwd");
- open_powerbox(fd_angel, "~/Desktop/", "*.py");
+ open_powerbox(fd_angel, "~/Desktop/", "*.txt", 0x2a00003);
return 0;
}
@@ -144,12 +144,12 @@
}
-void open_powerbox(int fd_angel, const char *path, const char *filter)
+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;
- options.parent_window = 0;
+ options.parent_window = parent;
options.start_path = path;
options.pathlen = strlen(path);
options.start_fd = -1;
More information about the p4-projects
mailing list