clean up in android.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Would anyone object to me cleaning up the setcon and setfilecon2 code that does the mls level stuff:

Currently the below code is duplicated:

pw = getpwuid(uid);
if (!pw)
goto err;
username = pw->pw_name;

if (!strncmp(username, "app_", 4)) {
id = strtoul(username + 4, NULL, 10);
if (id >= MLS_CATS)
goto err;
} else if (username[0] == 'u' && isdigit(username[1])) {
unsigned long unused;
unused = strtoul(username+1, &end, 10);
if (end[0] != '_')
goto err;
id = strtoul(end + 2, NULL, 10);
if (id >= MLS_CATS/2)
goto err;
if (end[1] == 'i')
id += MLS_CATS/2;
else if (end[1] != 'a')
goto err;
/* use app_ for matching on the user= field */
username = "app_";
}

I want to break it up into two functions.

1. that gets the normalized username
2. that computes the id, takes username, returns -1 on error


This way of the username stuff changes again in the future, we can normalize it one spot. The one that computes the id doesn't gain much by putting it in a function, but I think it will make the code more readable.

--
Respectfully,

William C Roberts



[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux