ls -l on Android device

Tito farmatito at tiscali.it
Fri Jan 8 13:43:05 UTC 2010


On Friday 08 January 2010 10:28:44 Mike Frysinger wrote:
> On Friday 08 January 2010 02:28:14 Denys Vlasenko wrote:
> > On Fri, Jan 8, 2010 at 6:48 AM, Mike Frysinger <vapier at gentoo.org> wrote:
> > > On Friday 08 January 2010 00:19:39 Tom Spear wrote:
> > >> On Thu, Jan 7, 2010 at 11:11 PM, Mike Frysinger wrote:
> > >> > On Thursday 07 January 2010 23:24:14 Tom Spear wrote:
> > >> >> more importantly, no /etc, so there is no passwd file for performing
> > >> >> uid to user name mappings etc.
> > >> >
> > >> > busybox doesnt query any /etc/ file directly so it doesnt care
> > >> > (ignoring the loginutils that manage the files).  that is up to the C
> > >> > library to manage.
> > >>
> > >> Unless I'm missing something, this comment in procps/ps.c says it does
> > >> care about passwd:
> > >>
> > >>     /* TODO: get_cached_username() returns numeric string if
> > >>      * user has no passwd record, we will display it
> > >>      * left-justified here; too long usernames are shown
> > >>      * as _right-justified_ IDs. Is it worth fixing? */
> > >>
> > >> What did I miss?
> > >
> > > a "passwd record" does not mean it needs /etc/passwd.  read the busybox
> > > code and you'll see that it does not parse /etc/passwd directly in any
> > > way -- it's using the standard functions C library functions to get
> > > records.  if you dig far enough, you end up at libbb/bb_pwd.c
> > 
> > Well, if you selected
> > 
> > CONFIG_USE_BB_PWD_GRP=y
> > CONFIG_USE_BB_SHADOW=y
> > 
> > in your .config, then bbox will use internal version of getpwnam() and
> >  such. So, try switching that off.
> > 
> > And anyway, can you post exact command you run, its output, and how it
> >  differs from "standard" command's output?
> 
> blah, i was looking at /etc/shadow which is only touched by loginutils
> -mikey 
> 
Hi,
my advice is to stay away from bionic libc
as it a a load of crippled crap where most 
passwd management functions are just
stubs that do not return complete passwd
structs. Therefore usally bad things happen...

typedef struct {
    struct passwd  passwd;
    struct group   group;
    char*          group_members[2];
    char           app_name_buffer[32];
    char           group_name_buffer[32];
} stubs_state_t;

static struct passwd*
android_iinfo_to_passwd( struct passwd          *pw,
                         struct android_id_info *iinfo )
{
    pw->pw_name  = (char*)iinfo->name;
    pw->pw_uid   = iinfo->aid;
    pw->pw_gid   = iinfo->aid;
    pw->pw_dir   = "/";
    pw->pw_shell = "/system/bin/sh";
    return pw;
}

static struct group*
android_iinfo_to_group( struct group *gr,
                        struct android_id_info *iinfo )
{
    gr->gr_name   = (char*) iinfo->name;
    gr->gr_gid    = iinfo->aid;
    gr->gr_mem[0] = gr->gr_name;
    gr->gr_mem[1] = NULL;
    return gr;
}

/* translate a uid into the corresponding app_<uid>
 * passwd structure (sets errno to ENOENT on failure)
 */
static struct passwd*
app_id_to_passwd(uid_t  uid, stubs_state_t*  state)
{
    struct passwd*  pw = &state->passwd;

    if (uid < AID_APP) {
        errno = ENOENT;
        return NULL;
    }

    snprintf( state->app_name_buffer, sizeof state->app_name_buffer,
              "app_%u", uid - AID_APP );

    pw->pw_name  = state->app_name_buffer;
    pw->pw_dir   = "/data";
    pw->pw_shell = "/system/bin/sh";
    pw->pw_uid   = uid;
    pw->pw_gid   = uid;

    return pw;
}


To make this work you need to:

1) statically link busybox with uClibc
2) copy the attached passwd,shadow,group and gshadow files
3) set adequate permissions on them

In this way ls will return user and group names as they are hardcoded in
bionic libc.

/* This is the master Users and Groups config for the platform.
** DO NOT EVER RENUMBER.
*/

#define AID_ROOT             0  /* traditional unix root user */

#define AID_SYSTEM        1000  /* system server */

#define AID_RADIO         1001  /* telephony subsystem, RIL */
#define AID_BLUETOOTH     1002  /* bluetooth subsystem */
#define AID_GRAPHICS      1003  /* graphics devices */
#define AID_INPUT         1004  /* input devices */
#define AID_AUDIO         1005  /* audio devices */
#define AID_CAMERA        1006  /* camera devices */
#define AID_LOG           1007  /* log devices */
#define AID_COMPASS       1008  /* compass device */
#define AID_MOUNT         1009  /* mountd socket */
#define AID_WIFI          1010  /* wifi subsystem */
#define AID_ADB           1011  /* android debug bridge (adbd) */
#define AID_INSTALL       1012  /* group for installing packages */
#define AID_MEDIA         1013  /* mediaserver process */
#define AID_DHCP          1014  /* dhcp client */
#define AID_SDCARD_RW     1015  /* external storage write access */
#define AID_VPN           1016  /* vpn system */
#define AID_KEYSTORE      1017  /* keystore subsystem */

#define AID_SHELL         2000  /* adb and debug shell user */
#define AID_CACHE         2001  /* cache access */
#define AID_DIAG          2002  /* access to diagnostic resources */

/* The 3000 series are intended for use as supplemental group id's only.
 * They indicate special Android capabilities that the kernel is aware of. */
#define AID_NET_BT_ADMIN  3001  /* bluetooth: create any socket */
#define AID_NET_BT        3002  /* bluetooth: create sco, rfcomm or l2cap sockets */
#define AID_INET          3003  /* can create AF_INET and AF_INET6 sockets */
#define AID_NET_RAW       3004  /* can create raw INET sockets */
#define AID_NET_ADMIN     3005  /* can configure interfaces and routing tables. */

#define AID_MISC          9998  /* access to misc storage */
#define AID_NOBODY        9999

#define AID_APP          10000 /* first app user */

#if !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
struct android_id_info {
    const char *name;
    unsigned aid;
};

static struct android_id_info android_ids[] = {
    { "root",      AID_ROOT, },
    { "system",    AID_SYSTEM, },
    { "radio",     AID_RADIO, },
    { "bluetooth", AID_BLUETOOTH, },
    { "graphics",  AID_GRAPHICS, },
    { "input",     AID_INPUT, },
    { "audio",     AID_AUDIO, },
    { "camera",    AID_CAMERA, },
    { "log",       AID_LOG, },
    { "compass",   AID_COMPASS, },
    { "mount",     AID_MOUNT, },
    { "wifi",      AID_WIFI, },
    { "dhcp",      AID_DHCP, },
    { "adb",       AID_ADB, },
    { "install",   AID_INSTALL, },
    { "media",     AID_MEDIA, },
    { "shell",     AID_SHELL, },
    { "cache",     AID_CACHE, },
    { "diag",      AID_DIAG, },
    { "net_bt_admin", AID_NET_BT_ADMIN, },
    { "net_bt",    AID_NET_BT, },
    { "sdcard_rw", AID_SDCARD_RW, },
    { "vpn",       AID_VPN, },
    { "keystore",  AID_KEYSTORE, },
    { "inet",      AID_INET, },
    { "net_raw",   AID_NET_RAW, },
    { "net_admin", AID_NET_ADMIN, },
    { "misc",      AID_MISC, },
    { "nobody",    AID_NOBODY, },
};

You should also set:

CONFIG_FIRST_SYSTEM_ID=1000
CONFIG_LAST_SYSTEM_ID=9999

If you plan to use adduser,addgroup applets and

CONFIG_FEATURE_SHADOWPASSWDS=y
CONFIG_USE_BB_PWD_GRP=y
CONFIG_USE_BB_SHADOW=y
CONFIG_USE_BB_CRYPT=y

to be bionic free.
Be aware that in this way uids and gids above 9999
(the ones assigned to android apps) will still show
up numerically as bionic creates them on the fly
as "app_ + uid".
A workaround for this would be to add all possible
app_uid to the passwd files (from 10000 to 65000)
but this is really a waste of space. 

Hope it helps.

Ciao,
Tito

PS.: you should also add a root passwd to the attached passwd or shadow files
as it is left blank
-------------- next part --------------
A non-text attachment was scrubbed...
Name: passwd_files.tar.bz2
Type: application/x-tbz
Size: 709 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20100108/0613f9ca/attachment-0001.bin>


More information about the busybox mailing list