fix whitespaces
[project/rpcd.git] / session.c
index e053979..fd003ac 100644 (file)
--- a/session.c
+++ b/session.c
@@ -2,7 +2,7 @@
  * rpcd - UBUS RPC server
  *
  *   Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
- *   Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
+ *   Copyright (C) 2013-2014 Jo-Philipp Wich <jow@openwrt.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -580,22 +580,31 @@ rpc_handle_access(struct ubus_context *ctx, struct ubus_object *obj,
 
        blobmsg_parse(perm_policy, __RPC_SP_MAX, tb, blob_data(msg), blob_len(msg));
 
-       if (!tb[RPC_SP_SID] || !tb[RPC_SP_OBJECT] || !tb[RPC_SP_FUNCTION])
+       if (!tb[RPC_SP_SID])
                return UBUS_STATUS_INVALID_ARGUMENT;
 
        ses = rpc_session_get(blobmsg_data(tb[RPC_SP_SID]));
        if (!ses)
                return UBUS_STATUS_NOT_FOUND;
 
-       if (tb[RPC_SP_SCOPE])
-               scope = blobmsg_data(tb[RPC_SP_SCOPE]);
+       blob_buf_init(&buf, 0);
 
-       allow = rpc_session_acl_allowed(ses, scope,
-                                                                       blobmsg_data(tb[RPC_SP_OBJECT]),
-                                                                       blobmsg_data(tb[RPC_SP_FUNCTION]));
+       if (tb[RPC_SP_OBJECT] && tb[RPC_SP_FUNCTION])
+       {
+               if (tb[RPC_SP_SCOPE])
+                       scope = blobmsg_data(tb[RPC_SP_SCOPE]);
+
+               allow = rpc_session_acl_allowed(ses, scope,
+                                               blobmsg_data(tb[RPC_SP_OBJECT]),
+                                               blobmsg_data(tb[RPC_SP_FUNCTION]));
+
+               blobmsg_add_u8(&buf, "access", allow);
+       }
+       else
+       {
+               rpc_session_dump_acls(ses, &buf);
+       }
 
-       blob_buf_init(&buf, 0);
-       blobmsg_add_u8(&buf, "access", allow);
        ubus_send_reply(ctx, req, buf.head);
 
        return 0;
@@ -1188,6 +1197,8 @@ rpc_blob_from_file(const char *path)
        if (len != blob_pad_len(&head))
                goto fail;
 
+       close(fd);
+
        return attr;
 
 fail: