[GTALUG] Processing a binary file with a shell script

Ansar Mohammed ansarm at gmail.com
Tue Aug 11 02:42:40 UTC 2015


Here is the complete background.

I need to write a tool to run on Linux that will do an LDAP lookup on
Active Directory for a specific 'hidden' attribute that tells the client
which Active Directory site it belongs to. The tool is part of a larger
suite (keytab creation, krb5.conf config etc) already written in Bourne.
Unfortunately, the value that is returned from AD is a binary blob. So
while I can call ldapsearch to retrieve the value, I still need something
to process/decompress the attribute.

The algorithm to decompress the blob is the same as is outlined in RFC
1035. But Windows implementations of such are sparsely documented.

I needed to ensure that I understood the decompression algorithm so I wrote
some fairly portable code to do both the LDAP lookup and  perform the
decompression of the binary blob.

So while I can port the code from Windows to Linux fairly easily, I would
like the tool to be converted to Bourne so that it can be a single script
(rather than having to deploy a script and an executable).


On Mon, Aug 10, 2015 at 11:18 AM, Mauro Souza <thoriumbr at gmail.com> wrote:

> If you have the program in C to process data, going to bash is like
> swapping a large truck for a turtle. Bash will be orders of magnitude
> slower, and you will have to take a lot of care to pipe data all over awk,
> sed, tr and the like.
> Bash is a terrible choice, python (or perl, or PHP) would be faster. Way
> faster.
>
> Mauro
> http://mauro.limeiratem.com - registered Linux User: 294521
> Scripture is both history, and a love letter from God.
>
> 2015-08-10 11:42 GMT-03:00 Brent Kimberley <Brent.Kimberley at durham.ca>:
>
>> How about ihex or srec?
>>
>>
>>   Original Message
>> From: Giles Orr
>> Sent: Monday, August 10, 2015 10:32
>> To: GTALUG Talk
>> Reply To: GTALUG Talk
>> Subject: Re: [GTALUG] Processing a binary file with a shell script
>>
>>
>> On 10 August 2015 at 04:12, Ansar Mohammed <ansarm at gmail.com> wrote:
>> > Hello All,
>> > I am writing a bourne shell script, to read a binary file as input and
>> take
>> > action depending on the contents of the file.
>> >
>> > The file is a mixture of ASCII and binary codes (such as ASCII filed
>> lengths
>> > and flags).
>> >
>> > I have the processing already done in C. I would like to convert it to a
>> > bourne shell.
>> >
>> > Does anyone have any suggestions on what combination of tools I may be
>> able
>> > to use?
>>
>> If you're only trying to look at the ASCII data (and trying to process
>> binary data in Bash seems like a poor idea), then you may want to look
>> at the "strings" command:
>>
>> $ strings $(which ls)
>>
>> "strings" is part of the binutils package on Debian.
>>
>> --
>> Giles
>> http://www.gilesorr.com/
>> gilesorr at gmail.com
>> ---
>> Talk Mailing List
>> talk at gtalug.org
>> http://gtalug.org/mailman/listinfo/talk
>> THIS MESSAGE IS FOR THE USE OF THE INTENDED RECIPIENT(S) ONLY AND MAY
>> CONTAIN INFORMATION THAT IS PRIVILEGED, PROPRIETARY, CONFIDENTIAL, AND/OR
>> EXEMPT FROM DISCLOSURE UNDER ANY RELEVANT PRIVACY LEGISLATION. No rights to
>> any privilege have been waived. If you are not the intended recipient, you
>> are hereby notified that any review, retransmission, dissemination,
>> distribution, copying, conversion to hard copy, taking of action in
>> reliance on or other use of this communication is strictly prohibited. If
>> you are not the intended recipient and have received this message in error,
>> please notify me by return e-mail and delete or destroy all copies of this
>> message.
>> ---
>> Talk Mailing List
>> talk at gtalug.org
>> http://gtalug.org/mailman/listinfo/talk
>>
>
>
> ---
> Talk Mailing List
> talk at gtalug.org
> http://gtalug.org/mailman/listinfo/talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/talk/attachments/20150810/adb6840f/attachment.html>


More information about the talk mailing list