Skip to content

Instantly share code, notes, and snippets.

View ychaouche's full-sized avatar

Yassine Chaouche ychaouche

View GitHub Profile
-*-outline-*-
(best viewed in emacs with outline-mode)
* by name
** apparmor
*** intro
Some processes are monitored by AppArmor and their actions can be restricted to their AppArmor profile.
For example : access to certain paths, or execution of certain commands, or certain kernel capabilities.
If the profile doesn't allow, the user gets a permission denied.
Example : tcpdump can't read or write files not ending with .pcap.
archive.create.tgz is a function
archive.create.tgz ()
{
local dir="$1";
local archivename="$dir.tgz";
shift;
echo tar --exclude=*~ $@ -cvzf $archivename $dir;
tar --exclude=*~ $@ -cvzf $archivename $dir
}
archive.create.zip is a function
#!/bin/bash
# 10:32:01 ~ -1- $ net.translate "j'ai pas envie de me prendre la tête avec unicode"
# I don't want to bother with unicode.
# 10:32:23 ~ -1- $
while (( $# ))
do
case "$1" in
$ python3.6 -c 'import sys; print(ascii(sys.argv[1]))"réussi à"'
Unable to decode the command from the command line:
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 39-40: surrogates not allowed
$
>>> with open('/dev/stdout','wb') as faowb: faowb.write(s.encode('UTF-8')+b'\n')
...
49
j'ai réussi à écrire une version plus concise
>>>
17:55:58 ~/CODE/TEST/PYTHON -1- $ LD_LIBRARY_PATH=/snap/core18/current/lib/x86_64-linux-gnu/ /snap/core18/current/lib64/ld-linux-x86-64.so.2 /snap/core18/current/usr/bin/python3.6
Python 3.6.9 (default, Mar 10 2023, 16:46:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s="j'ai réussi à écrire une version plus concise"
>>> print(s)
j'ai réussi à écrire une version plus concise
>>> print(s.encode('UTF-8'))
b"j'ai r\xc3\xa9ussi \xc3\xa0 \xc3\xa9crire une version plus concise"
>>>
$ python3.6
Python 3.6.9 (default, Mar 10 2023, 16:46:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print( "j'ai réussi à écrire une version plus concise".encode('UTF-8'))
b"j'ai r\xc3\xa9ussi \xc3\xa0 \xc3\xa9crire une version plus concise"
>>>
$ python3.6 unicodepython3.6 "j'ai réussi à écrire une version plus concise"
Traceback (most recent call last):
File "unicodepython3.6", line 9, in <module>
print(f"usertext was {usertext}")
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 19-20: surrogates not allowed
$ cat unicodepython3.6
#!/usr/bin/python
import argparse
Executing database schema update.
Updating database schema (2014042900)... [OK]
Updating database schema (2015030800)... [OK]
Updating database schema (2015111100)... [OK]
Updating database schema (2016081200)... [OK]
Updating database schema (2016100900)... [OK]
Updating database schema (2016112200)... [OK]
Updating database schema (2018021600)... [OK]
Updating database schema (2018122300)... [OK]
Updating database schema (2019092900)... [OK]
root@messagerie-recup[10.10.10.20] ~ # ps axu | grep dov
root 89939 0.0 0.0 5496 904 pts/1 S+ 13:23 0:00 tail -f /var/log/dovecot.log
root 89965 0.0 0.0 8156 4492 ? Ss 13:23 0:00 /usr/sbin/dovecot -F
dovecot 89966 0.0 0.0 4744 1432 ? S 13:23 0:00 dovecot/anvil
root 89967 0.0 0.0 4880 3008 ? S 13:23 0:00 dovecot/log
root 89968 0.0 0.0 7508 4400 ? S 13:23 0:00 dovecot/config
dovecot 89971 0.0 0.0 5680 1716 ? S 13:23 0:00 dovecot/stats
root 90499 0.0 0.0 6464 2160 pts/2 S+ 14:36 0:00 grep --color --exclude=*~ dov
root@messagerie-recup[10.10.10.20] ~ #