PERFORCE change 174074 for review
Jonathan Anderson
jona at FreeBSD.org
Mon Feb 1 11:13:51 UTC 2010
http://p4web.freebsd.org/chv.cgi?CH=174074
Change 174074 by jona at jona-belle-freebsd8 on 2010/02/01 11:13:15
Added ld_fdlist_append(), plus one sanity check and the ability to ignore names in lc_fdlist_lookup()
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/lib/libcapsicum/libcapsicum_fdlist.c#6 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/lib/libcapsicum/libcapsicum_fdlist.c#6 (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/libcapsicum/libcapsicum_fdlist.c#5 $
+ * $P4: //depot/projects/trustedbsd/capabilities/src/lib/libcapsicum/libcapsicum_fdlist.c#6 $
*/
#include <sys/mman.h>
@@ -296,6 +296,43 @@
int
+lc_fdlist_append(struct lc_fdlist **to, struct lc_fdlist *from) {
+
+ if ((to == NULL) || (*to == NULL) || (from == NULL)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ LOCK(*to);
+ LOCK(from);
+
+ int pos = 0;
+ for (unsigned int i = 0; i < from->count; i++) {
+ char *subsystem;
+ char *classname;
+ char *name;
+ int fd;
+
+ if (lc_fdlist_getentry(from, &subsystem, &classname, &name, &fd,
+ &pos) < 0)
+ return (-1);
+
+ if (lc_fdlist_add(to, subsystem, classname, name, fd) < 0) {
+ free(subsystem);
+ return (-1);
+ }
+
+ free(subsystem);
+ }
+
+ UNLOCK(from);
+ UNLOCK(*to);
+
+ return 0;
+}
+
+
+int
lc_fdlist_addcap(struct lc_fdlist **fdlist,
const char *subsystem, const char *id,
const char *name, int fd, cap_rights_t rights) {
@@ -311,7 +348,7 @@
const char *subsystem, const char *id, char **name, int *fdp,
int *pos) {
- if (l == NULL) {
+ if ((l == NULL) || (fdp == NULL)) {
errno = EINVAL;
return (-1);
}
@@ -337,8 +374,11 @@
!strncmp(id, names + entry->classoff, entry->classlen + 1))) {
/* found a matching entry! */
- *name = malloc(entry->namelen + 1);
- strncpy(*name, names + entry->nameoff, entry->namelen + 1);
+ if (name) {
+ *name = malloc(entry->namelen + 1);
+ strncpy(*name, names + entry->nameoff,
+ entry->namelen + 1);
+ }
*fdp = entry->fd;
More information about the p4-projects
mailing list