2009年12月12日 星期六

Add "Edit with Vim" into Windows 7 context menu

Ref: http://davidvielmetter.com/?p=1094

Two solutions are provided by David:

1) Edit the registry

Save the following content as a .reg file and merge with your registry
---8<---8<---8<---8<--- cut here ---8<---8<---8<---8<---
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Edit with Vim]

[HKEY_CLASSES_ROOT\*\shell\Edit with Vim\command]
@="C:\\Program Files (x86)\\Vim\\vim72\\gvim.exe \"%1\""
---8<---8<---8<---8<--- cut here ---8<---8<---8<---8<---

2) Vim as a "send to" target

Place the link of the "gvim.exe" into

C:\Users\\AppData\roaming\microsoft\windows\SendTo

2009年11月25日 星期三

Netfilter: Look up real destination IP address and port number after NATed

A user space server (or proxy daemon) may need to know the original IP address and port number of a connection before the connection is NATed (usually port redirection). This can be done easily with Netfilter/Linux. The steps are:
  1. accept() a new connection: c = accept(s, (struct sockaddr*) &sin, &sinlen)
  2. getsockopt(c, &sin, SOL_IP, SO_ORIGINAL_DST, &sin, &tsinlen).
The original destination IP address and port number can be then extracted from sin.sin_addr and sin.sin_port.

2009年11月16日 星期一

Compile Snort with large file support on Linux

Add these environment variables when running the configure script:

CFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64" ./configure ...

The built snort will be able to read trace files greater than 2GiB.

Modify Netfilter Packet Flow

We can often find the default netfilter packet flow from the following figure (although it's a little bit out dated ...):




You may wish to change the position of these blocks (hooks). It is not really complex to do that. As we can find the priority of these hooks in (kernel-source)/include/linux/netfilter_ipv4.h (if you'd like to modify other address families, just find the corresponding header files). Simply add new priorities into the enumeration of nf_ip_hook_priorities and then modify the table registration data structure, e.g., the mangle table registration is done in (kernel-source)/net/ipv4/netfilter/iptable_mangle.c.

Suppose we are going to move the "mangle" table before "nat" table in the POSTROUTING chain. The steps are:
  1. Add a new priority, say NF_IP_PRI_POST_MANGLE = 150 into the nf_ip_hook_priorities enumeration.
  2. Modify the ipt_ops data structure in iptable_mangle.c so that the priority of that hook in POSTROUTING chain is set to the newly added NF_IP_PRO_POST_MANGLE.
Recompile your kernel and everything is done! Just remember that a hook with a lower priority number will be placed earlier in the chain.


2009年11月15日 星期日

Setup PPTP server in Ubuntu

It's quick and easy. The steps are:
  1. apt-get install pptpd
  2. Modify "localip" and "remoteip" in /etc/pptpd.conf
  3. (Optional) Modify "ms-dns" in /etc/ppp/pptpd-options
  4. Add user accounts and passwords into /etc/ppp/chap-secrets. Place each user in a single line: username * "password" *
That's it.

2009年10月24日 星期六

iSCSI initiator on Ubuntu

Ref: http://www.cyberciti.biz/faq/howto-setup-debian-ubuntu-linux-iscsi-initiator/

Here are procedures to mount a iSCSI disk drive. I've tested it on Ubuntu 8.10:
  1. Install the open-iscsi package via apt-get

  2. Edit /etc/iscsi/iscsid.conf, below is my configuration:

    (You may read the original /etc/iscsi/iscsid.conf for more details)

    node.startup = automatic
    # it seems specify to use CHAP exactly will not work!? really strange!
    #node.session.auth.authmethod = CHAP
    node.session.auth.username = your-username
    node.session.auth.password = your-password
    discovery.sendtargets.auth.username = your-username
    discovery.sendtargets.auth.password = your-password
    node.session.timeo.replacement_timeout = 120
    node.conn[0].timeo.login_timeout = 15
    node.conn[0].timeo.logout_timeout = 15
    node.conn[0].timeo.noop_out_interval = 10
    node.conn[0].timeo.noop_out_timeout = 15
    node.session.initial_login_retry_max = 4
    node.session.iscsi.InitialR2T = No
    node.session.iscsi.ImmediateData = Yes
    node.session.iscsi.FirstBurstLength = 262144
    node.session.iscsi.MaxBurstLength = 16776192
    node.conn[0].iscsi.MaxRecvDataSegmentLength = 131072
    discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
    # allow the targets to control the setting of the digest checking
    node.conn[0].iscsi.HeaderDigest = CRC32C,None
    node.conn[0].iscsi.DataDigest = CRC32C,None

  3. Restart open-iscsi by: /etc/init.d/open-iscsi restart

  4. Discover the iscsi host by:
    iscsiadm -m discovery -t sendtargets -p ISCSI-SERVER-IP-ADDRESS
    It should return the available targets, e.g.,
    192.168.1.xx:3260,1 iqn.2009-10.Zebra:iscsi1

  5. Login the target you want to use by:
    iscsiadm -m node -T iqn.2009-10.Zebra:iscsi1 -p 192.168.1.33 -l
    There should be no error messages if the configuration is correct.

  6. Restart open-iscsi, again. The target you'd like to use should be automatically logged in and you can find its device name by dmesg or /var/log/messages.

  7. Suppose its device name is /dev/sdb, create a partition: fdisk /dev/sdb

  8. Format the partition: mke2fs -j /dev/sdb

  9. Finally, mount it by:
    mount -t ext3 /dev/sdb /path/to/your/mount/point

That's all. Enjoy it!


2009年10月16日 星期五

Occupied IME hot key

Recently, I ungrade an IME method by uninstalling its old one and the install the new one. However, when I have finished the installation, I found that I cannot assign the same hotkey to switch to the IME! It's just told me "請檢查是否有另一個項目使用相同的按鍵順序". Eh ... that's a stupid and inconvient design!

A solution to this problem may be -- downgrade to the original IME, remove its hotkey, and then upgrade again.

A better solution may be remove the old hotkey configuration directly from the registry. Find the folder:

HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys

There are many subfolders inside it, for example, 00000100, 00000101, 000102, ..., etc. In each subfolder, there are three major values, they are: Key Modifiers, Target IME, and Virtual Key. By inspection the Key Modifiers and Virtual Key, we can identify which is the right subfolder we should remove. For example, suppose the hotkey we would like to remove is Alt-Shift+9, the value for Key Modifiers would be "05 0c 00 00" and the value for Virtual Key would be "39 00 00 00".

Find the subfolder that contains the hotkey you are going to use. Remove it, and then you should be able to assign it to the upgraded IME.


Note: Key Modifier for Ctrl-Shift is "06 0c 00 00"

2009年10月15日 星期四

Missing MSVCP60.DLL

It really sucks that my Windows XP cannot boot again after I have uninstalled ASUS GamerOSD. The services.exe complains that it cannot find MSVCP60.DLL and suggest I to re-install an application ... Well, should I blame Microsoft or ASUS?

Anyway, after googling for a while, I tried the following solution and it works. All you need is a Windows XP installation CD. The steps to repair the file are:
  1. Boot using the Windows XP installation CD. Enter the repair console by pressing "R".

  2. Choose the location of your Windows XP installation and login with system administrator's password. Suppose your Windows XP is installed in C:\Windows directory.

  3. Get a MSVCP60.DLL: I would not recommend you to download it from Internet since that one from Internet may contain malicious codes ... you will never know.

    Here are some places that you may find this file in your harddisk:

    1. The C:\Windows\ServicePackFiles\I386\MSVCP60.DLL directory - You can copy it to C:\Windows\System32 directly.

    2. The (CD-ROM drive) X:\I386\MSVCP60.DL_ - You need to expand this file using the comand "expand X:\I386\MSVCP60.DL_ C:\Windows\System32"

    Choose one of the two above sources you like.

  4. Congratulations! You are almost done ... An important step here is to set the read-only attribute for MSVCP60.DLL. This is because the startup script may have scheduled to delete this file on boot time. Setting up the read-only attribute prevents this file being deleted. You can do this by the command "attrib +r C:\Windows\System32\MSVCP60.DLL".

  5. OK! Reboot your machine ... You should be able to boot normally.

Good luck to whom encounter the problem!

2009年10月14日 星期三

Linux: Format new partitions

Preferred file system type: ext4

mke2sf -t ext4 -j -O large_file,extent,uninit_bg /dev/sdaX
  • large_file: support > 2GB files, may be enabled by default
  • extent: ext4 only, increase performance for large file access
  • uninit_bg: reduce fsck time
tune2fs /dev/sdaX -m 1 /dev/sdaX
  • Well, for large partitions, I suggest the percentage of reserved spaces must be reduced -- imagine that 5% (default) for a 2TB disk is close to 100GB!
tune2fs -l /dev/sdaX
  • Check the parameters and information about the newly created file system.

GPT: GUID Partition Table

A good tool to use: gdisk

Traditional partition table stored in MBR has some limitationss: maximum 16 partitions and, the most important, a maximum single partition size limitation of 2TB.

To use GPT, there are some requirements:
  1. BIOS - must support EFI: Intel-based PCs should support EFI now.
  2. bootloader - must be GPT-aware: patched grub should be fine
  3. OS - must also be GPT-aware
I've tried an upgrade from MBR to GPT on Ubuntu 9.04 successfully with gdisk. However, you need to reinstall GPT-awared grub to make it boot correctly!

For the detail, please read the referenced URL.


FakeRaid HOWTO

Ref: https://help.ubuntu.com/community/FakeRaidHowto

This happens on some on-board RAID. On-board RAID often needs a software driver to work properly. Therefore, we have to setup and install the OS manually so that RAID volumes can be correctly recognized.

2009年10月11日 星期日

Windows Vista (and Windows 7): Enable administrative shares (C$, D$, ...)

To enable remote access to C$, D$, E$, etc. You have to add a registry key into system policies:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy

The type of the newly added key should be D-WORD (32-bit) value and the value should be set to 1.

To disable the shares, just remove the key or set it to zero.

Refs: