martes, 20 de diciembre de 2011

Using sqlite from the command line

Show and format the sql expression:
sqlite3 -separator ' ' test.db "select * from users where username='admin'" |awk {'print "username: " $1 "\npassword: " $2 '}

Insert data:
sqlite3 test.db "insert into users values ('user2','user2','test2')"
echo $?

if exit status equals zero means that everything run smoothly

martes, 22 de noviembre de 2011

using shell scripting with mysql
echo "select * from users" |mysql  myride --skip-column-names|awk {'print $1'}

Creating a HashBang wrapper

Some time ago I needed an executable that was able to call SQL sentences with mysql or sqlite. I did a little research to understand how Shebang works, I found out that was very easy to write your custom wrappers

wrapper :: /bin/bmysql
#!/bin/bash
export database=$1
#echo "Database:: $1| SQL: $2"
#echo $1 holds the file where sql data is stored

export sql_data=`cat $2|grep -v \"#!\"`
#echo "DEBUG:: $sql_data "
echo $sql_data|mysql $1
echo $?

and the script file /home/test/demo.sql

#!/bin/bmysql drupal
show databases;
Have fun with your own wrappers!!!

lunes, 4 de julio de 2011

Creating Jail for users

First: directory structure

You have to build your own custom jailed filesystem. Mine was on /var/cage:
./
.script.rc  bin  config  lib64  spool

./bin:
.lsd  bash  cat  init.rc  ls  sqlite3 echo 

./config:
current

./lib64:
ld-linux-x86-64.so.2  libc.so.6        libpthread.so.0   libselinux.so.1
libacl.so.1           libdl.so.2       libreadline.so.5  libsqlite3.so.0
libattr.so.1          libncurses.so.5  librt.so.1

./spool:
commands

Second. Creating a custom console.

This script will force that instead of creating a custom shell, the user will be jailed after login:

cp /usr/bin/chroot /usr/bin/rooted
chmod u+s /usr/bin/rooted

User is created on /home/jailed:
.profile must conatain the following line:
exec /usr/bin/rooted /var/cage /bin/init.rc


Adendum. /bin/init.rc

/bin/bash --init-file /.script.rc

Using sudo without password

Hi all!!!
Do you ever wanted to grant "root" priviledges to a user without having to type the root password?
I needed to have a user capable of performing "admin" tasks at same level as "root". In order to get things done,  I created a user called admin, member of group "users" with password locked (passwd -l admin). This step is important, because it means that no one except root will be able to access the account.
To grant "admin" unlimited access without password, i had to type sudo and include at the end the following line:

admin ALL=(ALL) NOPASSWD: ALL


Have a nice day!!! : )