1
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
Type "copyright", "credits" or "license" for more information.

IPython 2.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: ls -l
total 8
-rwxrwxrwx 1 root root 6144 Jul  8 18:01 root.db*

In [2]: import os,sqlite3,pwd

In [3]: os.getresuid()
Out[3]: (0, 0, 0)

In [4]: pwd.getpwuid(1001)
Out[4]: pwd.struct_passwd(pw_name='testac', pw_passwd='x', pw_uid=1001, pw_gid=1001, pw_gecos='', pw_dir='/home/testac', pw_shell='')

In [5]: os.seteuid(1001)

In [6]: db = sqlite3.connect('root.db')

In [7]: db.execute("Create table A ( test text )")
---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
<ipython-input-7-5236fe81d6c5> in <module>()
----> 1 db.execute("Create table A ( test text )")

OperationalError: unable to open database file

Above is an example of my problem.

I have a sqlite3 database that everyone can read and write. As you can see, My python is run under root. Then I set the effective user to a normal user. Then I open the sqlite3 database. It will say unable to open database.

Why I cannot open that database ? thanks .

gvolt
  • 21
  • 2

0 Answers0