Tuesday, November 18, 2014

The datepart second is not supported by date function dateadd for data type date.

In Epicor 10, I was trying to create some SQL to combine the values from the SysDate and SysTime fields of table 'erp.PartTran'. Field 'Sysdate' is of type 'date'. Field 'SysTime' is of type 'int' and is the number of Seconds in to the day, and so will have a maximum values of 86400. So I tried the function:
DATEADD(SECOND,SysTime,SysDate)

But I got the error:
Msg 9810, Level 16, State 1, Line 4
The datepart second is not supported by date function dateadd for data type date.

The fix is to cast the field 'SysDate' to type 'datetime', like this:
DATEADD(SECOND,SysTime,Convert(DateTime,SysDate))

Here is my complete SQL:
SELECT DATEADD(SECOND,SysTime,Convert(DateTime,SysDate)) SystemDate,
TranNum, PartNum, WareHouseCode, BinNum, TranClass, TranType, InventoryTrans, TranQty, UM,MtlUnitCost, ExtCost, CostMethod,
EntryPerson, TranReference, InvAdjSrc, InvAdjReason, LotNum, GLTrans, PostedToGL, MtlMtlUnitCost, EmpID, CostID, ActTranQty, ActTransUOM, BaseCostMethod
FROM erp.PartTran
WHERE Company='ABC' AND PartNum='XYZ'
ORDER BY TranNum;

Reference: What about a new DATEADD function?

Wednesday, November 27, 2013

Microsoft Access - Error 3088 "Too many expressions in ORDER BY clause"

In Access 2010, the maximum number (limit) of fields specified in the 'Order By' clause, seems to be 128. Should be enough for most cases!

Wednesday, October 24, 2012

Using tshark to troubleshoot http

Here I give an example of how to use tshark, which is a command line tool and a part of the wireshark package, to monitor http requests and responses.

On Windows, first identify the numbering of the NIC adapters, using the '-D' option:

C:\Program Files\Wireshark>tshark.exe -D
1. \Device\NPF_GenericDialupAdapter (Adapter for generic dialup and VPN capture)
2. \Device\NPF_{2F15B435-C783-4863-90AC-C9DF8B64FBE1} (VMware Accelerated AMD PCNet Adapter)

Ok, lets now look at http traffic when loading the twitter home page:
C:\Program Files\Wireshark>tshark -i 2 "tcp port 80" -R "http.request or http.response"
Capturing on VMware Accelerated AMD PCNet Adapter
0.005726 192.168.2.14 -> 199.59.150.39 HTTP 867 GET / HTTP/1.1
3.067846 192.168.2.14 -> 199.59.150.39 HTTP 867 [TCP Retransmission] GET / HTTP/1.1
4.577303 192.168.2.14 -> 184.169.78.33 HTTP 425 GET /a/1350941601/t1/css/t1_core_logged_out.bundle.css HTTP/1.1
4.578931 192.168.2.14 -> 184.169.78.33 HTTP 414 GET /a/1350941601/t1/css/t1_more.bundle.css HTTP/1.1
4.605371 199.59.150.39 -> 192.168.2.14 HTTP 279 HTTP/1.0 200 OK (text/html)
4.612847 184.169.78.33 -> 192.168.2.14 HTTP 615 HTTP/1.0 200 OK (text/html)
4.620900 184.169.78.33 -> 192.168.2.14 HTTP 593 HTTP/1.0 200 OK (text/html)
4.631572 192.168.2.14 -> 184.169.78.33 HTTP 414 GET /a/1350941601/images/bigger_spinner.gif HTTP/1.1
4.631683 192.168.2.14 -> 184.169.78.33 HTTP 426 GET /a/1350941601/t1/img/front_page/city-balcony@2x.jpg HTTP/1.1
4.634542 192.168.2.14 -> 184.169.78.33 HTTP 432 GET /c/swift/init.ef644480fe2a53578f7ce4eda13396e86b6fa74a.js HTTP/1.1
4.679344 184.169.78.33 -> 192.168.2.14 HTTP 60 HTTP/1.0 200 OK (GIF89a)
4.679459 184.169.78.33 -> 192.168.2.14 HTTP 60 HTTP/1.0 200 OK (GIF89a)
4.683034 184.169.78.33 -> 192.168.2.14 HTTP 629 HTTP/1.0 200 OK (text/html)
4.702673 192.168.2.14 -> 199.59.150.39 HTTP 529 GET /opensearch.xml HTTP/1.1
4.705784 199.59.150.39 -> 192.168.2.14 HTTP 417 HTTP/1.0 304 Not Modified
15 packets captured

You can see above, that this clearly shows the URLs to the html, image and css files that are downloaded from the server, and the associated http response codes.

Note the use of the tshark '-R' option to specify a "display" filter, to filter out everything, but the http requests and responses, so that we can concentrate on whats happening at the http level, without things like the tcp acks causing distraction. And you may want to expand the capture filter to just specify a particular host.

Customizing grub2 boot options in Fedora 18

In days of old, with RedHat Linux, and Fedora and Centos, on servers I used to disable the default behaviour of console display blanking screen-saver by putting the 'setterm -blank 0' command into file '/etc/rc.local'. On recent versions of Fedora, you do not get a '/etc/rc.local' file, however you can create one like this:
# vi /etc/rc.d/rc.local
# chmod a+x /etc/rc.d/rc.local
# ln -s /etc/rc.d/rc.local /etc
# ll /etc/rc.local
lrwxrwxrwx. 1 root root 18 Sep 24 15:44 /etc/rc.local -> /etc/rc.d/rc.local
#

But this no longer seem to be an appropriate way to run  'setterm -blank 0', as the command just seems to be ignored. I tried setting my '/etc/rc.local' file to this:
# cat /etc/rc.local
#!/bin/sh
/bin/date > /root/rc.local.start
/bin/sleep 5
/bin/setterm -blank 0
/bin/date > /root/rc.local.done

..just to prove the command was executing, and it was, but still the screen blanked after the timeout.

After much Googling, I found the answer was to use a kernel command line option of 'consoleblank=0'.

Now again in days of old, I would just edit '/etc/grub.conf' to set these kernel parameters, But now recent versions of Fedora are using Grub2, things have changed. I found that you can specify the kernel parameters, in file '/etc/default/grub', using the 'GRUB_CMDLINE_LINUX_DEFAULT' option.

And while I was editing the grub file, I decided to change some other settings. I wanted to disable the graphical boot splash screen, and just have a basic 'text' screen to select which kernel to boot, so I added 'GRUB_TERMINAL=console'. I also removed the 'rhgb quiet' options, as I like to see all those boot messages scrolling up the screen.

# cd /etc/default/
# cp grub grub.orig
# vi grub
# diff -u grub.orig grub
--- grub.orig   2012-10-24 10:28:28.120869824 +0100
+++ grub        2012-10-24 10:52:40.940184853 +0100
@@ -1,6 +1,8 @@
-GRUB_TIMEOUT=5
+GRUB_TIMEOUT=10
 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
 GRUB_DEFAULT=saved
-GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 rd.luks=0 $([ -x /usr/sbin/rhcrashkernel-param ] && /usr/sbin/rhcrashkernel-param || :) rhgb quiet"
+GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 rd.luks=0 $([ -x /usr/sbin/rhcrashkernel-param ] && /usr/sbin/rhcrashkernel-param || :)"
+GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0"
 GRUB_DISABLE_RECOVERY="true"
 GRUB_THEME="/boot/grub2/themes/system/theme.txt"
+GRUB_TERMINAL=console
#
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.6.2-2.fc18.x86_64
Found initrd image: /boot/initramfs-3.6.2-2.fc18.x86_64.img
Found linux image: /boot/vmlinuz-3.6.0-1.fc18.x86_64
Found initrd image: /boot/initramfs-3.6.0-1.fc18.x86_64.img
#

Ok, so lets check that worked....
# grep $'\tlinux' /boot/grub2/grub.cfg
linux   /vmlinuz-3.6.2-2.fc18.x86_64 root=UUID=9d81334c-ed70-4cc8-9279-e82eb8cdef1e ro rd.md=0 rd.lvm=0 rd.dm=0 rd.luks=0  consoleblank=0
linux   /vmlinuz-3.6.0-1.fc18.x86_64 root=UUID=9d81334c-ed70-4cc8-9279-e82eb8cdef1e ro rd.md=0 rd.lvm=0 rd.dm=0 rd.luks=0  consoleblank=0

In the above, note how I get grep to match for the tab character.

References:
http://lists.fedoraproject.org/pipermail/users/2012-March/415317.html
http://superuser.com/questions/152347/change-linux-console-screen-blanking-behavior
http://thangnguyennang.wordpress.com/2012/06/17/change-the-grub-menu-timeout-on-fedora-17-20-2/
http://ubuntuforums.org/showthread.php?t=1456104
http://www.dedoimedo.com/computers/grub-2.htm
http://fedoraproject.org/wiki/GRUB_2
http://www.redhat.com/archives/rhl-list/2004-May/msg07775.html
http://savannah.gnu.org/bugs/?23535
http://www.howtoarena.com/how-to-disable-linux-console-screen-blank-out-feature/

Thursday, July 12, 2012

Centos vlan configuration

On our Centos boxes, we start with a minimal installation, and then add additional rpm packages as required. Today, we wanted to add a vlan trunk interface on an existing box. We created the config file as follows:
# cat /etc/sysconfig/network-scripts/ifcfg-eth5.800
# Intel Corporation 82546GB Gigabit Ethernet Controller (Copper)
DEVICE=eth5.800
BOOTPROTO=static
HWADDR=00:1B:21:52:09:0F
ONBOOT=yes
IPADDR=192.168.51.193
NETMASK=255.255.255.192
VLAN=yes
#

But when we tried to bring up the vlan interface, we got this error:
# ifup eth5.800
Device eth5.800 does not seem to be present, delaying initialization.
#

This was caused because the 'vconfig' program was missing, and so we had to install that package:
# which vconfig
/usr/bin/which: no vconfig in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
# yum install vconfig
# which vconfig
/sbin/vconfig
#

Then everything worked as expected:
# ifup eth5.800
Added VLAN with VID == 800 to IF -:eth5:-
# ls -l /proc/net/vlan
-rw------- 1 root root 0 Jul 12 10:35 config
-rw------- 1 root root 0 Jul 12 10:35 eth5.800
# lsmod | grep 8021q
8021q 57425 0
#

BTW, the above commands were run on the following version of Centos:
# cat /etc/redhat-release
CentOS release 5.8 (Final)
#

Thursday, July 05, 2012

AES Encryption & Decryption from the command line with OpenSSL

Today, I wanted to gain a deeper understanding of AES encryption. I have succesfully used AES encryption with ipsec vpn's. But here I want to examine what are the inputs and outputs from the AES algorithm, and do some sanity checks with test data using openssl from the command-line.

On the wikipedia page for AES, they mention, "..Test vectors are a set of known ciphers for a given input and key. NIST distributes the reference of AES test vectors as AES Known Answer Test (KAT) Vectors (in ZIP format)."

That sounds like what I need as a reference, so I downloaded:

http://csrc.nist.gov/groups/STM/cavp/documents/aes/KAT_AES.zip

...and selected (guessed?) file "CBCVarKey128.rsp" as suitable, because I wanted to use a 128 bit key length,

Here is one example (from 128 possible examples) from that file:
KEY = 80000000000000000000000000000000
IV = 00000000000000000000000000000000
PLAINTEXT = 00000000000000000000000000000000
CIPHERTEXT = 0edd33d3c621e546455bd8ba1418bec8

Ok, first let's sanity check we can generate the required PLAINTEXT. I'm using xxd to do this, as I explained in an earlier blog post.

# echo -n '00000000000000000000000000000000' | xxd -p -r | hexdump -C
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010

So the above looks good. We are generating the 16 bytes of test data, from a 32 character hexadecimal string.

Openssl allow you to specify the Key and the 'Initialization Vector' on the command like, as hexadecimal strings, using the '-K' and '-iv' parameters. Be careful, thats an uppercase K for the key. As another sanity check, it is useful to use the '-P' option, again uppercase, to get openssl to report back what it thinks are the values of the Key and IV. So lets try this:

# echo -n '00000000000000000000000000000000' | xxd -p -r | openssl enc -aes-128-cbc -P -nosalt -K '80000000000000000000000000000000' -iv '00000000000000000000000000000000'
key=80000000000000000000000000000000
iv =00000000000000000000000000000000

Ok, thats good. They Key and IV values are what we were expecting.
By the way, for this sort of validation check, we don't want to use a salt, hence the use of the '-nosalt' option.
Right, lets remove the '-P' and see what data comes out:
# echo -n '00000000000000000000000000000000' | xxd -p -r | openssl enc -aes-128-cbc -nosalt -K '80000000000000000000000000000000' -iv '00000000000000000000000000000000' | hexdump -C
00000000 0e dd 33 d3 c6 21 e5 46 45 5b d8 ba 14 18 be c8 |.Ý3ÓÆ!åFE[غ..¾È|
00000010 fe 3d e6 e1 86 98 08 4f 63 de e5 04 42 ff 94 d2 |þ=æá...OcÞå.Bÿ.Ò|
00000020

Oh, that strange!
I'm trying to encrypt 16-bytes, but the output is 32 bytes long!
But the first 16 bytes of output looks correct!

The answer to this is padding. If you specify the '-nopad' option, then you get the expected 16 bytes of output:

echo -n '00000000000000000000000000000000' | xxd -p -r | openssl enc -aes-128-cbc -nopad -nosalt -K '80000000000000000000000000000000' -iv '00000000000000000000000000000000' | xxd -p
0edd33d3c621e546455bd8ba1418bec8

Good. Thats the CIPHERTEXT output we were expecting!

If you check 'man enc' you see that the '-nopad' option, disables standard block padding. And the man page also notes "All the block ciphers normally use PKCS#5 padding also known as standard block padding".

By the way, in the above tests, the IV is all-zeroes, so we can abbreviate the command like this:

echo -n '00000000000000000000000000000000' | xxd -p -r | openssl enc -aes-128-cbc -nopad -nosalt -K 80000000000000000000000000000000 -iv 0 | xxd -p
0edd33d3c621e546455bd8ba1418bec8

To finish off, lets try some decryption, reversing what we did above:
# echo -n '0edd33d3c621e546455bd8ba1418bec8' | xxd -p -r | openssl enc -aes-128-cbc -d -nosalt -K 80000000000000000000000000000000 -iv 0 -nopad | xxd -p
00000000000000000000000000000000

Ok, that looks good. I think I am begining to get the hang of this!

Using openssl to generate HMAC using a binary key

If you want to do a quick command-line generation of a HMAC, then the openssl command is useful.
For example:
# echo -n 'value' | openssl dgst -sha1 -hmac 'key'
(stdin)= 57443a4c052350a44638835d64fd66822f813319

# echo -n 'value' | openssl dgst -md5 -hmac 'key'
(stdin)= 01433efd5f16327ea4b31144572c67f6

...or alternatively...
# echo -n 'value' | openssl sha1 -hmac 'key'
(stdin)= 57443a4c052350a44638835d64fd66822f813319

# echo -n 'value' | openssl md5 -hmac 'key'
(stdin)= 01433efd5f16327ea4b31144572c67f6

Reference:
http://stackoverflow.com/questions/7285059/hmac-sha1-in-bash

BUT, note in the above commands, the 'value' and 'key' are ascii strings. The above syntax is problematic if you want to specify a Binary value for the key, which does not correspond to printable characters.

This had been a problem reported in the past:
http://www.mail-archive.com/openssl-users@openssl.org/msg49098.html
http://www.mail-archive.com/openssl-users@openssl.org/msg49100.html

But I can report here, that certainly with openssl v1.0.0, the following method allows you to specify a binary key, by passing it as a string of hex values.

To demonstate the point, let's get the hex string equivalent of the three character acsii string 'key', so that we can use the same hashes as in the examples above. To do this, I use utility 'xxd' which does a hexdump. (For further information on 'xdd' see my previous blog posts.)

# echo -n 'key' | xxd -p
6b6579

Ok, so the hex-string "6b6579" corresponds to ascii string "key".

So after reading up the man page for 'openssl dgst', we try a further alternate form of the command, like this:

# echo -n 'value' | openssl dgst -sha1 -mac HMAC -macopt key:key
(stdin)= 57443a4c052350a44638835d64fd66822f813319

# echo -n 'value' | openssl dgst -sha1 -mac HMAC -macopt hexkey:6b6579
(stdin)= 57443a4c052350a44638835d64fd66822f813319

# echo -n 'value' | openssl dgst -md5 -mac HMAC -macopt key:key
(stdin)= 01433efd5f16327ea4b31144572c67f6

# echo -n 'value' | openssl dgst -md5 -mac HMAC -macopt hexkey:6B6579
(stdin)= 01433efd5f16327ea4b31144572c67f6

Note the use of the '-macopt hexkey:string' option which allows you to specify the key in hexadecimal (two hex digits per byte).

Nice! So now we can do something like this:

# echo -n '55f80d132e8b68eb' | xxd -r -p | openssl dgst -sha1 -mac HMAC -macopt key:645a487340f4c7f0
(stdin)= 2f0928b4bb365b4a590d84960a7cd04fd2d80221

I hope to show a practical use of the above in a future blog post!

Finally, I will just confirm some details of the system that gave the above output:

# rpm -qa | grep openssl
openssl-1.0.0-20.el6_2.5.x86_64

# cat /etc/redhat-release
CentOS release 6.2 (Final)

By the way, if your wondering about the '(stdin)= ' that openssl is outputing, then see my previous blog post on this subject.

Convert a Hex dump to Binary data with xxd

In my last blog post, I demonstarted how to dump a binary file, using either 'hexdump' or 'xxd'.
In summary, we can do this:
# ls -l hash-file.bin
-rw-r--r-- 1 root root 20 Jul 4 10:05 hash-file.bin
# xxd -p hash-file.bin
57443a4c052350a44638835d64fd66822f813319

Ok, what if we want to do the reverse of this.
That is to take a string of hex characters and create a binary file!
The utility 'xxd' can also do this.

To demonstrate, lets first save the hex representation into a separate file:

# xxd -p hash-file.bin > hash-file.hex
# ls -l hash-file.hex
-rw-r--r-- 1 root root 41 Jul 4 12:04 hash-file.hex
# cat hash-file.hex
57443a4c052350a44638835d64fd66822f813319

Ok, here's the clever part. Note we now pass the '-r' option to xdd to 'reverse' it's operation.
# xxd -p -r hash-file.hex > new-file.bin
# ls -l new-file.bin
-rw-r--r-- 1 root root 20 Jul 4 12:19 new-file.bin
# xxd -p new-file.bin
57443a4c052350a44638835d64fd66822f813319
# cmp hash-file.bin new-file.bin
#

So we recreated the binary file, as 'new-file.bin' from the hex dump and we proved it is identical to the file we started with.

You can also feed into xdd from the pipeline, like this:

# cat hash-file.hex | xxd -p -r > new-file.bin
# xxd -p new-file.bin
57443a4c052350a44638835d64fd66822f813319

..and here are some more examples:
# echo -n 'password' | xxd -p | xxd -p -r | hexdump -C
00000000  70 61 73 73 77 6f 72 64                           |password|
00000008

# echo -n 'c0a06003' | xxd -p -r | hexdump -C
00000000  c0 a0 60 03                                       |..`.|
00000004

hexdump and xxd output compared

Here I'm working with a Centos Linux system, and I've found two seperate utility programs that can produced a hex dump. One is called hexdump and the other is xxd, and they are provided as part of two seperate packages.
# which hexdump
/usr/bin/hexdump
# rpm -qf /usr/bin/hexdump
util-linux-2.13-0.59.el5

# which xxd
/usr/bin/xxd
# rpm -qf /usr/bin/xxd
vim-common-7.0.109-7.el5

Ok, so lets compare the output format of the hex dump with these utilities. But first we need some test data, which I'm going to generate with 'openssl'. Conveniently, openssl can output the data in either hex (the default) or binary.

# echo -n 'value' | openssl dgst -sha1 -hmac "key"
57443a4c052350a44638835d64fd66822f813319
# echo -n 'value' | openssl dgst -sha1 -hmac "key" -binary > hash-file.bin
# ls -l hash-file.bin
-rw-r--r-- 1 root root 20 Jul 4 10:05 hash-file.bin

So we have our test data in a file called 'hash-file.bin'. It's 20 bytes long as it contains a 160 bit sha1 hash. Ok, let's try dumping that file and see what we get:
# hexdump hash-file.bin
0000000 4457 4c3a 2305 a450 3846 5d83 fd64 8266
0000010 812f 1933
0000014

# xxd hash-file.bin
0000000: 5744 3a4c 0523 50a4 4638 835d 64fd 6682  WD:L.#P.F8.]d.f.
0000010: 2f81 3319                                /.3.

Um, interesting!
Note the default output is grouping the bytes into 16-bit values and there is a difference in how to interpret the endianness.

Let's try customizing the output with some options:

# hexdump -C hash-file.bin
00000000  57 44 3a 4c 05 23 50 a4  46 38 83 5d 64 fd 66 82  |WD:L.#P.F8.]d.f.|
00000010  2f 81 33 19                                       |/.3.|
00000014

# xxd -g 1 hash-file.bin
0000000: 57 44 3a 4c 05 23 50 a4 46 38 83 5d 64 fd 66 82  WD:L.#P.F8.]d.f.
0000010: 2f 81 33 19                                      /.3.

# xxd -p hash-file.bin
57443a4c052350a44638835d64fd66822f813319

So this is 'better' for seeing the byte sequence.

Openssl and the "(stndin)= " prefix

Recently, I've been playing around with the openssl utility. Doing things like this:
# echo -n 'value' | openssl dgst -sha1 -hmac 'key'
57443a4c052350a44638835d64fd66822f813319

# rpm -qa | grep openssl
openssl-0.9.8e-22.el5_8.3

# cat /etc/redhat-release
CentOS release 5.8 (Final)

Note that I show the version and operating system I'm using. Here's why. Look at the following:
# echo -n 'value' | openssl dgst -sha1 -hmac 'key'
(stdin)= 57443a4c052350a44638835d64fd66822f813319

# rpm -qa | grep openssl
openssl-1.0.0-20.el6_2.5.x86_64

# cat /etc/redhat-release
CentOS release 6.2 (Final)

So on a more recent system, openssl has prefixed it's output with "(stndin)= ".
I'm not finding this particularly helpful for my application.
One workaround, suggested here, is to use sed to remove it, like this:
# echo -n 'value' | openssl dgst -sha1 -hmac 'key' | sed 's/^.*= //'
57443a4c052350a44638835d64fd66822f813319

Wednesday, May 16, 2012

Comparing RPM packages installed on two hosts, without using temporary files

When setting up a new Linux server, it's often interesting to compare the list of packages that are installed on the new server, with the list of packages installed on an existing server. You can use the following command line, which makes use of Bash supports for process substitution, to show the difference between packages installed on the local host and on the remote host.
 # ssh root@remotehost 'rpm -qa | sort' | diff -u <(rpm -qa | sort) -


If the above command gives no output, it means that the two hosts have identical packages installed.

If you want to disregard the package version differences in the comparison, then you will need to use something like this:

 # ssh root@remotehost 'rpm -qa --queryformat "%{NAME}\n" | sort' | diff -u <(rpm -qa --queryformat "%{NAME}\n" | sort) -

Update(2013-07-02):
Following Paul Waterman's comment, I did try out his rpmscomp Perl script, and I did find it useful. So I would recommend you also give it a try:

https://github.com/pdwaterman/rpmscomp

Also, to help in removing packages, I have found the rpmreader package useful:

https://fedorahosted.org/rpmreaper/

Friday, May 11, 2012

Moving old Nokia ringtones to the Apple iPhone

For the last seven years, I have used the 'bach' ringtone on my old Nokia 6230i. Now I have an iPhone 4s, I wanted the option of using the same ring tone. What follows is the procedure I used. I did this all on a Windows PC, but I believe you can also use 'faac' on Linux. Note that this procedure is 'free'.

I download the Nokia 6230i ringtone "Bach.aac" from here:

http://meramob.com/filedownload/2011/41824/Bach.html

I used this online service...

http://media.io/

... to convert the "Bach.aac" to "Bach.wav".

I then downloaded "FAACv1.28 Binary for Win32" as file "faac-1.28-mod.zip" from this site:

http://www.rarewares.org/aac-encoders.php

..and unziped the archive to extract binary executable "faac.exe".

Here is the 'help' for faac:

C:\Temp>faac.exe --help
Freeware Advanced Audio Coder
FAAC 1.28

Usage: faac.exe [options] infiles ...
Options:
-q Set quantizer quality.
-b Set average bitrate to x kbps. (ABR, lower quality mode)
-c Set the bandwidth in Hz. (default=automatic)
-o X Set output file to X (only for one input file)
-r Use RAW AAC output file.
-P Raw PCM input mode (default 44100Hz 16bit stereo).
-R Raw PCM input rate.
-B Raw PCM input sample size (8, 16 (default), 24 or 32bits).
-C Raw PCM input channels.
-X Raw PCM swap input bytes
-I Input channel config, default is 3,4 (Center third, LF fourth)

MP4 specific options:
-w Wrap AAC data in MP4 container. (default for *.mp4 and *.m4a)
-s Optimize MP4 container layout after encoding
--artist X Set artist to X
--writer X Set writer to X
--title X Set title to X
--genre X Set genre to X
--album X Set album to X
--compilation Set compilation
--track X Set track to X (number/total)
--disc X Set disc to X (number/total)
--year X Set year to X
--cover-art X Read cover art from file X
--comment X Set comment to X

Documentation:
--license Show the FAAC license.
--help Show this abbreviated help.
--long-help Show complete help.

More tips can be found in the audiocoding.com Knowledge Base at
http://www.audiocoding.com/wiki/

I then used this command line to convert the WAV file to a M4A file:

C:\Temp>faac.exe -b 128 -c 44100 -w Bach.wav
Freeware Advanced Audio Coder
FAAC 1.28

Average bitrate: 128 kbps
Quantization quality: 100
Bandwidth: 16000 Hz
Object type: Low Complexity(MPEG-4) + M/S
Container format: MPEG-4 File Format (MP4)
Encoding Bach.wav to Bach.m4a
frame | bitrate | elapsed/estim | play/CPU | ETA
403/403 (100%)| 74.8 | 0.4/0.4 | 29.51x | 0.0

Note that I used the "-w" option so that the AAC data stream was 'wrapped' in a MP4 container.

I then renamed "Bach.m4a" to "Bach.m4r".
(Note the M4R extension is used to identify the file as a ringtone.)

And I then dragged and dropped the "Bach.m4r" file into the iTunes library.
(If iTunes fails to accept the dropped file, it means that file is not in the correct format.)

Then I synced the ringtone to the iPhone.

The following pages provided inspiration for the above:

Wednesday, November 30, 2011

Query your Switch using SNMP and Linux

So you want to query a switch using snmp to see which MACs are being seen on which ports. In that case you will need the BRIDGE-MIB. On Centos-5 it is supplied, but as part of the 'libsmi' package.

# rpm -qa | egrep 'libsmi|net-snmp' | sort
libsmi-0.4.5-2.el5
net-snmp-5.3.2.2-14.el5_7.1
net-snmp-libs-5.3.2.2-14.el5_7.1
net-snmp-utils-5.3.2.2-14.el5_7.1

So you need to create file '/etc/snmp/snmp.conf' and configure as follows:

# cat /etc/snmp/snmp.conf
mibdirs +/usr/share/mibs/ietf

Then you should have success with the following command.
Remember to use the correct community string - by default its usually 'public'.
And the mib object name IS case sensitive.

# snmptable -v1 -c public -Cbw 80 192.168.24.1 -IR BRIDGE-MIB::dot1dTpFdbTable
SNMP table: BRIDGE-MIB::dot1dTpFdbTable

Address Port Status
0:c:29:45:21:9e 24 learned
0:c:29:79:6c:73 24 learned
0:12:3f:c3:9d:7b 19 learned
0:14:38:a2:70:7e 15 learned
0:14:5e:68:74:ed 17 learned
0:1b:78:22:bc:30 21 learned
0:26:55:e7:5b:f4 27 learned
0:50:56:a7:61:32 22 learned
64:31:50:cd:c7:0 0 self
9c:8e:99:19:99:a6 23 learned
9c:8e:99:c4:46:56 13 learned
c8:4c:75:90:f:e0 28 learned

Status 'self' or 'mgmt' is the MAC of the switch itself - used for the management connection.


If you have a modular switch, you may want to check the logical to physical port name mapping, as show next. If you just have a simple switch, the port names are usually boring!


# snmpwalk -v1 -c public 192.168.24.1 -IR IF-MIB::ifName | head -n 5
IF-MIB::ifName.1 = STRING: 1
IF-MIB::ifName.2 = STRING: 2
IF-MIB::ifName.3 = STRING: 3
IF-MIB::ifName.4 = STRING: 4
IF-MIB::ifName.5 = STRING: 5

Before you run the above commands, it may be useful to ping every host on your subnet, just so that the switch has seen everything. You can use 'nmap' for that:

# nmap -n -sP 192.168.24.0/24

Good luck with the above. I've often found these command very useful!

Friday, August 05, 2011

bash initialisation files

I've been installing Centos 5 into VirtualBox this evening. Due to some mistyping, I ended up in the situation where I needed to manually create the 'home' directory for the user 'nwsmith'. Ok, thats simple, just remember to set the correct user and group, and the correct permissions:

# mkdir /home/nwsmith
# chown nwsmith.nwsmith /home/nwsmith
# chmod 700 /home/nwsmith

But when I logged in as user 'nwsmith' I was not getting the correct bash prompt. It looked like PS1 was not being set correctly. I quickly realised that I was missing the '.bashrc' file from my home directory, so I copied that across from '/etc/skel/.bashrc'.

But still I was not getting the correct prompt. But I found that if I ran the command 'source ./.bashrc' then I did get the correct prompt. Finally the penny dropped, when I googled up this link Initialisation files and configuration from the University of Cambridge Computer Laboratory. I'm just going to quote the paragraph I found really useful:

When bash is invoked as a login shell it first reads and executes commands from the file /etc/profile, if that file exists. This initialises a few environment variables, and calls a set of small initialisation scripts from the directory /etc/profile.d, which will vary depending on the software loaded on the machine (for example, if KDE is loaded there will be one called kde.sh).

After reading that file, it looks for ~/.bash_profile or ~/.bash_login or ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. (The --noprofile option could be used when the shell is started to inhibit this behaviour.)

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. (This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc).

Thus, by default, the file ~/.bashrc is not read automatically when a login shell is started. For this reason it is usual behaviour to add a section to ~/.profile (or ~/.bash_profile or ~/.bash_login) to read and execute it, so that you get uniform behaviour on both login shells and normal interactive shells.

After reading that I realised that I also need a '.bash_profile' file in my home directory, so I copied one across from '/etc/skel/.bash_profile'. And then when I logged in as user 'nwsmith' I got the prompt I was expecting.

By the way, '.bash_profile' and '.bashrc' do NOT need to have 'x' executable permission.

Friday, July 22, 2011

selinux, ipsec-tools and '/etc/racoon/racoon.conf'

The racoon daemon failed to start, and this message was logged:

# grep denied /var/log/messages
Jul 21 17:57:56 hexgate kernel: type=1400 audit(1311267452.973:4): avc: denied { getattr } for pid=2412 comm="racoon" path="/etc/racoon/racoon.conf" dev=md0 ino=1401757 scontext=system_u:system_r:racoon_t:s0 tcontext=root:object_r:user_home_t:s0 tclass=file

So I guess I had got the wrong security context on the file. To fix it, I did this:

# ls -lZ /etc/racoon/racoon.conf
-rw------- root root root:object_r:user_home_t /etc/racoon/racoon.conf
#
# restorecon -v /etc/racoon/racoon.conf
restorecon reset /etc/racoon/racoon.conf context root:object_r:user_home_t:s0->system_u:object_r:ipsec_conf_file_t:s0
#
# ls -lZ /etc/racoon/racoon.conf
-rw------- root root system_u:object_r:ipsec_conf_file_t /etc/racoon/racoon.conf
#

..and then racoon started Ok.
So what other file security context could be relevant to racoon:

# grep racoon /etc/selinux/targeted/contexts/files//file_contexts
/etc/racoon(/.*)? system_u:object_r:ipsec_conf_file_t:s0
/var/racoon(/.*)? system_u:object_r:ipsec_var_run_t:s0
/var/run/racoon.pid -- system_u:object_r:ipsec_var_run_t:s0
/etc/racoon/certs(/.*)? system_u:object_r:ipsec_key_file_t:s0
/usr/sbin/racoon -- system_u:object_r:racoon_exec_t:s0
/etc/racoon/psk\.txt -- system_u:object_r:ipsec_key_file_t:s0
#

By the way, this was on the following system:

# cat /etc/redhat-release
CentOS release 5.5 (Final)
#
# rpm -qa | grep selinux-policy
selinux-policy-2.4.6-279.el5_5.2
selinux-policy-targeted-2.4.6-279.el5_5.2

Thursday, June 30, 2011

Installing TweetDeck with Adobe AIR on Fedora 15

Unfortunately, there is a problem installing TweakDeck on Fedora 15, and even more unfortunately, it does not look like it will be fixed.

Using the 'TechnoZeal' instructions, I had no difficulty installing Adobe AIR on Fedora 15 (64-bit), although AIR seems to be a 32-bit application and so you will need to install many 32-bit library files.

[nwsmith@fed15-x64 ~]$ rpm -qa | grep -i adobe
adobe-release-i386-1.0-1.noarch
adobeair-2.6.0-19170.i386

I downloaded the latest TweakDeck '.air' file:

[nwsmith@fed15-x64 Downloads]$ ll
-rw-rw-r--. 1 nwsmith nwsmith 2373967 Jun 30 20:46 TweetDeck_0_37.6.air
[nwsmith@fed15-x64 Downloads]$ md5sum -b TweetDeck_0_37.6.air
d8dc9c0fbff37c31c8af6a788854cb25 *TweetDeck_0_37.6.air

..but when you try to install it, it aborts with error message:

Sorry, an error has occured.
The application could not be installed because the installer file is
damaged. Try obtaining a new installer file from the application author.

Eventually I discovered that the 'Adobe AIR Application Installer' was recording a log file:

[nwsmith@fed15-x64 ~]$ cd /home/nwsmith/.appdata/Adobe/AIR/Logs/
[nwsmith@fed15-x64 Logs]$ ll
-rw-rw-r--. 1 nwsmith nwsmith 83863 Jun 30 21:41 Install.log
[nwsmith@fed15-x64 Logs]$ cat Install.log
[Adobe AIR Application Installer:4156][INFO] Application Installer begin with version 2.6.0.19170 on Linux x86
[Adobe AIR Application Installer:4156][INFO] Commandline is:
[Adobe AIR Application Installer:4156][INFO] Installed runtime (2.6.0.19170) located at /opt/Adobe AIR
[Adobe AIR Application Installer:4156][INFO] Cancel request received
[Adobe AIR Application Installer:4156][INFO] Application Installer end with exit code 6
[Adobe AIR Application Installer:4192][INFO] Application Installer begin with version 2.6.0.19170 on Linux x86
[Adobe AIR Application Installer:4192][INFO] Commandline is:
[Adobe AIR Application Installer:4192][INFO] Installed runtime (2.6.0.19170) located at /opt/Adobe AIR
[Adobe AIR Application Installer:4192][INFO] Unpackaging file:///home/nwsmith/Downloads/TweetDeck_0_37.6.air to /tmp/FlashTmp.NhdYfW
[Adobe AIR Application Installer:4192][INFO] Application signature verified
[Adobe AIR Application Installer:4192][INFO] Unpackaging/validation complete
[Adobe AIR Application Installer:4192][INFO] No app located for appID 'TweetDeckFast' and pubID 'FFF259DC0CE2657847BBB4AFF0E62062EFC56543.1'
[Adobe AIR Application Installer:4192][INFO] Converting unpackaged application to a native installation package in /tmp/FlashTmp.wkEIg0
[Adobe AIR Application Installer:4192][ERR] Native installation package creation failed: [ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Unhandled exception Error: Error creating the package /opt/Adobe AIR/Versions/1.0/Resources/rpmbuilder error : symbol not found: parseSpec, /usr/lib/librpmbuild.so: undefined symbol: parseSpec error :
<-- SNIP-->
File not found: /tmp/FlashTmp.wkEIg0/build/usr/share/app-install/desktop/tweetdeckfast.fff259dc0ce2657847bbb4aff0e62062efc56543.1.desktop" errorID=1]
[Adobe AIR Application Installer:4192][ERR] Application Installer end with exit code 7

So Googling on "symbol not found: parseSpec" we find these links:

...where Panu Matilainen summaries:

"Yes, the entire librpmbuild API has changed in rpm 4.9.x and parseSpec() no
longer exists, it's been replaced by a new saner interface known as
rpmSpecParse(). Air (whatever it is, apparently some Adobe proprietary app)
appears to be cheating against soname changes by using the non-versioned -devel
.so symlink and now gets burned because of it. It'd be much better off
launching rpmbuild than using the librpmbuild API.

And yes, Fedora 15 is using rpm 4.9.x:

[nwsmith@fed15-x64 ~]$ rpm -qa | grep ^rpm | sort
rpm-4.9.0-9.fc15.x86_64
rpm-build-4.9.0-9.fc15.x86_64
rpm-build-libs-4.9.0-9.fc15.i686
rpm-build-libs-4.9.0-9.fc15.x86_64
rpm-devel-4.9.0-9.fc15.i686
rpm-devel-4.9.0-9.fc15.x86_64
rpm-libs-4.9.0-9.fc15.i686
rpm-libs-4.9.0-9.fc15.x86_64
rpm-python-4.9.0-9.fc15.x86_64

So it looks like Adobe need to fix it. Unfortunately, we read here that:

"Note: Beginning June 14 2011, Adobe AIR is no longer supported for desktop Linux distributions."

So I've given up on this. A pity as it would have been really nice to run TweetDeck on Fedora Linux. Anyway now I guess I can remove all those 32-bit libraries I just install, and revert to a 'clean' 64-bit environment.


Status Update: 2011-07-15
Please read Sérgio Basto's comments to this post. Sérgio seems to have found a way around the problem, using Mock. I've not yet tried this for myself, but I will give it a try when I have a few minutes to spare. If anyone else tried this method, please post a comment with your result.


Status Update: 2011-07-22
Chris Beckenbach is reporting success with Sergio's method.

Tuesday, June 14, 2011

DTrace for Linux: Progress, but still a work in progress

A couple of months back, I blog posted on Paul Fox's port of DTrace to Linux. I've continued to play around with it since then, and so I think its about time for another blog post about it.

Certainly now there is no problem compiling DTrace for Linux on Fedora 14 with the 2.6.35 kernel, provided you install the necessary dependencies that I listed in the previous post. Since my initial report, I've exchanged many emails with Paul, and he had been able to incorporate in the code the necessary fixes to support compiling on Fedora.

Paul has spent a lot of time recently on the cross-call (aka xcall) problem, and you can read the details on Paul's blog. Certainly this is a challenging area, and although there are still some issues, it looks to me like Paul is determined to fully resolve the issues.

Ok, so let's give DTrace for Linux a bit of a work out and discover a little bit more about it.

After compiling, with 'make all' and installing with 'make install', you load
the DTrace module, with 'make load'.

# uname -a
Linux fed14-64 2.6.35.13-91.fc14.x86_64 #1 SMP Tue May 3 13:23:06 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
# make load
tools/load.pl
21:41:23 Syncing...
21:41:24 Loading: build/driver/dtracedrv.ko
21:41:25 Preparing symbols...
21:41:25 Probes available: 319433
21:41:30 Time: 7s

So you can see there are a lot of probes available. Let's look at a break down:

# dtrace -l | awk '{ print $2 }' | sort | uniq -c | sort -n
1 PROVIDER
3 dtrace
4 io
17 profile
1270 syscall
63808 fbt
254330 instr

You can see that most of the probes come from the 'instr' provider, which I believe is unique to the Linux port of DTrace. And note that the number of providers available is less than what is available on Solaris and FreeBSD.

Let's list the probes, where there are only a small number of probes for the providers:

[root@fed14-64 ~]# dtrace -l -n dtrace:::
ID PROVIDER MODULE FUNCTION NAME
1 dtrace BEGIN
2 dtrace END
3 dtrace ERROR
[root@fed14-64 ~]# dtrace -l -n io:::
ID PROVIDER MODULE FUNCTION NAME
4 io do_sync_read start
5 io do_sync_read done
6 io do_sync_write start
7 io do_sync_write done
[root@fed14-64 ~]# dtrace -l -n profile:::
ID PROVIDER MODULE FUNCTION NAME
254912 profile profile-97
254913 profile profile-199
254914 profile profile-499
254915 profile profile-997
254916 profile profile-1999
254917 profile profile-4001
254918 profile profile-4999
254919 profile tick-1
254920 profile tick-10
254921 profile tick-100
254922 profile tick-500
254923 profile tick-1000
254924 profile tick-5000
319429 profile tick-1ms
319430 profile tick-1s
319431 profile tick-5s
319432 profile tick-10s

Now let's give a breakdown of the number of probes available for each modules for the FBT (Function Boundary Tracing) provider. This will give you an idea of what kernel modules I have loaded on my test system.

[root@fed14-64 dtrace-20110404]# dtrace -l -P fbt | awk '{print $3}' | sort | uniq -c | sort -n
1 MODULE
12 freq_table
13 output
14 speedstep_lib
15 iTCO_vendor_support
15 p4_clockmod
23 i2c_i801
29 ppdev
30 i2c_algo_bit
31 iTCO_wdt
33 snd_page_alloc
37 snd_seq_device
37 soundcore
41 dcdbas
41 snd_hwdep
61 sata_sil24
63 microcode
79 snd_hda_intel
83 parport_pc
99 snd_timer
100 drm_kms_helper
109 video
138 scsi_transport_spi
141 i2c_core
155 parport
199 snd_hda_codec_idt
337 ttm
357 snd
357 tg3
359 snd_seq
420 fuse
424 aic7xxx
490 snd_hda_codec
495 snd_pcm
744 e1000e
867 drm
1671 ipv6
1875 nouveau
52615 kernel

As you can see from the above, I have two different network interface cards in my system. One is a Broadcom, supported by the 'tg3' module, and the other is an Intel card, supported by the 'e1000e' module.

Lets list the probes available for one of the FBT modules:

# dtrace -l -n fbt:p4_clockmod::entry
ID PROVIDER MODULE FUNCTION NAME
310254 fbt p4_clockmod cpufreq_p4_get entry
310256 fbt p4_clockmod cpufreq_p4_setdc entry
310258 fbt p4_clockmod cpufreq_p4_target entry
310260 fbt p4_clockmod cpufreq_p4_verify entry
310262 fbt p4_clockmod cpufreq_p4_cpu_init entry
310264 fbt p4_clockmod cpufreq_p4_exit entry
310266 fbt p4_clockmod cpufreq_p4_cpu_exit entry
310268 fbt p4_clockmod cleanup_module entry
# dtrace -l -n fbt:p4_clockmod::return
ID PROVIDER MODULE FUNCTION NAME
310255 fbt p4_clockmod cpufreq_p4_get return
310257 fbt p4_clockmod cpufreq_p4_setdc return
310259 fbt p4_clockmod cpufreq_p4_target return
310261 fbt p4_clockmod cpufreq_p4_verify return
310263 fbt p4_clockmod cpufreq_p4_cpu_init return
310265 fbt p4_clockmod cpufreq_p4_exit return
310267 fbt p4_clockmod cpufreq_p4_cpu_exit return

Ok, enough of listing probes! Let show some simple DTrace one-liners in action on Linux:

# dtrace -n 'syscall:::entry { @num[execname] = count(); }'
dtrace: description 'syscall:::entry ' matched 635 probes
^C
audispd 1
udisks-daemon 6
rtkit-daemon 8
gnome-settings- 9
abrtd 10
console-kit-dae 10
hald-addon-acpi 12
sendmail 14
gnome-screensav 15
sshd 17
crond 18
dbus-daemon 18
gnome-panel 33
gnome-power-man 38
clock-applet 49
gvfs-afc-volume 60
metacity 68
irqbalance 120
nautilus 157
gedit 362
dtrace 1553
Xorg 10039
firefox 12083
#
# dtrace -n 'syscall:::entry { @num[probefunc] = count(); }'
dtrace: description 'syscall:::entry ' matched 635 probes
^C
rt_sigreturn 1
brk 2
getdents 2
select 6
stat 8
nanosleep 11
rt_sigaction 16
munmap 18
close 21
fstat 21
mmap 21
inotify_add_watch 26
open 32
rt_sigprocmask 32
ioctl 49
write 195
poll 525
read 736
futex 1283
#
# dtrace -n 'fbt:e1000e::entry { @num[probefunc] = count(); }'
dtrace: description 'fbt:e1000e::entry ' matched 373 probes
^C
e1000_clean 17
e1000_clean_rx_irq 17
e1000_clean_tx_irq 17
e1000_desc_unused.clone.26 17
e1000_intr_msi 17
e1000_irq_enable 17
e1000_watchdog 17
e1000_watchdog_task 17
e1000e_get_laa_state_82571 17
e1000e_has_link 17
e1000e_update_adaptive 17
e1000e_update_stats 17
napi_schedule_prep 17
test_and_set_bit 17
e1000_ioctl 34
e1000_get_stats 411

Here is the 'instr' provider in action:

# dtrace -n 'instr:e1000e:: { @num[probefunc] = count(); }'
dtrace: description 'instr:e1000e:: ' matched 3472 probes
^C

e1000_get_drvinfo-je 1
e1000_get_drvinfo-jne 1
e1000e_get_sset_count-ja 3
e1000_get_drvinfo-callr 5
e1000_clean_rx_irq-callr 27
e1000_clean_rx_irq-je 27
e1000_desc_unused.clone.26-jbe 27
e1000_irq_enable-je 27
e1000_watchdog-callr 27
e1000e_get_laa_state_82571-jne 27
e1000e_update_adaptive-jbe 27
e1000e_update_adaptive-je 27
e1000e_update_adaptive-jne 27
e1000e_update_stats-jbe 27
napi_schedule_prep-callr 27
napi_schedule_prep-jne 27
test_and_set_bit-lock 27
e1000_clean-jne 54
e1000_intr_msi-callr 54
e1000_intr_msi-je 54
e1000e_has_link-je 54
e1000e_update_stats-ja 54
e1000_clean-callr 81
e1000_clean-je 81
e1000_watchdog_task-jne 81
e1000_clean_tx_irq-je 108
e1000_watchdog_task-je 108
e1000_watchdog_task-callr 189

One of the aspects that Paul has been developing recently is a suite of test programs that can be used to stress test the system, and expose any problems with the DTrace for Linux port. To try this out, run 'make test'.

Ok, I'm out of time for tonight. Hopefully I can find time for some more post to this blog soon.

Thursday, March 31, 2011

Trying DTrace for Linux on Fedora 14

Some months, or even years ago, I noticed that Paul Fox, the author of the CRiSP editor, was working on a port of DTrace to Linux. Paul seems to have started work on this port back at the start of 2008. He has made regular progress reports on his website blog, and from June 2010, he also started using Google's blogger, which did seem to have taken over as Paul's main blog, but now I notice he has put all the blogger posts back on his website blog!

In February 2011, I finally go around to trying out the code.

Paul seems to be developing on/for Ubuntu, but I wanted to try it on Fedora 14. I had a number of problems, first indentifying which RPM packages I needed to install for the build. And then there were various compile problems, and it took me a while to figure out how to resolve these problems, as I would not claim to be any sort of expert on this.

Here is a list of the RPM packages I needed to install to get the code to compile:

binutils-devel
elfutils-libelf-devel
kernel-devel
libdwarf
libdwarf-devel
libdwarf-static
zlib-devel

I was eventually able to work out the necessary patches to get it to compile on Fedora 14. I did try emailing Paul to give him some feedback, and I think he may have read my emails, but so far I have never received a reply back from him!

Here for posterity, I publish my patch, just to prove I did some work! But note that this is already out of date, as Paul's DTrace for Linux port has continued to moved on.
$ diff -uNr dtrace-20110215 dtrace-20110215.fed14/
diff -uNr dtrace-20110215/cmd/ctfconvert/dwarf.c dtrace-20110215.fed14/cmd/ctfconvert/dwarf.c
--- dtrace-20110215/cmd/ctfconvert/dwarf.c 2010-08-24 23:34:26.000000000 +0100
+++ dtrace-20110215.fed14/cmd/ctfconvert/dwarf.c 2011-03-18 01:19:57.786335906 +0000
@@ -88,9 +88,9 @@
#include <errno.h>
#include "linux.h"
#include <libelf.h>
-#include <libdwarf.h>
+#include <libdwarf/libdwarf.h>
#include <libgen.h>
-#include <dwarf.h>
+#include <libdwarf/dwarf.h>

#include "ctf_headers.h"
#include "ctftools.h"
diff -uNr dtrace-20110215/cmd/ctfconvert/makefile dtrace-20110215.fed14/cmd/ctfconvert/makefile
--- dtrace-20110215/cmd/ctfconvert/makefile 2010-10-17 17:55:26.000000000 +0100
+++ dtrace-20110215.fed14/cmd/ctfconvert/makefile 2011-03-18 01:19:23.255448742 +0000
@@ -44,7 +44,7 @@
LIBS = ../../build/libctf.a -ldwarf -lbfd -lelf -lz

all:
- @if [ ! -f /usr/lib/libdwarf.a ]; then \
+ @if [ ! -f /usr/lib64/libdwarf.a ]; then \
echo "=================================================================" ; \
echo "=== You need /usr/lib/libdwarf.a and /usr/lib/libbfd.a installed to build." ; \
echo "=== " ; \
diff -uNr dtrace-20110215/tools/build.pl dtrace-20110215.fed14/tools/build.pl
--- dtrace-20110215/tools/build.pl 2011-01-26 23:36:06.000000000 +0000
+++ dtrace-20110215.fed14/tools/build.pl 2011-03-19 14:16:48.725192127 +0000
@@ -59,7 +59,7 @@
}

if (! -f "/usr/include/gelf.h") {
- print "Error: you dont appear to have /usr/include/elf.h, which means\n";
+ print "Error: you dont appear to have /usr/include/gelf.h, which means\n";
print "compilation will fail. You should add the libelf-dev package to\n";
print "your system and retry the 'make all'.\n";
exit(1);
diff -uNr dtrace-20110215/tools/mkctf.sh dtrace-20110215.fed14/tools/mkctf.sh
--- dtrace-20110215/tools/mkctf.sh 2010-08-26 10:03:21.000000000 +0100
+++ dtrace-20110215.fed14/tools/mkctf.sh 2011-03-18 01:21:59.600884493 +0000
@@ -19,11 +19,11 @@
cd $build_dir
cmd=`grep '^cmd_' $pwd/build/driver/.cpu_x86.o.cmd |
sed -e 's/^.* := //' |
-sed -e 's/-Wp,-MD[^ ]* /-g /' |
+sed -e 's/-Wp,-MD[^ ]* /-gdwarf-2 /' |
sed -e 's/\\\\//g' |
sed -e 's/cpu_x86/ctf_struct/g' `
#echo $cmd
eval $cmd
cd $pwd
-build/ctfconvert -L label -o build/linux-$BUILD_KERNEL.ctf build/driver/.tmp_ctf_struct.o
+build/ctfconvert -L label -o build/linux-$BUILD_KERNEL.ctf build/driver/ctf_struct.o
ls -l build/linux-$BUILD_KERNEL.ctf

And here is a very quick and basic test, to show DTrace running:

# uname -a:
Linux fed14-64 2.6.35.11-83.fc14.x86_64 #1 SMP Mon Feb 7 07:06:44 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
# make load
tools/load.pl
01:26:50 Syncing...
01:26:50 Loading: build/driver/dtracedrv.ko
01:26:52 Preparing symbols...
01:26:52 Probes available: 314700
01:26:56 Time: 6s

# dtrace -n BEGIN
dtrace: description 'BEGIN' matched 1 probe
CPU ID FUNCTION:NAME
1 1 :BEGIN
^C

Admittedly, that is the most basic DTrace one-liner you can possibly try. But I did also try a few 'syscall' one-liners, mostly with success.

Anyway, once I got this going, I wanted to try with Paul's latest release of the code, to get his latest bug fixes, but I was stopped in my tracks, as his FTP site was down. And it continued to be down, for over a week, which was quite frustrating. I tried emailing him, and leaving a blog comment, but again, I got no response. And there was no mention of this problem on his web sites, or blog.

Eventualy, while Googling, I discovered that Paul has a Twitter account, and that he had announced there, that he has a new host name for his FTP site. There is no mention of Paul's Twitter account on his web sites or blogs, at this moment. So I will publicize it here, as he does seem to make good use of it to report progress with DTrace for Linux:
http://twitter.com/#!/crispeditor

And for anyone wanting to try compiling the DTrace for Linux code, please note the new download site is:
ftp://crisp.dyndns-server.com/pub/release/website/dtrace/


Ok, so now I guess I had better download the latest release of the code, and try it out.

Thursday, January 27, 2011

selinux, hwclock and /etc/adjtime

If you are having problems with hwclock, you may want to remove the file '/etc/adjtime' and let hwclock recreate the file, for reasons discussed here:

"hwclock never updates drift factor in /etc/adjtime if time is always set more than once a day"

However, if you have selinux enabled, with an enforcing targeted policy, this will result in the wrong file security context. Here is how to fix it:

# ls -Z /etc/adjtime
-rw-r--r-- root root root:object_r:etc_t:s0 /etc/adjtime

# restorecon -v /etc/adjtime
restorecon reset /etc/adjtime context root:object_r:etc_t:s0->system_u:object_r:adjtime_t:s0

# ls -Z /etc/adjtime
-rw-r--r-- root root system_u:object_r:adjtime_t:s0 /etc/adjtime

# grep adjtime /etc/selinux/targeted/contexts/files/file_contexts
/etc/adjtime -- system_u:object_r:adjtime_t:s0

Thursday, July 29, 2010

Running Access 97 on Windows 7

Today I had to get Access 97 running on a Windows 7 64bit PC. When I arrived on site, my colleague had already successfully installed Office 97, and the SR-1 patch (sr1off97.exe). So I guess that the well known "Hatten" file issue had already been resolved.

"There is no license" error message starting Microsoft Access
http://support.microsoft.com/kb/141373

On further investigation, I found that an attempt to install the SR-2 patch had failed, and also that the on-line help for Access 97 was not working at all. And I could see that the "Programming help" file had not been installed.

To install "Programming help", I ran the maintenance setup, but it soon failed, reporting message "Setup Error 825 - Object 9807". This issue is covered by the Microsoft support Article ID: 156638

OFF97: International English SR-1 Patch Offpro97.inf
http://support.microsoft.com/kb/156638

Basically, you need to download file "offpro97.exe" and extract from that the file "off97pro.inf" and copy it across to the 'setup' directory, replacing the existing file.

To get the help working, you need to install support for "winhelp32.exe".
This issue is covered by the Microsoft support Article ID: 917607

I cannot open Help files that require the Windows Help (WinHlp32.exe) program
http://support.microsoft.com/kb/917607

But then when you try to use the Access 97 help files, you will get error "There was a problem running the macro. (1037)". The fix for this is covered in the same Microsoft support article.

Basically, you need to run "C:\WINDOWS\syswow64\regedit32.exe" and create key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WinHelp" and then create DWORD "AllowProgrammaticMacros" and set it to value "1".

In order to install the SR-2 patch (sr2bof97.exe), you need to replace some of the Windows 7 font files, with older versions copied from Windows XP. These are the font files, from Windows XP, that I used:

17/07/2004 11:39 127,596 comic.ttf
29/08/2002 13:00 111,476 comicbd.ttf
21/11/1996 00:00 41,408 hatten.ttf
17/07/2004 22:55 383,140 tahoma.ttf
17/07/2004 22:55 355,436 tahomabd.ttf

Finally, I installed file "Jet35sp3.exe" to make sure the Jet Engine was at the final version.

Ok, so that's it. I tried testing a few things with Access 97, and it seems to run fine on Windows 7.