On 15/03/2015 22:00, Luka Perkov wrote:
> Signed-off-by: Luka Perkov <[email protected]>
> ---
>  file.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/file.c b/file.c
> index 54f5d8a..95dd4d4 100644
> --- a/file.c
> +++ b/file.c
> @@ -92,6 +92,7 @@ static const struct blobmsg_policy 
> rpc_file_rb_policy[__RPC_F_RB_MAX] = {
>  enum {
>       RPC_F_RW_PATH,
>       RPC_F_RW_DATA,
> +     RPC_F_RW_MODE,
>       RPC_F_RW_BASE64,
>       __RPC_F_RW_MAX,
>  };
> @@ -99,6 +100,7 @@ enum {
>  static const struct blobmsg_policy rpc_file_rw_policy[__RPC_F_RW_MAX] = {
>       [RPC_F_RW_PATH]   = { .name = "path",   .type = BLOBMSG_TYPE_STRING },
>       [RPC_F_RW_DATA]   = { .name = "data",   .type = BLOBMSG_TYPE_STRING },
> +     [RPC_F_RW_MODE]   = { .name = "mode",   .type = BLOBMSG_TYPE_INT32  },
>       [RPC_F_RW_BASE64] = { .name = "base64", .type = BLOBMSG_TYPE_BOOL   },
>  };
>  
> @@ -372,6 +374,7 @@ rpc_file_write(struct ubus_context *ctx, struct 
> ubus_object *obj,
>  {
>       struct blob_attr *tb[__RPC_F_RW_MAX];
>       bool base64 = false;
> +     mode_t mode = 0644;
>       int fd, rv = 0;
>       void *rbuf;
>       size_t rbuf_len;
> @@ -382,12 +385,16 @@ rpc_file_write(struct ubus_context *ctx, struct 
> ubus_object *obj,
>       if (!tb[RPC_F_RW_PATH] || !tb[RPC_F_RW_DATA])
>               return UBUS_STATUS_INVALID_ARGUMENT;
>  
> -     if ((fd = open(blobmsg_data(tb[RPC_F_RW_PATH]), O_CREAT | O_WRONLY | 
> O_TRUNC)) < 0)
> -             return rpc_errno_status();
> +     if (tb[RPC_F_RW_MODE])
> +             mode = blobmsg_get_u32(tb[RPC_F_RW_MODE]);
>  
>       if (tb[RPC_F_RW_BASE64])
>               base64 = blobmsg_get_bool(tb[RPC_F_RW_BASE64]);
>  
> +     umask(0);

setting umask to 0 and then not resetting it to the old value afterwards
seems wrong.

->> main.c:     umask(0077);

> +     if ((fd = open(blobmsg_data(tb[RPC_F_RW_PATH]), O_CREAT | O_WRONLY | 
> O_TRUNC, mode)) < 0)
> +             return rpc_errno_status();
> +
>       if (base64) {
>               rbuf_len = blobmsg_data_len(tb[RPC_F_RW_DATA]) - 1;
>               rbuf = b64decode(blobmsg_data(tb[RPC_F_RW_DATA]), &rbuf_len);
> 
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to