Category Archives: FreeBSD

All the stuff i run into working with BSD and Linux & share how i fixed it.

Recover MySQL password in FreeBSD and nix

This is an reminder, and saves time google’ing for the way.

Sometimes we get the question from a customer to check something in there database, noone knew there even was a root password for the database. This is a quick way to change the PW.

FreeBSD:
In the /etc/rc.conf
mysql_args=”–skip-grant-tables –skip-networking”

And restart the MySQL server. now you can login with mysql -u root -p

Change the PW:
use mysql;
UPDATE USER SET Password=PASSWORD(‘yournewpassword’) WHERE USER=’root’;
Now remove the arguments again from the rc.conf and restart. Voillia.

For linux et start the server like this:
mysqld –user=mysql –skip-grant-tables –skip-networking &

Gr gr! :)

Disable/Enable access to mailbox in vpopmail

Disable for the user $emailadres
/usr/local/vpopmail/bin/vmoduser -p -s -w -i -r $emailadress
And enable it again for $emailadres
/usr/local/vpopmail/bin/vmoduser -x $emailadress

vmoduser: usage: [options] email_addr or domain (for each user in domain)
options: -v ( display the vpopmail version number )
         -n ( don't rebuild the vpasswd.cdb file )
         -q quota ( set quota )
         -c comment (set the comment/gecos field )
         -e encrypted_passwd (set the password field )
         -C clear_text_passwd (set the password field )
the following options are bit flags in the gid int field
         -x ( clear all flags )
         -d ( don't allow user to change password )
         -p ( disable POP access )
         -s ( disable SMTP AUTH access )
         -w ( disable webmail [IMAP from localhost*] access )
            ( * full list of犀利士
 webmail server IPs in vchkpw.c )
         -i ( disable non-webmail IMAP access )
         -b ( bounce all mail )
         -o ( user is not subject to domain limits )
         -r ( disable roaming user/pop-before-smtp )
         -a ( grant qmailadmin administrator privileges )
         -S ( grant system administrator privileges - access all domains )
         -E ( grant expert privileges - edit .qmail files )
         -f ( disable spamassassin)
         -F ( delete spam)
         -m ( disable maildrop)
  [The following flags aren't used directly by vpopmail but are]
  [included for other programs that share the user database.]
         -u ( set no dialup flag )
         -0 ( set V_USER0 flag )
         -1 ( set V_USER1 flag )
         -2 ( set V_USER2 flag )
         -3 ( set V_USER3 flag )

Shared object “libz.so.5″ not found, required by “zlib.so” in Unknown on line 0

PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/gd.so’ – Shared object “libz.so.5″ not found, required by “gd.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/zip.so’ – Shared object “libz.so.5″ not found, required by “zip.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/zlib.so’ – Shared object “libz.so.5″ not found, required by “zlib.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/xml.so’ – Shared object “libz.so.5″ not found, required by “xml.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/xmlrpc.so’ – Shared object “libz.so.5″ not found, required by “xmlrpc.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/pdo_mysql.so’ – Shared object 犀利士
“libz.so.5″ not found, required by “pdo_mysql.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/dom.so’ – Shared object “libz.so.5″ not found, required by “dom.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/xmlreader.so’ – Shared object “libz.so.5″ not found, required by “xmlreader.so” in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/20060613/mysqli.so’ – Shared object “libz.so.5″ not found, required by “mysqli.so” in Unknown on line 0

Solved these errors by just making a symnlink to the never version…

[root@web9 /usr/local/etc/rc.d]# locate libz.so.5
/lib/libz.so.5
[root@web9 /usr/local/etc/rc.d]# ls -als /lib/libz.so.*
78 -r–r–r– 1 root wheel 77980 Apr 11 09:51 /lib/libz.so.6
[root@web9 /usr/local/etc/rc.d]# cd /lib/
[root@web9 /lib]# ln -s libz.so.6 libz.so.5

What u should do is just recompile all the installed software, so it links to the new libary’s

Grgr Thomas

FreeBSD shared object “libutil.so.8″ not found

Hi,

Stumbled into this problem today by doing an upgrade from 8.3 to 9.1-release-p2.

First time i ran freebsd-update it all gone well, nothing was broke, but after ur done recompiling ports and reboot the machine all sorts of software complains that it cant find the required libary.

The solution is to make a symnlink from the old to the new library:
cd /lib
ln -s libutil.so.9 libutil.so.8

Not the best solution tho, the best way is to look the specific programs that give this error and reinstall them against the new 9.x librarys.

30 day reminder certificates bash.

Like i said, im stil very new in Unix / Linux. Came up with the following to check for certificates that are gonna expire within 30 days time, it sends a mail to the chosen emailadres if u add it to the crontab.

#!/usr/local/bin/bash
# check certificate and mail output bla.
HOST=`hostname`
DOMAINS=`ls /home/vhosts/*/c犀利士
ertificates/*.crt | sed ‘s//home/vhosts/(.*)certificates/1/g’ | sed s/”//.*”/””/`

for DOMAIN in $DOMAINS
do
CERT=`ls /home/vhosts/$DOMAIN/certificates/*.crt`
for CERTS in $CERT
do
expiry=$(openssl x509 -in $CERTS -noout -enddate | cut -d’=’ -f2 | awk ‘{print $2 ” ” $1 ” ” $4}’)

Expirydate=$(date -j -f “%d %b %Y” “${expiry}” +%s)
Today=$(date +%s)
secondsToExpire=$(echo ${Expirydate} – ${Today} | bc)
daysToExpire=$(echo “${secondsToExpire} / 60 / 60 / 24” | bc)

DAYS=${daysToExpire}

if [ $DAYS -lt 30 ]
then
echo “——- Certificate check ——-” > /tmp/mailcert.txt
echo “$DOMAIN verloopt over $DAYS dagen.” > /tmp/mailcert.txt

/usr/bin/mail -s “Certificaten check $HOST” who@knows.nl < /tmp/mailcert.txt

fi
done
done

Gr gr
Thomas

Spamassasin install on qmail with qmail-scanner / tcpserver

So to install spamassasin on a freebsd server with qmail tcpserver.
This will reject in and outgoing spam or quarantine or delete it.

SpamAssassin:

/usr/ports/mail/p5-Mail-SpamAssassin
make install clean
Just say yes blabla, read before u do so.
Add to /etc/rc.conf
spamd_enable=”YES”

cp /usr/local/etc/mail/spamassassin/local.cf.sample /usr/local/etc/mail/spamassassin/local.cf

Edit:
/usr/local/etc/mail/spamassassin/local.cf
Remove the #’s before the following options
required_score 5.0 (When is it tagged as spam?)
use_bayes 1 (Autolearn)
bayes_auto_learn 1
shortcircuit BAYES_99 spam
shortcircuit BAYES_00 ham

Start spamasassin:
/usr/local/etc/rc.d/sa-spamd restart

QMAIL-SCANNER:

/usr/ports/mail/qmail-scanner
make install clean

Check if the output is blank by running this:
/usr/local/bin/qmail-scanner-queue.pl

Edit:
/usr/local/bin/qmail-scanner-queue.pl
Im not gonna go deep into clamav deamon etc. This is just to filter spam and very basic.

Search for:
my @scanners_installed=(“clamdscan_scanner”,”mhr_scanner”,”spamassassin”,”perlscan_scanner”);

Replace that with:
my @scanners_installed=(“mhr_scanner”,”spamassassin”,”perlscan_scanner”);

Trestholds in spamscores:
Search for:
my $sa_quarantine_site=’0′;
Replace that with:
my $sa_quarantine_site=’9′;

Search for:
my $sa_delete_site=’0′;
Replace that with:
my $sa_delete_site=’15’;

Search for:
my $sa_reject_site=’0′;
Replace that with:
my $sa_reject_site=’15’;

Search for:
my $sa_alt=’0′;
Replace that with:
my $sa_alt=’1′;

Copy and create new “quarantine-events.txt”:
cp /var/spool/qscand/quarantine-events.txt.sample /var/spool/qscand/quarantine-events.txt
/usr/local/bin/qmail-scanner-queue.pl -g

TCPSERVER:
Bron: https://cr.yp.to/qmail/faq/servers.html

Create this file:
/etc/tcp.smtp
Add this to the file:
127.0.0.1:allow,RELAYCLIENT=””
:allow,QMAILQUEUE=”/usr/local/bin/qmail-scanner-queue”

And run this make it a cdb file.
tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp

Qmail does not need to be re犀利士
started for this process.

STARTUP:
In the startup script i put this in, tho it would be more neat to do that otherwise.. but like i said its just fooling around and im a new to bsd :
command_args=”-d -r ${pidfile} -m 4″
its the maxium number of threads the spamd deaemon can spawn.

Cronjob:
Rotate the logfiles and update, send a mail.

Crontab:
# Spamassasin log rotate / quarantine cleanup
30 4 * * * root /home/thomas/qmscandrotate.sh

The cron itself in /home/thomas/qmscandrotate.sh:
#!/usr/local/bin/bash# Rotate spam quarantine witch are older then 7 days and have a spamscore over 9 points HOST=`hostname` /bin/rm /var/log/spamass.txt quarantine=`/usr/bin/find /var/spool/qscand/quarantine/spam/new/ -type f -mtime +7` /bin/echo “Clean spam quarantine, 7 days retention” >> /var/log/spamass.txt

/bin/echo “— $HOST —” >> /var/log/spamass.txt
for MESSAGE in $quarantine
do
/bin/echo “Cleaned up: $MESSAGE” >> /var/log/spamass.txt
/bin/rm -rf $MESSAGE
done

# the logfiles that are beeing recreated automatic after removing them
# the main logfile where u wanna look if something have happend is /var/log/maillog
/bin/echo “” >> /var/log/spamass.txt
# move log to log1 to be removed the next day
# debug logging rotate / remove
/bin/echo “Rotate logfiles:” >> /var/log/spamass.txt
/bin/rm /var/spool/qscand/qmail-queue.log1
/bin/mv /var/spool/qscand/qmail-queue.log /var/spool/qscand/qmail-queue.log1
touch /var/spool/qscand/qmail-queue.log
chown qscand:qscand /var/spool/qscand/qmail-queue.log
# quarantine logfiles rotate / remove
/bin/rm -rf /var/spool/qscand/quarantine.log1
/bin/mv /var/spool/qscand/quarantine.log /var/spool/qscand/quarantine.log1
echo “Rotation logiles in /var/spool/qscand/ done” >> /var/log/spamass.txt
touch /var/spool/qscand/quarantine.log
chown qscand:qscand /var/spool/qscand/quarantine.log
/bin/echo “” >> /var/log/spamass.txt
/bin/echo “Spamassassin updates:” >> /var/log/spamass.txt
# update spamassasin to latest ruleset put a -D after the /sa-update to see what its doing.
/usr/local/bin/sa-update -v >> /var/log/spamass.txt
/usr/local/etc/rc.d/sa-spamd restart
/bin/echo “Updates done / restart SA done” >> /var/log/spamass.txt
/usr/bin/mail -s “Spamassassin updates/maintance $HOST” who@knows.nl < /var/log/spamass.txt

Dont forget to make it executable:
chmod +x /home/thomas/qmscandrotate.sh

And like i pointed out earlyer, this works but its not the best way to do it..:)

Gr gr! :)