Monday, April 25, 2011

Dropbox authentication issues

There has been some discussion of whether the dropbox authentication system is a vulnerability, or just as insecure as everything else. At the very least: if changing your password doesn't change the underlying key stored on your machine, that an attacker could have copied, it makes denying access to an attacker post-compromise fairly difficult.

Wednesday, April 13, 2011

#ifdef DEBUG print statements in C

The #ifdef DEBUG design pattern for debug output is extremely common in C code. Here is a nice DEBUG macro I have used in the past:

#ifdef DEBUG
#define DEBUG_PRINT(fmt, args...)  \
       fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __FUNCTION__, ##args)
#define DEBUG_PRINT(fmt, args...)    /* Don't do anything in non-debug builds */

As suggested in this post, letting the compiler see your debug code is important to ensure it isn't broken by people changing code without making debug builds. This macro achieves that goal by letting the preprocessor insert a statement that will be pulled out by the optimiser for non-debug builds. This is the best solution I have come across.

#ifdef DEBUG
#define DEBUG_TEST 1
#define DEBUG_TEST 0

#define DEBUG_PRINT(fmt, args...) \
        do { if (DEBUG_TEST) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
                                __LINE__, __FUNCTION__, ##args); } while (0)

Mingw example makefile for console app and DLL

Here is a basic Makefile to use with mingw to compile some common types of windows binaries - a windows console app, a non-console 'windows' subsystem app, and a DLL.

# Example mingw makefile


CC = i586-mingw32msvc-gcc

# A basic windows app (won't bring up a console window)
CFLAGS = -Wall -O -Wl,--subsystem,windows

# for debugging make this a console app (so we can write to stdout/stderr) easily;
# turn off optimisations and include symbols to help with running in a debugger
CFLAGS_DEBUG = -Wall -O0 -g -Wl,--subsystem,console -DDEBUG

# Create a dll instead of an exe
CFLAGS_DLL = -Wall -O0 -g -shared -Wl,--subsystem,windows -DDLL

# Any libraries you need - in this case wininet for communicating to the internet
LIBS = -lwininet

# Strip the binary for our prod build
STRIP = i586-mingw32msvc-strip

# UPX pack to minimise size for our prod build
UPX=upx -9

# Leave symbols, turn off optimisation, and send output to console
debug: $(TARGETNAME).c
        $(CC) -o $(TARGETNAME)_dbg $(CFLAGS_DEBUG) $^ $(LIBS)

# No debug symbols, debug statements removed, subsystem windows means we won't pop a window
        $(CC) -o $@ $(CFLAGS) $^ $(LIBS)

        $(CC) -o $@ $(CFLAGS_DLL) $^ $(LIBS)

release: $(TARGETNAME)
        $(STRIP) $<
        $(UPX) $<

Using a word macro to run an executable on Windows 7, Office 2007

To write a macro in Office 2007, you'll want the developer tab in the ribbon.  Turn it on by clicking the Office icon in the top left corner of Word and then 'Word Options'.  Find the 'Show Developer tab in the Ribbon' and check it.

Use this macro code to run blah.exe when the document is opened (using AutoOpen):

Private Declare Function WinExec Lib "Kernel32.dll" (ByVal lpCmdLine As String, ByVal nShowCmd As Long) As Long

Sub AutoOpen()

    Call WinExec("C:\blah.exe", SW_NORMAL)

End Sub

Sunday, April 3, 2011

Streaming internet radio with MythTV

Streaming internet radio with mythtv is, sadly, still confined to the realm of hacks. One simple solution is to just drop ".pls" files into your videos directory. Assuming you use mplayer to play your videos, that should just work. Unfortunately I like to use the internal player so I can use the time stretch feature on videos as well as recordings. The internal player doesn't play ".pls" files, so that option is out.

The other approach is to hack in a new menu item and get it to run mplayer. There are a few descriptions of how to do this, so here is my 2c.

Edit /usr/share/mythtv/themes/defaultmenu/library.xml to add:

    <text>Listen to Internet Radio</text>
    <description>Listen to Internet Radio</description>
    <action>MENU inetradio.xml</action>

And create inetradio.xml in the same directory.  The Australian Broadcasting Corporation (ABC) links are a little hard to find - you can get them here.
<mythmenu name="INETRADIO">

<action>EXEC /usr/bin/mythradio</action>

<action>EXEC /usr/bin/mythradio</action>

<action>EXEC /usr/bin/mythradio</action>

<text>666 ABC Canberra</text>
<action>EXEC /usr/bin/mythradio</action>

<text>ABC Classic FM</text>
<action>EXEC /usr/bin/mythradio</action>

<text>Stop Playing</text>
<action>EXEC pkill -f mplayer</action>


And create /usr/bin/mythradio (this wouldn't be necessary if you could give multiple commands to "EXEC" - unfortunately it seems to break the syntax and mythtv says it is an invalid XML file). The include file is a one line mplayer config that tells mplayer to allow the screensaver to run, so you can avoid burn-in while listening to the radio.

pkill -f mplayer
/usr/bin/mplayer -include /etc/mythtv/mplayer_noscr.conf $1 &

and here is /etc/mythtv/mplayer_noscr.conf: