#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
-#if !TARGET_OS_EMBEDDED
+#include <TargetConditionals.h>
#include <membership.h>
#include <membershipPriv.h>
-#endif
#include <uuid/uuid.h>
#endif
#include <signal.h>
#endif
#include <stdint.h> /* intmax_t */
+#include <assert.h>
#ifdef __APPLE__
#include <get_compat.h>
#else
{
FTSENT *p;
- if (COMPAT_MODE("bin/ls", "Unix2003")) {
+ assert(dp);
+ if (COMPAT_MODE("bin/ls", "Unix2003") && (dp->list != NULL)) {
if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
(void)printf("total %qu\n", (u_int64_t)howmany(dp->btotal, blocksize));
}
static char *
uuid_to_name(uuid_t *uu)
{
-#if TARGET_OS_EMBEDDED
- return strdup("<UNKNOWN>");
-#else /* !TARGET_OS_EMBEDDED */
- int is_gid = -1;
- struct group *tgrp = NULL;
- struct passwd *tpass = NULL;
- char *name = NULL;
- uid_t id;
-
-
+ int type;
+ char *name = NULL;
+ char *recname = NULL;
+
#define MAXNAMETAG (MAXLOGNAME + 6) /* + strlen("group:") */
- name = (char *) malloc(MAXNAMETAG);
-
- if (NULL == name)
- err(1, "malloc");
-
- if (!f_numericonly) {
- if (0 != mbr_uuid_to_id(*uu, &id, &is_gid))
- goto errout;
+ name = (char *) malloc(MAXNAMETAG);
+
+ if (NULL == name) {
+ err(1, "malloc");
}
-
- switch (is_gid) {
- case ID_TYPE_UID:
- tpass = getpwuid(id);
- if (!tpass) {
- goto errout;
- }
- snprintf(name, MAXNAMETAG, "%s:%s", "user", tpass->pw_name);
- break;
- case ID_TYPE_GID:
- tgrp = getgrgid((gid_t) id);
- if (!tgrp) {
- goto errout;
- }
- snprintf(name, MAXNAMETAG, "%s:%s", "group", tgrp->gr_name);
- break;
- default:
+
+ if (f_numericonly) {
+ goto errout;
+ }
+
+ if (mbr_identifier_translate(ID_TYPE_UUID, *uu, sizeof(*uu), ID_TYPE_NAME, (void **) &recname, &type)) {
goto errout;
- }
- return name;
- errout:
- if (0 != mbr_uuid_to_string(*uu, name)) {
- fprintf(stderr, "Unable to translate qualifier on ACL\n");
- strcpy(name, "<UNKNOWN>");
}
- return name;
-#endif /* !TARGET_OS_EMBEDDED */
+
+ snprintf(name, MAXNAMETAG, "%s:%s", (type == MBR_REC_TYPE_USER ? "user" : "group"), recname);
+ free(recname);
+
+ return name;
+errout:
+ uuid_unparse_upper(*uu, name);
+
+ return name;
}
static void
-printxattr(DISPLAY *dp, char *filename, ssize_t xattr)
+printxattr(DISPLAY *dp, int count, char *buf, int sizes[])
{
- int flags = XATTR_NOFOLLOW;
- char *buf = malloc(xattr);
-
- if (NULL == buf)
- err(1, "malloc");
- if (listxattr(filename, buf, xattr, flags) > 0) {
- char *name;
- for (name = buf; name < buf+xattr; name += strlen(name) + 1) {
- ssize_t size = getxattr(filename, name, 0, 0, 0, flags);
- putchar('\t');
- printname(name);
- putchar('\t');
- printsize(dp->s_size, size);
- putchar('\n');
- }
+ for (int i = 0; i < count; i++) {
+ putchar('\t');
+ printname(buf);
+ putchar('\t');
+ printsize(dp->s_size, sizes[i]);
+ putchar('\n');
+ buf += strlen(buf) + 1;
}
- free(buf);
}
static void
FTSENT *p;
NAMES *np;
char buf[20];
-#ifdef __APPLE__
- acl_t acl = NULL;
- acl_entry_t dummy;
- char full_path[MAXPATHLEN];
- char *filename;
- ssize_t xattr = 0;
- char str[2];
-#endif
#ifdef COLORLS
int color_printed = 0;
#endif
np = p->fts_pointer;
#ifdef __APPLE__
buf[10] = '\0'; /* make +/@ abut the mode */
- filename = p->fts_name;
- if (p->fts_level != FTS_ROOTLEVEL)
- {
- snprintf(full_path, sizeof full_path, "%s/%s",
- p->fts_parent->fts_accpath, p->fts_name);
- filename = full_path;
- }
- /* symlinks can not have ACLs */
- acl = acl_get_link_np(filename, ACL_TYPE_EXTENDED);
- if (acl && acl_get_entry(acl, ACL_FIRST_ENTRY, &dummy) == -1) {
- acl_free(acl);
- acl = NULL;
- }
- xattr = listxattr(filename, NULL, 0, XATTR_NOFOLLOW);
- if (xattr < 0)
- xattr = 0;
- str[1] = '\0';
- if (xattr > 0)
- str[0] = '@';
- else if (acl != NULL)
- str[0] = '+';
- else
- str[0] = ' ';
+ char str[2] = { np->mode_suffix, '\0' };
#endif /* __APPLE__ */
if (f_group && f_owner) { /* means print neither */
#ifdef __APPLE__
printlink(p);
(void)putchar('\n');
#ifdef __APPLE__
- if (f_xattr && xattr) {
- printxattr(dp, filename, xattr);
+ if (np->xattr_count && f_xattr) {
+ printxattr(dp, np->xattr_count, np->xattr_names, np->xattr_sizes);
}
- if (acl != NULL) {
- if (f_acl)
- printacl(acl, S_ISDIR(sp->st_mode));
- acl_free(acl);
- acl = NULL;
+ if (np->acl != NULL && f_acl) {
+ printacl(np->acl, S_ISDIR(sp->st_mode));
}
#endif /* __APPLE__ */
}
* Have to do random access in the linked list -- build a table
* of pointers.
*/
- if (dp->entries > lastentries) {
+ if ((lastentries == -1) || (dp->entries > lastentries)) {
lastentries = dp->entries;
- if ((array =
- realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
+ if ((array = realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
warn(NULL);
printscol(dp);
+ return;
}
}
+ memset(array, 0, dp->entries * sizeof(FTSENT *));
for (p = dp->list, num = 0; p; p = p->fts_link)
if (p->fts_number != NO_PRINT)
array[num++] = p;
if (num % numcols)
++numrows;
+ assert(dp->list);
if (dp->list->fts_level != FTS_ROOTLEVEL && (f_longform || f_size))
(void)printf("total %qu\n", (u_int64_t)howmany(dp->btotal, blocksize));
if (!f_sortacross)
base = row;
for (col = 0, chcnt = 0; col < numcols; ++col) {
- chcnt += printaname(array[base], dp->s_inode,
- dp->s_block);
+ assert(base < dp->entries);
+ chcnt += printaname(array[base], dp->s_inode, dp->s_block);
if (f_sortacross)
base++;
else