[Fwd: libsemanage API]
-------- Original Message --------
Subject: libsemanage API
Date: Fri, 06 Jul 2007 10:59:23 -0400
From: Joe Rocklin <[email protected]>
To: [email protected]
Hi Dan,
I'm trying to use the API to libsemanage from C++, and I'm running into some difficulties finding relevant documentation on the subject. If you could point me in the right direction, I'd really appreciate it!
The issue I'm having is with trying to work with the return results from semanage_user_list. The struct defines for semanage_user_t (as well as semanage_user_base_t and semanage_user_extra_t) are in the .c files, not the header files, which causes a compile to fail with the following error:
setest.cpp:19: error: request for member ‘name’ in ‘*(((semanage_user_t**)(((unsigned int)i) * 4u)) + list)’, which is of non-class type ‘semanage_user_t*’
I've attached the small program used to test this. If I run this in ddd and display the variable list[0].name it correctly displays the contents. I believe the issue is that the compiler isn't aware of the struct definition, which isn't presented until the link phase.
Is there another way of accessing this data? Or is the correct answer to move the struct definitions into the header files?
--Joe
extern "C" {
#include <semanage/semanage.h>
}#include <iostream>
using namespace std;
int main (int argc, char **argv) {
semanage_handle_t *sh = semanage_handle_create();
semanage_user_t **list;
unsigned int count;
semanage_connect(sh);
semanage_user_list(sh, &list, &count);
for (int i = 0; i < count; i++) {
cout << i << ": " << list[i].name << endl;
}
return 0;
}extern "C" {
#include <semanage/semanage.h>
#include <semanage/user_record.h>
}#include <iostream>
using namespace std;
int main (int argc, char **argv) {
semanage_handle_t *sh = semanage_handle_create();
semanage_user_t **list;
unsigned int count;
semanage_connect(sh);
semanage_user_list(sh, &list, &count);
for (int i = 0; i < count; i++) {
cout << i << ": " << semanage_user_get_name(list[i])
<< endl;
}
return 0;
}sudo ./a.out
Password:
0: root
1: staff_u
2: sysadm_u
3: system_u
4: user_u
Quoted 8 lines · Daniel J Walsh
extern "C" { #include <semanage/semanage.h> }#include <iostream>
using namespace std;
int main (int argc, char **argv) {
Quoted 15 lines
semanage_handle_t *sh = semanage_handle_create();
semanage_user_t **list;
unsigned int count;
semanage_connect(sh);
semanage_user_list(sh, &list, &count);
for (int i = 0; i < count; i++) {
cout << i << ": " << list[i].name << endl;
}
return 0;
}--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.