<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:admin="http://webns.net/mvcb/"
>
<channel>
<title>[www.tuxx-home.at] - Website of Alexander Griesser</title>
<link>http://www.tuxx-home.at/archives/cat_1/</link>
<description>News from the front</description>
<dc:language>en-us</dc:language>
<dc:creator>Alexander Griesser</dc:creator>
<dc:date>2007-11-11T10:32:22+01:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />
<item>
<link>http://www.tuxx-home.at/archives/2005/06/21/T08_44_39/</link>
<title>busybox id -G patch</title>
<dc:date>2005-06-21T08:44:39+01:00</dc:date>
<dc:creator>Alexander Griesser</dc:creator>
<dc:subject>Busybox</dc:subject>
<description><![CDATA[Today I enhanced the busybox &quot;id&quot; command with the -G option which
is used to print out all groups a user belongs to (instead of -g which just
prints the users gid).<br />
The following diff allows busybox's id command to handle -G and -Gn (which 
would display the names instead of the gids). The output is the same as
with GNU id.<br />
<pre>
diff -Nur busybox/coreutils/id.c busybox.new/coreutils/id.c
--- busybox/coreutils/id.c      2005-06-20 08:20:09.000000000 +0200
+++ busybox.new/coreutils/id.c  2005-06-21 08:22:29.226988717 +0200
@@ -23,6 +23,7 @@
 /* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */
 /* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever length and to
  * be more similar to GNU id.
+ * -G and -Gn implemented by Alexander Griesser [busybox@tuxx-home.at] 2005
  */

 #include "busybox.h"
@@ -30,6 +31,7 @@
 #include &lt;stdio.h&gt;
 #include &lt;unistd.h&gt;
 #include &lt;sys/types.h&gt;
+#include &lt;grp.h&gt;

 #ifdef CONFIG_SELINUX
 #include &lt;selinux/selinux.h&gt;          /* for is_selinux_enabled() */
@@ -39,6 +41,7 @@
 #define NAME_NOT_NUMBER   2
 #define JUST_USER         4
 #define JUST_GROUP        8
+#define JUST_GROUP_LIST  16

 static short printf_full(unsigned int id, const char *arg, const char prefix)
 {
@@ -53,6 +56,16 @@
        return status;
 }

+static void print_group(gid_t gid, int use_name)
+{
+       struct group *grp = NULL;
+       grp = getgrgid(gid);
+       if(use_name)
+         bb_printf("%s", grp-&gt;gr_name);
+       else
+         bb_printf("%u", grp-&gt;gr_gid);
+}
+
 extern int id_main(int argc, char **argv)
 {
        struct passwd *p;
@@ -61,8 +74,8 @@
        unsigned long flags;
        short status;

-       bb_opt_complementaly = "u~g:g~u";
-       flags = bb_getopt_ulflags(argc, argv, "rnug");
+       bb_opt_complementaly = "u~g:g~u:g~G:G~g:u~G:G~u";
+       flags = bb_getopt_ulflags(argc, argv, "rnugG");

        if ((flags & BB_GETOPT_ERROR)
        /* Don't allow -n -r -nr */
@@ -78,7 +91,7 @@
                uid = getuid();
                gid = getgid();
        }
-
+
        if(argv[optind]) {
                p=getpwnam(argv[optind]);
                /* my_getpwnam is needed because it exits on failure */
@@ -99,6 +112,28 @@
                bb_fflush_stdout_and_exit(EXIT_SUCCESS);
        }

+       /* Support -G and -Gn */
+       if(flags & JUST_GROUP_LIST) {
+               gid_t *groups;
+               long ngroups_max;
+               int i, ngroups;
+               ngroups_max = sysconf(_SC_NGROUPS_MAX);
+               groups = (gid_t*) malloc(ngroups_max * sizeof(gid_t) + 1);
+               ngroups = getgroups(ngroups_max, groups);
+               /* first print the (e)gid */
+               print_group(gid, flags & NAME_NOT_NUMBER);
+               /* now cycle through all other gids, except for egid */
+               for(i = 0; i &lt; ngroups; i++) {
+                       if(groups[i] != gid) {
+                               bb_printf(" ");
+                               print_group(groups[i], flags & NAME_NOT_NUMBER);
+                       }
+               }
+               bb_printf("\n");
+               /* exit */
+               bb_fflush_stdout_and_exit(EXIT_SUCCESS);
+       }
+
        /* Print full info like GNU id */
        /* my_getpwuid doesn't exit on failure here */
        status=printf_full(uid, my_getpwuid(NULL, uid, 0), 'u');
diff -Nur busybox/include/usage.h busybox.new/include/usage.h
--- busybox/include/usage.h     2005-06-20 08:20:13.000000000 +0200
+++ busybox.new/include/usage.h 2005-06-21 07:55:51.482737569 +0200
@@ -1111,7 +1111,8 @@
        "\t-g\tprints only the group ID\n" \
        "\t-u\tprints only the user ID\n" \
        "\t-n\tprint a name instead of a number\n" \
-       "\t-r\tprints the real user ID instead of the effective ID"
+       "\t-r\tprints the real user ID instead of the effective ID\n" \
+       "\t-G\tprint all group IDs\n"
 #define id_example_usage \
        "$ id\n" \
        "uid=1000(andersen) gid=1000(andersen)\n"
diff -Nur busybox/testsuite/id/id-G-works busybox.new/testsuite/id/id-G-works
--- busybox/testsuite/id/id-G-works     1970-01-01 01:00:00.000000000 +0100
+++ busybox.new/testsuite/id/id-G-works 2005-06-21 08:26:49.403257154 +0200
@@ -0,0 +1 @@
+test x$(id -G) = x$(busybox id -G)
diff -Nur busybox/testsuite/id/id-Gn-works busybox.new/testsuite/id/id-Gn-works
--- busybox/testsuite/id/id-Gn-works    1970-01-01 01:00:00.000000000 +0100
+++ busybox.new/testsuite/id/id-Gn-works        2005-06-21 08:26:58.917657846 +0200
@@ -0,0 +1 @@
+test x$(id -Gn) = x$(busybox id -Gn)
</pre>
This patch may also be downloaded <a class="file" href="/projects/busybox/busybox-id-G.diff">here</a>.]]></description>
</item>
<item>
<link>http://www.tuxx-home.at/archives/2005/06/17/T09_07_39/</link>
<title>CGI Post method handling in bash scripts</title>
<dc:date>2005-06-17T09:07:39+01:00</dc:date>
<dc:creator>Alexander Griesser</dc:creator>
<dc:subject>Busybox</dc:subject>
<description><![CDATA[I just wanted to post my way of handling CGI POST method Request Strings
using bash here because I didn't find anything useful in the web straightaway.
The following code reads all Data from stdin (which is POST's way to send you the data) and parses it according to the CGI protocol rules.<br />
The main problem is, that all special charactes such as exclamation marks, white spaces, german umlauts, etc. are being encoded as %xx, where xx is the hexadecimal code of this ascii character. So one has to transform these occurences to their representatives in the ascii-table.<br />
Please keep in mind, that this example is written for use with busybox so I
had to include some tricks that might not be necessary on normal installations (e.g. busybox's sed is not able to display ascii characters with the notation \xnn (where nn is any hexadecimal number)).<br />
<br />
<span class="uln bold">Update 2006-04-21:</span><br />
There was an error in this script that caused it to behave incorrectly if a percent
sign (%25) was found in $POST_STRING. Here's the updated version:<br />

<pre>
if [ "$REQUEST_METHOD" = "POST" ]; then
read POST_STRING

  while true; do
    HEX="$(echo "$POST_STRING" | sed 's/^.*[^%]%\([0-9a-fA-F][0-9a-fA-F]\).*/\1/')"
    if [ "$HEX" = "$POST_STRING" ]; then
      break;
    fi
    REP=$(echo -e \\x$HEX)
    # to avoid mishandling of %25 (== '%') replace all occurences of the
    # percent sign itself with a double percent sign (kind of escaping)
    [ "$REP" = "%" ] && REP="%%"

    POST_STRING="$(echo "$POST_STRING" | sed 's/^\(.*[^%]\)%\([0-9a-fA-F][0-9a-fA-F]\)/\1'$REP'/')"
  done

  # replace all escaped percent signs with a single percent sign
  POST_STRING=$(echo $POST_STRING | sed 's/%%/%/g')

  # replace all ampersands with spaces for easier handling later
  POST_STRING=$(echo $POST_STRING | sed 's/&/ /g')

  do_stuff
fi
</pre>
POST_STRING then contains the decoded Parameter-List which could be fed into
a bash-array (of course, that's also not possible with the busybox builtin,
because there's no declare plugin (not at the moment, at least)).<br />
In my application I did also use the following line afterwards to replace
all ampersands by spaces because I used &quot; for token in $POST_STRING&quot; afterwards (you may also set the IFS environment variable to &quot;&amp;&quot; if you like).<br />
<pre>
  # replace all ampersands with spaces for easier handling later
  POST_STRING=$(echo $POST_STRING | sed 's/&/ /g')
</pre>
If you have any idea of how this could be done better, don't hesitate to
contact me.]]></description>
</item>
<item>
<link>http://www.tuxx-home.at/archives/2005/06/16/T11_36_53/</link>
<title>Why it is really useful to place symlinks to busybox plugins</title>
<dc:date>2005-06-16T11:36:53+01:00</dc:date>
<dc:creator>Alexander Griesser</dc:creator>
<dc:subject>Busybox</dc:subject>
<description><![CDATA[Today I finally figured out why my kill script didn't work. The reason for
this was, that my killall respectively pidof call didn't return a process id
for the given process name.<br />
After thorough investigation of the busybox sourcecode and trying some other
stuff I found out, that pidof/killall doesn't parse /proc/$PID/cmd for the process name instead it cuts out the text between the round braces in /proc/$PID/stat. This text usually contains the name of argv[0] and in case of not having a symlink for e.g. httpd to busybox but calling the plugin directly this text contains &quot;exe&quot; instead of the applet-name itself. pidof and killall will then not be able to find the PID to the given process name (you may try &quot;pidof exe&quot; instead, if you don't believe me). After creating the symlink from httpd to busybox the killall and pidof commands worked fine (although one has to call the httpd-applet by using the full path to the symlink, otherwise this fancy applet-loading mechanism which writes &quot;exe&quot; into the stat entry comes into place).]]></description>
</item>
<item>
<link>http://www.tuxx-home.at/archives/2005/05/31/T10_13_46/</link>
<title>Getting hotplug to work with busybox</title>
<dc:date>2005-05-31T10:13:46+01:00</dc:date>
<dc:creator>Alexander Griesser</dc:creator>
<dc:subject>Busybox</dc:subject>
<description><![CDATA[Today I enabled hotplug support for my thinclient installation.
That was not that tricky, but some of debian's hotplug scripts use
commands or regular expressions that can't be handled when using busybox.
<br />
I had to modify two files, <strong>/etc/hotplug/usb.rc</strong> and <strong>/etc/hotplug/firmware.agent</strong>
(I don't know if these are the only two files to modify, but at the moment
I don't need more functionality from hotplug):
<br />
<pre>
--- usb.rc.orig 2005-05-31 10:11:19.585542257 +0200
+++ usb.rc      2005-05-31 10:13:04.817216587 +0200
@@ -108,7 +108,12 @@
            case "$device" in
                *:*) continue;;
            esac
-           devlink=$(readlink -f $device)
+           # modification for busybox, because busybox's readlink does not
+           # support the -f option
+           # devlink=$(readlink -f $device)
+           devlink=$(readlink $device)
+           devlink=$(echo $devlink | sed 's/^\.\.\/\.\.\/\.\.\//\/sys\//')
+           # end of modification
            DEVPATH=${devlink#/sys}

            ./usb.agent
@@ -116,7 +121,12 @@

        # interface events
        for device in /sys/bus/usb/devices/[0-9]*:*; do
-           devlink=$(readlink -f $device)
+           # modification for busybox, because busybox's readlink does not
+           # support the -f option
+           # devlink=$(readlink -f $device)
+           devlink=$(readlink $device)
+           devlink=$(echo $devlink | sed 's/^\.\.\/\.\.\/\.\.\//\/sys\//')
+           # end of modification
            DEVPATH=${devlink#/sys}

            bDeviceClass=$((0x$(cat $devlink/../bDeviceClass)))

--- firmware.agent.orig 2005-05-31 10:11:27.646215495 +0200
+++ firmware.agent      2005-05-31 10:14:12.707033483 +0200
@@ -23,7 +23,10 @@
 FIRMWARE_DIRS="/lib/firmware /usr/local/lib/firmware /usr/lib/hotplug/firmware"

 # mountpoint of sysfs
-SYSFS=$(sed -n '/^.* \([^ ]*\) sysfs .*$/ { s//\1/p ; q }' /proc/mounts)
+# modification for busybox, because busybox's sed can't handle this regex
+# SYSFS=$(sed -n '/^.* \([^ ]*\) sysfs .*$/ { s//\1/p ; q }' /proc/mounts)
+SYSFS=$(awk "-F " '/^sysfs/ { print $2 } ' /proc/mounts)
+# end of modification

 # use /proc for 2.4 kernels
 if [ "$SYSFS" = "" ]; then
</pre>
<br />
<strong>Update 2005-06-14:</strong> Today I downloaded a daily snapshot of busybox and
was very pleased to see, that the readlink-plugin now supports the -f option, so the patch to usb.rc is obsolete. The problem with firmware.agent persists though.]]></description>
</item>
<item>
<link>http://www.tuxx-home.at/archives/2005/05/13/T13_15_48/</link>
<title>busybox and shell traps</title>
<dc:date>2005-05-13T13:15:48+01:00</dc:date>
<dc:creator>Alexander Griesser</dc:creator>
<dc:subject>Busybox</dc:subject>
<description><![CDATA[Today I stumbled accross an issue with busybox and shell traps.
I tried to add some kind of automatic error responses to my thinclient
runlevel scripts using signal traps. I configured a trap to signal 0 to
start a dialog interface containing the detaild error message, but because
of the trap on signal 0, it's always executed - on success and on failure - 
when the scripts exits. So I had to define some a variable that contains one
specified value on success and another value on failure. Due to the forementioned fact that busybox lets me just do a single command in the trap, I wasn't
able to check for the value of this variable, e.g. the following code didn't
work:<br />
<pre>
[ "$VARIABLE" = "0" ] && do_something
</pre>
Busybox only evalutes $VARIABLE and then returns from my trap, do_something
was never called.<br />
Finally I came to this solution:<br />
<pre>
ignore()
{
}

errordlg()
{
  $SCRIPT_OK /usr/bin/dialog --title "LXTC" --clear --msgbox "$*" 8 51
}

# Enable Error Reporting
set -e
SCRIPT_OK=

trap 'errordlg Error while loading keyboard layout!' 0

echo -n "Loading keyboard layout $KEYLAYOUT..."
try /bin/loadkeys $KEYLAYOUT

SCRIPT_OK=ignore
</pre>
That worked fine and should be self-explanatory.]]></description>
</item>
<item>
<link>http://www.tuxx-home.at/archives/2005/04/19/T11_10_35/</link>
<title>Small replacement script for the shell-builtin &quot;command&quot;</title>
<dc:date>2005-04-19T11:10:35+01:00</dc:date>
<dc:creator>Alexander Griesser</dc:creator>
<dc:subject>Busybox</dc:subject>
<description><![CDATA[While trying to get my thinclient installation to work, I recognized that
Debian's &quot;startx&quot; command uses the shell builtin &quot;command&quot;
to check where the binary &quot;deallocvt&quot; is located.<br />
This shell builtin is not available when using busybox v0.60. Of course I could
simply replace the command-call in startx with a call to &quot;which&quot;, but
that would break my thinclient-creation script, so I wrote a simple command
replacement as shell script:<br />
<pre>
#!/bin/sh
#
# This script tries to replace the BASH-builtin "command" (according to
# the information I got from "man command".
#
# Some scripts (e.g. startx) rely on this builtin command
#
# by Alexander Griesser <work@tuxx-home.at>
# 2005-04-19

if [ $# -lt 1 ]; then
  exit 0
fi

case $1 in
    "-v")
        which $2
        ;;
    "-V")
        if which $2 >/dev/null 2>&1; then
          echo $2 is $(which $2)
        else
          echo "command: $2: not found"
          exit 1
        fi
        ;;
    "-p")
        shift
        $*
        ;;
    *)
      $*
      ;;
esac
</pre>
Name this script &quot;command&quot; (without the .sh extension) and place
it anywhere in your $PATH (I put it to /bin).<br />
<strong>Update:</strong> As with version 1.0pre the command-builtin appeared in busybox, yeah!]]></description>
</item>
</channel>
</rss>
