PERFORCE change 168437 for review
Jonathan Anderson
jona at FreeBSD.org
Fri Sep 11 10:34:04 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=168437
Change 168437 by jona at jona-trustedbsd-belle-vmware on 2009/09/11 10:33:21
Let user_angel clients advise the server of their name
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#18 edit
.. //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#15 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.c#18 (text+ko) ====
@@ -56,10 +56,26 @@
int angel = -1;
+
+char client_name[81] = "libuserangel";
+
const char *VERSION = "UA/0.1";
const char *ua_protocol_version() { return VERSION; }
+
+int ua_set_client_name(const char *name)
+{
+ strncpy(client_name, name, 80);
+ if(strnlen(name, 81) > 80)
+ {
+ errno = EOVERFLOW;
+ return -1;
+ }
+ else return 0;
+}
+
+
int ua_find(void)
{
char *homedir = getenv("HOME");
@@ -87,8 +103,8 @@
// receive server 'hello'
- struct ua_datum *hello_datum = ua_recv(angel, NULL, NULL);
- if(!hello_datum)
+ struct ua_datum *d = ua_recv(angel, NULL, NULL);
+ if(!d)
{
int olderrno = errno;
close(angel);
@@ -99,7 +115,7 @@
unsigned int hellolen = 120;
char hello[hellolen];
- if(ua_unmarshall_string(hello_datum, hello, &hellolen) < 0)
+ if(ua_unmarshall_string(d, hello, &hellolen) < 0)
{
int olderrno = errno;
close(angel);
@@ -107,7 +123,7 @@
angel = -1;
return -1;
}
- free(hello_datum);
+ free(d);
// validate server 'hello' message
if(strncmp(hello, "user_angel", 10))
@@ -131,6 +147,31 @@
return -1;
}
+
+ // send client name
+ d = ua_marshall_string(client_name, strnlen(client_name, 80));
+ if(!d)
+ {
+ int olderrno = errno;
+ close(angel);
+ errno = olderrno;
+ angel = -1;
+ return -1;
+ }
+
+ if(ua_send(angel, d, NULL, 0) < 0)
+ {
+ int olderrno = errno;
+ free(d);
+ close(angel);
+ errno = olderrno;
+ angel = -1;
+ return -1;
+ }
+
+ free(d);
+
+
return angel;
}
==== //depot/projects/trustedbsd/capabilities/src/lib/libuserangel/libuserangel.h#15 (text+ko) ====
@@ -50,6 +50,9 @@
/** Version of the User Angel protocol */
const char* ua_protocol_version(void);
+/** Set the client name (to appear in powerboxes, etc.) */
+int ua_set_client_name(const char *client_name);
+
/** Find the user angel (at $HOME/.user-angel or the like) */
int ua_find(void);
More information about the p4-projects
mailing list