Re: Adding a 'struct' into new python type

2015-03-08 Thread Lakshmipathi.G
Hi Jason,

Thanks for the response. Okay, Will try to convert 'struct test' into
new python object (say 'PyStructTest') and include it inside
CountDictType as pyobject instead of 'struct'.
Will post details here, If i encounter any issues.

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in/readme.html


On Sat, Mar 7, 2015 at 9:23 PM, Jason Swails jason.swa...@gmail.com wrote:


 On Sat, Mar 7, 2015 at 4:15 AM, Lakshmipathi.G lakshmipath...@gmail.com
 wrote:

 Hi,

 I'm following this example :
 http://nedbatchelder.com/text/whirlext.html#h_making_a_type and trying
 to add
 new data into 'CountDict' type

 Adding a simple 'char' works well.

 typedef struct {
PyObject_HEAD
PyObject * dict;
int count;
char c;  //add this and placed an entry into PyMemberDef as T_CHAR.
 } CountDict;

 I can access  'c' from python code,no issues so far.

 Now I want to added 'struct type' into this 'CountDict' type.
 struct test {
 int x;
 };

 typedef struct {
PyObject_HEAD
PyObject * dict;
int count;
char c;
struct test t1; //?? how to add this
 } CountDict;



 How to do achieve this? (Due to legacy code dependency, I can't use
 ctype/cpython etc).
 thanks for any help/pointers.


 The way *I* would do this is turn struct test into another Python object.
 Then instead of defining it in CountDict as type struct test, define it as
 the PyStructTest that you assigned it to when you turned it into a Python
 class.

 For example, in that website you linked to, CountDict was turned into a
 CountDictType Python type.  So do something similar to test in which you
 turn it into a PyStructTest type in the same way.  Then declare it as a
 PyStructTest pointer instead of a struct test.

 I'm not sure you can get around an approach like this.  I believe that in
 order to access data from Python, it needs to be a Python type.  The
 struct-to-Python-type conversion *knows* how to translate basic types, like
 char, double, float, int, and long into their Python equivalents; but it
 can't handle something as potentially complicated as an arbitrary struct.
 Of course, if all you want to do is access t1 from C, then I think what you
 have is fine.

 Good luck,
 Jason
-- 
https://mail.python.org/mailman/listinfo/python-list


Adding a 'struct' into new python type

2015-03-07 Thread Lakshmipathi.G
Hi,

I'm following this example :
http://nedbatchelder.com/text/whirlext.html#h_making_a_type and trying
to add
new data into 'CountDict' type

Adding a simple 'char' works well.

typedef struct {
   PyObject_HEAD
   PyObject * dict;
   int count;
   char c;  //add this and placed an entry into PyMemberDef as T_CHAR.
} CountDict;

I can access  'c' from python code,no issues so far.

Now I want to added 'struct type' into this 'CountDict' type.
struct test {
int x;
};

typedef struct {
   PyObject_HEAD
   PyObject * dict;
   int count;
   char c;
   struct test t1; //?? how to add this
} CountDict;

How to do achieve this? (Due to legacy code dependency, I can't use
ctype/cpython etc).
thanks for any help/pointers.




Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in/readme.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how avoid delay while returning from C-python api?

2014-05-30 Thread Lakshmipathi.G
Yes, Cython looks easier but the problem its a very old code ( 6 or 7  years ).
Almost entire code base uses plain python-c api.


Thanks for the example, will use Cython or Ctypes way for side-projects!


Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in/readme.html
-- 
https://mail.python.org/mailman/listinfo/python-list


how avoid delay while returning from C-python api?

2014-05-28 Thread Lakshmipathi.G
Hi -

I have C-Python api like below.  It works fine, but the problem is
while invoking this method
from python script say

#cat script.py
snip
offset=0
size=4
write_object(offset,size)
/snip


This calls write_this_c() C api and returns quickly to next printf statement.
But the return call (Py_RETURN_NONE) takes something like 4-6 seconds.

-
static
PyMethodDef xyz_methods[] = {
{write_object, write_object, METH_VARARGS,write some stuff },
{NULL, NULL, 0, NULL}
};



static PyObject *
write_object(PyObject *self, PyObject *args)
{
int offset, size;
if (!PyArg_ParseTuple(args,ii, offset, size))
Py_RETURN_NONE;

printf(before call);
write_this_c(offset, size);
printf(after call);
Py_RETURN_NONE;  ##delay happens here
}

How to avoid this delay time? Thanks for any help/pointers!




Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how avoid delay while returning from C-python api?

2014-05-28 Thread Lakshmipathi.G
The statement after call printed to stdout and the script waits
there for few seconds. So I was assuming something delaying the return
value.

Just found out there is core-dump segmentation fault (core dumped)
python ..Probably fixing core dump should resolve the issue.
Thanks!


Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading c struct via python

2013-11-13 Thread Lakshmipathi.G
 Looks like your e... Is that the key field?

Yes, you are right 'e' is the key. And rest of them are data.

AND the order of the items is o before i
-- that doesn't seem to match your C struct definition.

Sorry, I was testing the bdb and while doing that I noticed,
c-struct order is not same as inserted bdb record . But forgot to
fix the struct order before posting it here.

(And also I didn't expect someone will dig this deeper on the binary
string output :p . Thanks for your effort! )


s format in which you precode the length of the string in the
format (10s is a 10 character string), and p format in which the first
byte of the string is the length (0..255) of the rest of the string. The
struct module doesn't handle C-type null terminated strings directly.

I think we can use 'p' format. (Thus storing the string-length before
actual
string content). That should help us unpack easily.

Thanks  Dennis Lee Bieber, for the detailed info and step by step parsing
of the output. It really helped.



--
 Wulfraed Dennis Lee Bieber AF6VN
 wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

 --
 https://mail.python.org/mailman/listinfo/python-list




-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
https://mail.python.org/mailman/listinfo/python-list


Reading c struct via python

2013-11-11 Thread Lakshmipathi.G
Hi -
We have C code which writes following struct into berkeley db (my_db.db).

struct my_info {
unsigned long int i, e;
int o;
char *f;
char *s;
};

How to read this via Python? Google search gave this code
---
$ cat pybsd2.py
from bsddb import db
fruitDB = db.DB()
fruitDB.open('my_db.db', None, db.DB_BTREE, db.DB_DIRTY_READ)
cursor = fruitDB.cursor()
rec = cursor.first()
while rec:
print rec
rec = cursor.next()
fruitDB.close()
---

While storing an entry (o=500,f=/home/laks/abcde,s=OSr,i=4668368
,e=1) and reading it back i get

$ python pybsd2.py
(\x10'\x00\x00\x00\x00\x00\x00,
\xf4\x01\x00\x00\xd0;G\x00\x00\x00\x00\x00\x10'\x00\x00\x00\x00\x00\x00/home/laks/abcde\x00OSr\x00)

And this http://docs.python.org/2/library/bsddb.html says bdb module is
removed  recently.

Further Searching provides modules like cpickle,ctypes,struct - not sure
which is the right approach/way to proceed.
Should we proceed with bdb module and find out how to retrive integer from
db or use others like ctypes/(c)pickle/struct etc?

Thanks for any help.

Ps : If this question already answered and discussed often, please redirect
me to that thread.

-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reg secure python environment with web terminal emulator

2013-08-08 Thread Lakshmipathi.G
 the same exploits. Think of a binary generated elsewhere (where
 gcc is available) and put into your environment.

That's pretty bad news :(


 I am convinced that 100 % security is impossible - and correspondingly
 would use a pragmatic approach: I would rely on OS level
 constraints (user with very restricted rights, process running
 in an isolated box) - and ensure the OS is kept up to date
 to reduce the risk of exploits of OS security weaknesses.


Yes,agree 100% security will never be possible. I'll explore about running
process as an isolated box. Thanks for the suggestions and inputs.



-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pexpect, loading an entry field

2013-08-07 Thread Lakshmipathi.G
Hi -
I'm using Python 2.7.3 (Fedora 17) . I tried a simple example with
pexpect to copy a file to remote system. It works

$ cat pex.py
import pexpect
s = pexpect.spawn ('scp pex.py root@10.30.77.244:/tmp')
s.expect ('Password:')
s.sendline ('a')
s.expect(pexpect.EOF,timeout=20)

Execute above program (change remote ip and password) - If it works
then its not an issue with pexpect or python
environment.


-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in



On Tue, Aug 6, 2013 at 11:33 PM, inq1ltd inq1...@inqvista.com wrote:


 pexpect looks simple to use. Please check this example


 http://www.pythonforbeginners.com/systems-programming/how-to-use-the-pexpect

 -module-in-python/

  python help;

 

  I am using pexpect to open my program.

  Can someone tell me how to get data to appear in

  an entry field.

  After pexpect opens the my program I have tried to use

  send, sendline, and write functions to try to put data into

  the program's entry field.

  However, the data is going to the terminal window,

  the window that is used to initiate the call to pexpect

  but not to the entry field in the open program.

  I would appreciate suggestions.

 

  jol

 



 Thanks for the response.



 I have been there but that site gives me

 the same information that I get from

 noah.org. I have the pexpect docs and they presume

 that this problem doesn't exist.



 None of the information in the NOAH site or the FAQ's

 address this question.



 I'm using suse linux running python 2.7 and pexpect.



 The data, when using send() method is going to the terminal window,

 This is the same window that is used to initiate the call to pexpect.



 Pexpect opens the program but the send method sends

 data to the terminal window, not the entry field located

 in the child spawned by pexpect.



 interact works, as does close(), TIMEOUT, EOF, before, after,

 expect_exact and methods. But the entry field does not

 load.



 So my question is;



 Why??









 

 

 

  --

  http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reg secure python environment with web terminal emulator

2013-08-07 Thread Lakshmipathi.G
Hi -

Thanks for the response. Yes, we used OS features to
restrict the system user accounts.

We don't allow gcc - this helped us to avoid  kernel exploits via C code like :
https://www.centos.org/modules/newbb/viewtopic.php?viewmode=flattopic_id=42827forum=59
https://bugzilla.redhat.com/show_bug.cgi?id=962792

We are concerned whether user may try C exploits via Python code and break the
system. What's the minimal python set-up you would suggest? I'm
thinking something like:

1- Uninstall python-devel packages
2- Remove easy_install or pip (any such install utilities)
3- Keep only very basic modules under /usr/lib/python/site-packages
and delete the others.

Thanks.


-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in






On Wed, Aug 7, 2013 at 11:35 AM, dieter die...@handshake.de wrote:
 Lakshmipathi.G lakshmipath...@gmail.com writes:

 We have a server running a web-based terminal emulator (based on shellinabox
 for screen-casting  check www.webminal.org) that allows users to learn
 simple bash commands. This Linux environment secured by things like quota,
 selinux,ulimit  etc

 Now some users are requesting python access. How to ensure python is executed
 in a restricted environment. I came across
 http://docs.python.org/2/library/restricted.html
 but it seems like disabled in 2.3. Any thoughts on how we can safely
 provide python access
 to users.

 When you are satisfied with the protection you have achieved
 for bash commands, those same protection might be sufficient
 for Python as well. I assume that you used operating system
 facilities to restrict what the (system) user can do on the
 operating system level: the same restriction would apply to the
 (same) user executing Python code.

 --
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reg secure python environment with web terminal emulator

2013-08-07 Thread Lakshmipathi.G
 If you permit file I/O and anything that can spawn a process, it is
 possible to create a raw binary executable and trigger its execution.
 --

Yes,we permit file i/o with quota limits and spawning a process is
allowed upto a limit.
If I'm not wrong, we will be safe if user invokes  subprocess  or
os.system('sudo') calls
due to system constraints.

Could you please share more info about creating raw binary executable
and its potential
problem.

Thanks for your response.


-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Reg secure python environment with web terminal emulator

2013-08-06 Thread Lakshmipathi.G
Hi -

We have a server running a web-based terminal emulator (based on shellinabox
for screen-casting  check www.webminal.org) that allows users to learn
simple bash commands. This Linux environment secured by things like quota,
selinux,ulimit  etc

Now some users are requesting python access. How to ensure python is executed
in a restricted environment. I came across
http://docs.python.org/2/library/restricted.html
but it seems like disabled in 2.3. Any thoughts on how we can safely
provide python access
to users.


I hope this is the correct mailing-list, If not please redirect me to
the right one.

Thanks for any help.

-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pexpect, loading an entry field

2013-08-06 Thread Lakshmipathi.G
pexpect looks simple to use. Please check this example
http://www.pythonforbeginners.com/systems-programming/how-to-use-the-pexpect-module-in-python/

-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in

On Tue, Aug 6, 2013 at 8:35 PM, inq1ltd inq1...@inqvista.com wrote:
 python help;



 I am using pexpect to open my program.

 Can someone tell me how to get data to appear in

 an entry field.



 After pexpect opens the my program I have tried to use

 send, sendline, and write functions to try to put data into

 the program's entry field.



 However, the data is going to the terminal window,

 the window that is used to initiate the call to pexpect

 but not to the entry field in the open program.



 I would appreciate suggestions.

 jol




 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list