OSX – How to change the root user’s shell.

Or the default shell of any user for that matter. I don’t know if this is recommended or not, but changing from /bin/sh to /bin/bash will enable tab-completion, and since I’m a lazy admin that’s what I’ll do. (Plus, less keystrokes = longer hardware life for my keyboard.)

This command will display the user’s default shell (replace root with desired username):
rivendell:~ root# dscl . -read /Users/root UserShell

Now change the shell (in this case to /bin/bash):
rivendell:~ root# dscl . -change /Users/root UserShell /bin/sh /bin/bash

Make sure it was changed:

rivendell:~ root# dscl . -read /Users/root UserShell
UserShell: /bin/bash
rivendell:~ root# echo $0
-sh
rivendell:~ root# su -
rivendell:~ root# echo $0
-bash

CPAN changing permissions on OSX

some Perl code
some Perl code

If you are looking for a Perl module to interface with Amazon’s S3 hosting service, do not use the Net::Amazon::S3 module. It has an unrealistically huge list of modules on which it’s dependent (one of which is more like a framework — a pain in itself) and you’ll likely never get it installed. The Amazon::S3 module by Timothy Appnel installs without a hitch, and it was based on an earlier version of the Net::Amazon::S3 module.

So apparently something in CPAN on OSX 10.6 (Perl version 5.10.0) causes it to change permissions of the /usr/bin/cpan script, not only removing the executable bit for all, but also setting the write bit (not good).

This results in the common “permission denied” message when someone trys to run CPAN to install some Perl modules:


[root@lorien ~]# cpan
-bash: /usr/bin/cpan: Permission denied

For the uninitiated, this permission change will render your CPAN installation completely vulnerable to anyone who logs in (or breaks in) to the system, even standard “normal” user accounts.

You can run this find statement to show all files in a directory (including subdirectories) that are world-writeable:
find . -perm -o+w

In the example below, I’ve paired this with the “exec” argument using ‘ls’ to show the permissions and inode number of each file.


[root@lorien bin]# find . -perm -o+w -exec ls -ldi {} \;
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./c2ph
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./corelist
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./cpan
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./cpan2dist
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./cpanp
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./cpanp-run-perl
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./dprofpp
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./enc2xs
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./find2perl
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./h2ph
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./h2xs
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./libnetcfg
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./perlbug
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./perlcc
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./perldoc
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./perlivp
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./perlthanks
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./piconv
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./pl2pm
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./pod2html
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./pod2latex
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./pod2man
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./pod2text
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./pod2usage
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./podchecker
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./podselect
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./psed
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./pstruct
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./ptar
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./ptardiff
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./s2p
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./shasum
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./splain
2491453 -rw-rw-rw- 34 root wheel 807 2009-06-24 02:42 ./xsubpp

As you can see from the output, there are a lot of files that were affected, but you can also see from the inode number that they are all hard links to the same file (good in this case). So, we fix the permissions on one file and we fix them all.


[root@lorien bin]# chmod 0755 cpan
[root@lorien bin]# ls -ld cpan
-rwxr-xr-x 34 root wheel 807 2009-06-24 02:42 cpan
[root@lorien bin]# find . -perm -o+w -exec ls -ldi {} \;
[root@lorien bin]#

Life is good again. (Note: this will fix the problems, but not the root cause. I’m too lazy to start looking into CPAN itself to find the root cause, so… I’ll leave it to the smart guys who actually write the code for CPAN to figure that one out.)

And in case you are wondering, yes, my computer’s name is Lorien. What can I say? I’m a LotR nerd. Not too unusual for us techie types.

Mac OS X – madplay mp3 player

This was originally posted on my old blog, ngmarleyDOTnet, on May 8, 2009 @ 11:20 CST. That blog is now defunct and the content is slowly being absorbed into this one. I pretty much do use iTunes exclusively on my Macbook now, but wanted to preserve this for posterity.

I’m not a huge fan of iTunes. On my Linux systems, I use a command-line MP3 player. I simply type the names of the files I want to play as arguments.

By contrast, I have to click around about 17 different times to play the songs I want in iTunes, including clicking around in the “open file/folder” dialog box (because Apple apparently believes the average Mac user too stupid to be able to type the absolute path to the file(s) on disk, so they don’t offer that as an option). The UI is, to me, insufferable. All I want to do is play a few songs, quickly. Seriously, it should take less than 2 seconds to do this.

More stuff I hate about iTunes:

  • the iTunes store. Which can’t be disabled or hidden (not very well, anyway)
  • the Genius Sidebar (which can be hidden, but is nevertheless annoying)
  • I’m sure there’s more, but I’m getting irritated just thinking about iTunes

I attempted to compile the current source release of madplay, and was able to do so after patching audio_carbon.c, but didn’t get any audio output.

Finally I was able to install this using fink, but then received this error:


[root@lorien ~]# madplay
dyld: Library not loaded: /sw/lib/libintl.1.dylib
Referenced from: /sw/bin/madplay
Reason: image not found
Trace/BPT trap

At first glance it appears as though I need to install libintl, but I went poking around in the fink lib directory /sw/lib. Apparently I already had a couple of versions of libintl installed (both static and dynamic), but none to match the version above. Of course this was easily fixed with a symbolic link:


[root@lorien lib]# ln -s libintl.dylib libintl.1.dylib
[root@lorien lib]# logout
[ngmarle@lorien Mana]$ madplay
Usage: madplay [OPTIONS] FILE [...]
Try `madplay --help' for more information.

Now I have all the functionality of my favorite cmd-line mp3 player on my Macbook.

*note: I was able to compile/install mpg123 from source, but the pause function put on a 1-second infinite loop instead of actually pausing. I also had to modify the mpg123 source to be able to exit the player without having to kill the process from an external terminal window.

The below is other debugging I was using: “otool -L” is like “ldd” on Linux. This will list the dynamic dependencies (shared libraries on which an executable is dependent) for an executable.


[root@lorien ~]# otool -L /sw/bin/madplay
/sw/bin/madplay:
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 136.0.0)
/sw/lib/libintl.1.dylib (compatibility version 2.0.0, current version 2.1.0)
/sw/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/sw/lib/libmad.0.dylib (compatibility version 3.0.0, current version 3.1.0)
/sw/lib/libid3tag.0.dylib (compatibility version 4.0.0, current version 4.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.1)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 32.0.0)