A bit about

Hello, everyone! All you can see below is just my bank of information. Some material I've found in the fathomless net, some I've learned myself. Don't think all of the information here is right or actual, but may be it could be of use for you :) All feedback is welcome, especially constructive ones :)

Friday, September 30, 2011

BASH: check new line at end of file

Sometimes it's useful to check if a file had newline at the end. For example, if there're lots of C source code (compiler shows warning if no newline found) or file is going to be processed by "cat filename | while read;" construction. The last one will not read the bottom line of the file.

I found several answers in Google, they used "sed" or "tail -n 1", but didn't work me.

I used the following construction:
if [ -s filename -a "$(tail -c 1 filename)" = "" ]; then
echo "Has newline";
echo "No newline";

Friday, August 19, 2011

Samba: no password access

Probably I'm a newbie to SMB protocol and Samba server, but it turns to be a problem to organize a comfortable access to Samba server.

What I mean comfortable? Ok, to me it's, for example, several directories which can be accessed without prompting for username or password (irritating one as soon as you want to organize media share free for all) and several directories which require authentication.

In this post it seemed that I resolved my problems by setting "security = share" in Samba server access, but then I found several things about this:

+ yes, it allows one to browse server directories and access public ones without password

- it doesn't provide True authentication. According to Samba's documentation for secured shares, it just receives password from client (ignoring username) and then tries to compare this password against users which are allowed to access that share. From my perspective, it's not fully secure

- strange, but I only succeeded in authentication from Windows. If only I tried to use Dolphin, Konqueror or even smbclient, I always got "NT_STATUS_WRONG_PASSWORD". I haven't succeeded in googling and troubleshooting this issue.

So, "security = share" doesn't seem to be a solution. On the other hand, if I apply "security = user", Windows clients always ask for password even if I try to access public shares (which would allow even without providing one).

I was able to find a "magic spell" here:
security = user
map to guest = Bad Password
guest account = guest

After that, both Linux and Windows clients (even consoles like IconBit) were able to authenticate correctly.

So, finally steps which were done (I assume here that system users "guest", "user1" and "user2" are available in the server system):

1) Add Samba users and set the same passwords as system ones:
# smbpasswd -a user1
# smbpasswd -a user2
# smbpasswd -a guest

Leave blank password for "guest" account. If any account already exists, just remove it with "smbpasswd -x ". Just to be sure.

2) Create several test shares and assign full access to them (or at least for those users, which are supposed to access these shares):
# mkdir -p /shares/public
# mkdir -p /shares/share1
# mkdir -p /shares/share2
# chmod 777 /shares/public
# chmod 777 /shares/share1
# chmod 777 /shares/share2

3) Put the following configuration into your [global] section of smb.conf:
workgroup = workgroup
server string = %h server
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0

security = user
map to guest = Bad Password
guest account = guest

encrypt password = true
passbd backend = tdbsam
obey pam restrictions = no
invalid users = root
unix password sync = yes
domain logons = no

Fields decorated with "####" are the most important ones. Other fields can be changed depending on system's security and other requirements.

4) Configure you shares the following way:
comment = Public Staff
path = /shares/public
guest ok = yes
writable = yes
browseable = yes
valid users =

comment = Share for user1
path = /shares/share1
guest ok = no
writable = yes
browseable = yes
valid users = user1

comment = Share for user2
path = /shares/share2
guest ok = no
writable = yes
browseable = yes
valid users = user2

5) Finally, restart your Samba server. In my Debian it's "/etc/init.d/samba restart"

Now all clients should be able to list shares on this server and access "public" directory without prompting password. At the same time, in order to access share1, user must be authenticated with "user1" and his password (similar way for share2).

The only problem I had is accessing from Windows XP. Originally it authenticated as "guest" and was able to access public, but when I tried to access "share1", it didn't prompt for password, but instead showed me a message saying that access is denied.

In log files of Samba server I could see that Windows XP still tries to authenticate with "guest". So, it seems to be a problem of Windows XP which doesn't close session and doesn't prompt for password within one session. It seems to me that reboot could fix this problem.

Anyway, this also look like a bug in SMB protocol. It says that upon establishing connection, server just tell the client its security level ('share', 'user', etc.) and then it's up to client - how and when to ask for password. Windows XP as usually does it wrong :)

Sunday, May 1, 2011

mencoder: convert DVD to mp4

Found a command to convert movie to mp4 here and slightly modified it in order to capture DVD from hard drive:
mencoder dvd://2 -dvd-device /home/username/Secret/VIDEO_TS -o secret.mp4 -vf dsize=480:352:2,scale=-8:-8,harddup -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ovc x264 -sws 9 -x264encopts nocabac:level_idc=30:bframes=0:bitrate=512:threads=auto:turbo=1:global_header:threads=auto:subq=5:frameref=6:partitions=all:trellis=1:chroma_me:me=umh

Saturday, April 30, 2011

Mencoder: 1 duplicate frame(s)

Trying to convert DVD Video from hard drive to .avi file by means of mencoder I received a lot of messages like "1 duplicate frame(s)". As result, my there was problem with sound sync in the produced avi file. I used this command:
mencoder dvd://2 -dvd-device /home/Secret/VIDEO_TS -o secret.avi -oac copy -ovc copy
One of the solution proposed by post author here worked for me. I changed audio codec and everything went ok:
mencoder dvd://2 -dvd-device /home/Secret/VIDEO_TS -o secret.avi -oac mp3lame -ovc copy
May be not a universal solution, but definitely something to try working on the problem

Sunday, February 6, 2011

Russian layout in Wine applications

I've tried to solve this problem for a long time. The problem is that in applications executed be means of Wine I can't type in russian layout. Existing text is shown correctly, but as soon as I switch to russian symbols don't appear while I type.

I googled a lot, and saw a lot of different tips about solutions of this problem. Some people say that creating a symlink (ln -s /usr/share/X11/locale/en_US.UTF-8 /usr/share/X11/locale/ru_RU.UTF-8) worked in their case. Other said that copying of TTF fonts from Windows solved the problem. Even export LC_ALL=ru_RU.UTF-8 insted of LC_ALL=ru_RU.utf8 worked in one particular case.

But all of these solutions didn't work for me and I think that there is no universal solution for this problem.

I finally solved it on my computer and the reason was that my LC_ALL variable wasn't set and even when I tried to set it, I always used forms of LC_ALL=ru_RU{...}. Accidentally I tried (just for fun) export LC_ALL=en_US.UTF-8 and somehow it did the trick.

Thursday, December 9, 2010

Windows 7: Arrows on shortcuts

There are 2 problems in one:

  • Big ugly arrows on shortcuts in Windows 7
  • Appending of "Link for" to all newly created shortcuts
Both of them are solved by simply correcting 2 values in Windows registry and adding a new file to a system.

New file is a blank icon (which probably can be created manualy, but I've downloaded it from here). This file, called for example blank.ico, should be put into %systemroot%. Now let's tweak the registry.

To disable arrows, create a key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Icons] and add parameter with RG_EXPAND_SZ type:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Icons]

To disable "link for", set:

I tested it on my Windows 7. I'm not sure, but probably this solution also applies for other versions of Windows.

Friday, September 3, 2010

Man: specify the page to browse

It's just a small notice which can be found in man help. The reason I wrote this post is that it was not evident for me and I spent some time to pick this information from man man.

So, the task is to open a particular man page instead of default one. It can be found in man man:
-S section_list
List is a colon separated list of manual sections to search. This option overrides the MANSECT environment variable.

I used to say "man page" speaking about page numbers, but they call it sections. So, to open the 3rd page for syslog:
man -S syslog
By default, it usually opens syslog(2)