busybox with single applet enabled
Tito
farmatito at tiscali.it
Fri May 20 20:41:29 UTC 2011
On Friday 20 May 2011 21:33:05 Tito wrote:
>
> On Friday 20 May 2011 20:08:30 you wrote:
> > To Tito:
> > > Maybe something like this in adduser.c:
> > >
> > > /* We assume that if bb's addgroup applet is enabled we will use it */
> > > if (ENABLE_ADDGROUP && !ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS) {
> > > argv[1] = (char*)"-g";
> > > } else {
> > > /* external addgroup or bb's addgroup with long options */
> > > argv[1] = (char*)"--gid";
> > > }
> > > argv[2] = utoa(p->pw_gid);
> > > argv[3] = (char*)"--";
> > > argv[4] = p->pw_name;
> > > argv[5] = NULL;
> > >
> > > Untested, just an idea.
> > > Ciao,
> > > Tito
> >
> > Tito, I think your code is fine for common case, but won't work in
> > corner ones: let's assume that you configured busybox with adduser
> > support (without long options), may be even installed it, but then you
> > installed (let it be desktop system) adduser package. Your wrapper
> > script was rewritten by full-blown adduser, but condition in if
> > remains true => -g option used.
>
> In fact my target was to fix the compatibility issue trying to detect
> some sane defaults that do not increase codesize, of course
> there will be always corner cases, but it will be impossibile
> to take care of all.
A solution could be:
--- loginutils/adduser.c.original 2011-05-18 23:21:11.000000000 +0200
+++ loginutils/adduser.c 2011-05-20 22:20:38.000000000 +0200
@@ -93,8 +93,9 @@ static void addgroup_wrapper(struct pass
argv[4] = NULL;
} else {
/* Add user to his own group with the first free gid found in passwd_study */
-//TODO: to be compatible with external addgroup programs we should use --gid instead...
- argv[1] = (char*)"-g";
+ /* To be compatible with external addgroup programs we use --gid */
+ /* bb's addgroup handles this even if long options are disabled */
+ argv[1] = (char*)"--gid";
argv[2] = utoa(p->pw_gid);
argv[3] = (char*)"--";
argv[4] = p->pw_name;
--- loginutils/addgroup.c.original 2011-04-03 22:55:23.000000000 +0200
+++ loginutils/addgroup.c 2011-05-20 22:27:09.000000000 +0200
@@ -134,6 +134,13 @@ int addgroup_main(int argc UNUSED_PARAM,
}
#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS
applet_long_options = addgroup_longopts;
+#else
+ /* Handle this long flag to fix bb's adduser compatibility issues
+ with external addgroup programs */
+ if (strcmp(argv[1], "--gid") == 0) {
+ argv[1][1] = 'g';
+ argv[1][2] = 0;
+ }
#endif
/* Syntax:
* addgroup group
---------------------------------------------------------------------------------------------------------------------------------
This is rather a UGLY(Tm) hack and is only compile tested.
Ciao,
Tito
> >
> > To Ralf:
> > Of course I use symlink now, ./applet -> ./busybox in my description
> > points to it =). I investigated this issue just because I thought that
> > it is busybox bug and wanted to solve it.
> > But may be It is better to warn others at compiling stage by final
> > message when result of compilation is reported.
> >
>
PS.: by thinking more about it I would dare say that it is not a bug:
you can not name a single applet binary "busybox" as default.
What would you then do if you have more single applet binaries
on your system? There is only one solution: name them by
the applet, therefore you don't need the "parse argv[0] == busybox"
code. Looks like sane default to me.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: adduser_addgroup_ugly_hack.patch
Type: text/x-diff
Size: 1333 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20110520/01ea52b3/attachment.bin>
More information about the busybox
mailing list