Implement dbase_file_set, fix memleak
Changes:
- implement dbase_file_set
- fix a memory leak in dbase_file_modify that I've been trying to find - there are no more leaks that I know of
=============
I'll be really busy until the middle of next week - not sure if I can get a many patches written.
A short TODO:
- interface: pass handle into sepol records, or implement status codes
- stub: implement interface parse/print
- stub: implement dbase_policydb_list
- fix: fix port key handling of modify() [ do not replace an entire range on weak match (not exact) ]
- improvement: track when the policy is modified, and do not rebuild on commit if it wasn't modified
- add error messages everywhere (and further propagate handle), and make sure they're user-friendly
- uncomment if0-ed code, add new semanage interfaces to semanage.h, and the map file
Not important at this time:
- stub: implement dbase_policydb_del (not currently used)
- stub: implement dbase_policydb_flush (not currently used)
- fix: users parser/genusers parser should not look for range substring - that's ambiguous
- fix: seusers parser should allow multiline MLS context with whitespace
libsemanage/src/database_file.c +19 -5
@@ -388,14 +388,26 @@ static int dbase_file_set( record_key_t* key, record_t* data) { +cache_entry_t * entry; +int status; +if (enter_rw (handle, dbase) <0 ) goto err; -/* Stub */ - key =NULL ; - data =NULL ; + status =dbase_file_cache_locate (handle, dbase, key, &entry); +if (status <0 ) + goto err; +if (status ==STATUS_NODATA ) { +/* FIXME: handle error */ + goto err; + } +else { + dbase->rtable->free (entry->data); + entry->data = data; + } + dbase->modified =1 ; -return STATUS_ERR ; +return STATUS_SUCCESS ; err:/* FIXME: handle error */
@@ -422,8 +434,10 @@ static int dbase_file_modify(if (dbase_file_cache_add (dbase, data) <0 ) goto err; } -else +else { + dbase->rtable->free (entry->data); entry->data = data; + } dbase->modified =1 ;return STATUS_SUCCESS ;
Quoted 13 lines
A short TODO:
- interface: pass handle into sepol records, or implement status codes
- stub: implement interface parse/print
- stub: implementdbase_policydb_list
- fix: fix port key handling ofmodify()[ do not replace an entire range on weak match (not exact) ]
- improvement: track when the policy is modified, and do not rebuild on commit if it wasn't modified
- add error messages everywhere (and further propagate handle), and make sure they're user-friendly
- uncomment if0-ed code, add new semanage interfaces tosemanage.h, and the map file
Another TODO:
============
- investigate whether database functions should be made reentrant, exactly what kind of code can and cannot be executed in the iterate() handler, and document that - things like: are modify() functions allowed on the same database in iterate()? Other databases? queries()? Out-of-transaction vs in-transaction behavior?
--
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.
Quoted 4 lines · Ivan Gyurdiev
Changes:
- implementdbase_file_set
- fix a memory leak indbase_file_modifythat I've been trying to find - there are no more leaks that I know of
Merged both patches (query APIs, dbase_file_set) as of libsemanage 1.3.36.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
... (back on-list)
Quoted 3 lines
Conclusion:
- should be safe to uncomment all the code (in theory :)
Here... (but the other things mentioned still need to be addressed).
Changes:
- enable some things for testing: semanage users, seusers, booleans.
libsemanage/include/semanage/semanage.h +22 -0
@@ -25,4 +25,26 @@#include <semanage/modules.h> #include <semanage/debug.h> +/* Records */ +#include <semanage/boolean_record.h> +#include <semanage/user_record.h> +#include <semanage/seuser_record.h> +#if 0 +#include <semanage/iface_record.h> +#include <semanage/port_record.h> +#endif + +/* Dbase */ +#include <semanage/booleans_local.h> +#include <semanage/booleans_policy.h> +#include <semanage/users_local.h> +#include <semanage/users_policy.h> +#include <semanage/seusers.h> +#if 0 +#include <semanage/ports_local.h> +#include <semanage/ports_policy.h> +#include <semanage/interfaces_local.h> +#include <semanage/interfaces_policy.h> +#endif +#endif
libsemanage/src/direct_api.c +0 -2
@@ -349,11 +349,9 @@ static int semanage_direct_commit(semanaif (semanage_verify_kernel (sh) !=0 ) goto cleanup; -#if 0 /* Commit changes to components */ if (semanage_commit_components (sh) <0 ) goto cleanup; -#endif retval =semanage_install_sandbox (sh);
libsemanage/src/libsemanage.map +1 -0
@@ -9,5 +9,6 @@ LIBSEMANAGE_1.0 { semanage_module_list_nth; semanage_module_get_name; semanage_module_get_version; semanage_select_store; semanage_reload_policy; semanage_set_reload; + semanage_user_*; semanage_bool_*; semanage_seuser_*; local: *; };
libsemanage/src/semanage_store.c +0 -2
@@ -1351,7 +1351,6 @@ int semanage_expand_sandbox(semanage_han goto cleanup; } -#if 0 dbase_policydb_attach (sh,semanage_user_dbase_policy (sh)->dbase, out);dbase_policydb_attach (sh,semanage_port_dbase_policy (sh)->dbase, out);dbase_policydb_attach (sh,semanage_iface_dbase_policy (sh)->dbase, out);
@@ -1368,7 +1367,6 @@ int semanage_expand_sandbox(semanage_hanERR (sh,"Unable to merge local modifications into policy." ); goto cleanup; } -#endif if ((kernel_filename =semanage_path (SEMANAGE_TMP ,SEMANAGE_KERNEL )) ==NULL ) { goto cleanup;