[Toybox] Regarding smack behavior of ls command

Hyejin Kim hj8296 at gmail.com
Sun May 17 20:26:18 PDT 2015


Hi.

Recently smack feature is added by ls command only and I tested it on
emulator of tizen platform.
But, some operations are not proper at my point of view and I'll share them.

Below is the smack code at seclabel().
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  } else if (CFG_TOYBOX_SMACK) {
    int fd = openat(dirtree_parentfd(dt), dt->name, O_PATH|O_NOFOLLOW);
    char buf[SMACK_LABEL_LEN+1];
    ssize_t len = 1;
    strcpy(buf, "?");
    if (fd != -1) {
      len = fgetxattr(fd, XATTR_NAME_SMACK, pad?buf:0,
pad?SMACK_LABEL_LEN:0);
      close(fd);
      if (len<1 || len>SMACK_LABEL_LEN) len = 0;
      else buf[len] = 0;
    }
    if (pad) printf(" %*s "+(pad>0), pad, buf);
    return len;
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

1. At first, fd is wrong. So, cant call fgetxattr() and print ? for label.

2. 3rd and 4th param of fgetxattr() is changable for __pad__. but why
should the __pad__ affect them?

3. If it is hard to get fd, can change to call getxattr() with filepath
instead of calling fgetxattr with fd. I got a right result on emulator with
belowing example.

For example :

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  } else if (CFG_TOYBOX_SMACK) {
    char* path = dirtree_path(dt, 0);
    char buf[SMACK_LABEL_LEN+1];
    ssize_t len = 1;
    strcpy(buf, "?");
    if (path) {
      len = getxattr(path, XATTR_NAME_SMACK, buf, SMACK_LABEL_LEN);
      if (len<1 || len>SMACK_LABEL_LEN) len = 0;
      else buf[len] = 0;
    }
    printf(" %*s "+(pad>0), pad, buf);
    return len;
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Can anyone give me an opinion?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150518/edcb6b41/attachment.htm>


More information about the Toybox mailing list