dazukoio.h File Reference

Go to the source code of this file.

Defines

#define DAZUKO_ON_OPEN   1
#define DAZUKO_ON_CLOSE   2
#define DAZUKO_ON_EXEC   4
#define DAZUKO_ON_CLOSE_MODIFIED   8
#define DAZUKO_ON_UNLINK   16
#define DAZUKO_ON_RMDIR   32

Typedefs

typedef dazuko_id dazuko_id_t

Functions

int dazukoRegister (const char *groupName, const char *mode)
int dazukoSetAccessMask (unsigned long accessMask)
int dazukoAddIncludePath (const char *path)
int dazukoAddExcludePath (const char *path)
int dazukoRemoveAllPaths (void)
int dazukoGetAccess (struct dazuko_access **acc)
int dazukoReturnAccess (struct dazuko_access **acc)
int dazukoUnregister (void)
int dazukoRegister_TS (dazuko_id_t **dazuko, const char *groupName, const char *mode)
int dazukoSetAccessMask_TS (dazuko_id_t *dazuko, unsigned long accessMask)
int dazukoAddIncludePath_TS (dazuko_id_t *dazuko, const char *path)
int dazukoAddExcludePath_TS (dazuko_id_t *dazuko, const char *path)
int dazukoRemoveAllPaths_TS (dazuko_id_t *dazuko)
int dazukoGetAccess_TS (dazuko_id_t *dazuko, struct dazuko_access **acc)
int dazukoReturnAccess_TS (dazuko_id_t *dazuko, struct dazuko_access **acc)
int dazukoUnregister_TS (dazuko_id_t **dazuko)


Define Documentation

#define DAZUKO_ON_CLOSE   2
 

Definition at line 40 of file dazukoio.h.

#define DAZUKO_ON_CLOSE_MODIFIED   8
 

Definition at line 42 of file dazukoio.h.

#define DAZUKO_ON_EXEC   4
 

Definition at line 41 of file dazukoio.h.

#define DAZUKO_ON_OPEN   1
 

Definition at line 39 of file dazukoio.h.

#define DAZUKO_ON_RMDIR   32
 

Definition at line 44 of file dazukoio.h.

#define DAZUKO_ON_UNLINK   16
 

Definition at line 43 of file dazukoio.h.


Typedef Documentation

typedef struct dazuko_id dazuko_id_t
 

Definition at line 74 of file dazukoio.h.


Function Documentation

int dazukoAddExcludePath const char *  path  ) 
 

Definition at line 701 of file dazukoio_core.c.

References dazukoAddExcludePath_TS().

00702 {
00703         return dazukoAddExcludePath_TS(_GLOBAL_DAZUKO, path);
00704 }

int dazukoAddExcludePath_TS dazuko_id_t dazuko,
const char *  path
 

Definition at line 706 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, ADD_EXCLUDE_PATH, dazuko_set_path(), and dazukoAddExcludePath_TS_compat1().

Referenced by dazukoAddExcludePath().

00707 {
00708 #if !defined(NO_COMPAT1)
00709         if (_GLOBAL_DAZUKO_COMPAT1)
00710                 return dazukoAddExcludePath_TS_compat1(dazuko_id, path);
00711 #endif
00712 
00713         return dazuko_set_path(dazuko_id, path, ADD_EXCLUDE_PATH);
00714 }

int dazukoAddIncludePath const char *  path  ) 
 

Definition at line 686 of file dazukoio_core.c.

References dazukoAddIncludePath_TS().

00687 {
00688         return dazukoAddIncludePath_TS(_GLOBAL_DAZUKO, path);
00689 }

int dazukoAddIncludePath_TS dazuko_id_t dazuko,
const char *  path
 

Definition at line 691 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, ADD_INCLUDE_PATH, dazuko_set_path(), and dazukoAddIncludePath_TS_compat1().

Referenced by dazukoAddIncludePath().

00692 {
00693 #if !defined(NO_COMPAT1)
00694         if (_GLOBAL_DAZUKO_COMPAT1)
00695                 return dazukoAddIncludePath_TS_compat1(dazuko_id, path);
00696 #endif
00697 
00698         return dazuko_set_path(dazuko_id, path, ADD_INCLUDE_PATH);
00699 }

int dazukoGetAccess struct dazuko_access **  acc  ) 
 

Definition at line 764 of file dazukoio_core.c.

References dazukoGetAccess_TS().

00765 {
00766         return dazukoGetAccess_TS(_GLOBAL_DAZUKO, acc);
00767 }

int dazukoGetAccess_TS dazuko_id_t dazuko,
struct dazuko_access **  acc
 

Definition at line 769 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, DAZUKO_FILENAME_MAX_LENGTH, dazuko_get_value(), dazukoGetAccess_TS_compat1_wrapper(), dazukoReturnAccess_TS_compat1_wrapper(), dazuko_access::event, dazuko_access::file_device, dazuko_access::file_gid, dazuko_access::file_mode, dazuko_access::file_size, dazuko_access::file_uid, dazuko_access::filename, dazuko_access::flags, free_request(), GET_AN_ACCESS, dazuko_id::id, ITOA_SIZE, dazuko_access::mode, NULL, dazuko_access::pid, process_request(), dazuko_request::reply_buffer, dazuko_request::reply_buffer_size_used, dazuko_access::set_event, dazuko_access::set_file_device, dazuko_access::set_file_gid, dazuko_access::set_file_mode, dazuko_access::set_file_size, dazuko_access::set_file_uid, dazuko_access::set_filename, dazuko_access::set_flags, dazuko_access::set_mode, dazuko_access::set_pid, dazuko_access::set_uid, dazuko_access::uid, unescape_string(), and xp_verify_id().

Referenced by dazukoGetAccess().

00770 {
00771         struct dazuko_request   *request;
00772         struct dazuko_access    *temp_acc;
00773         size_t                  size;
00774         size_t                  filename_size;
00775         char                    buffer[ITOA_SIZE];
00776 #if !defined(NO_COMPAT1)
00777         int                     compat1_ret;
00778 #endif
00779 
00780         if (dazuko_id == NULL)
00781                 return -1;
00782 
00783 #if !defined(NO_COMPAT1)
00784         if (_GLOBAL_DAZUKO_COMPAT1)
00785         {
00786                 compat1_ret = dazukoGetAccess_TS_compat1_wrapper(dazuko_id, acc);
00787 
00788                 if (compat1_ret == 0 && !(dazuko_id->write_mode))
00789                 {
00790                         /* we are in read_only mode so we return the access immediately */
00791 
00792                         dazukoReturnAccess_TS_compat1_wrapper(dazuko_id, acc, 1, 0);
00793 
00794                         /* this could be dangerous, we do not check if the return was successfull! */
00795                 }
00796 
00797                 return compat1_ret;
00798         }
00799 #endif
00800 
00801         if (dazuko_id->id < 0)
00802                 return -1;
00803 
00804         if (xp_verify_id(dazuko_id) != 0)
00805                 return -1;
00806 
00807         if (acc == NULL)
00808                 return -1;
00809 
00810         size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00811                 + 1 /* \0 */
00812                 ;
00813 
00814         request = alloc_request(GET_AN_ACCESS, size,
00815                 1 + 2 + 1 + DAZUKO_FILENAME_MAX_LENGTH /* \nFN=filename */
00816                 + 1024 /* miscellaneous access attributes */
00817                 + 1 /* \0 */
00818                 );
00819         if (request == NULL)
00820                 return -1;
00821 
00822         snprintf(request->buffer, size, "\nID=%d", dazuko_id->id);
00823         request->buffer[size - 1] = 0;
00824         request->buffer_size = strlen(request->buffer) + 1;
00825 
00826         temp_acc = (struct dazuko_access *)malloc(sizeof(struct dazuko_access));
00827         if (temp_acc == NULL)
00828         {
00829                 free_request(&request);
00830                 return -1;
00831         }
00832 
00833         memset(temp_acc, 0, sizeof(struct dazuko_access));
00834 
00835         filename_size = DAZUKO_FILENAME_MAX_LENGTH + 1;
00836         temp_acc->filename = (char *)malloc(filename_size);
00837         if (temp_acc->filename == NULL)
00838         {
00839                 free(temp_acc);
00840                 free_request(&request);
00841                 return -1;
00842         }
00843 
00844         if (process_request(dazuko_id, buffer, sizeof(buffer), request, 1) != 0)
00845         {
00846                 free(temp_acc->filename);
00847                 free(temp_acc);
00848                 free_request(&request);
00849                 return -1;
00850         }
00851 
00852         if (request->reply_buffer_size_used > 0)
00853         {
00854                 if (dazuko_get_value("\nFN=", request->reply_buffer, temp_acc->filename, filename_size) == 0)
00855                 {
00856                         temp_acc->set_filename = 1;
00857                         unescape_string(temp_acc->filename);
00858                 }
00859 
00860                 if (dazuko_get_value("\nEV=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00861                 {
00862                         temp_acc->event = atoi(buffer);
00863                         temp_acc->set_event = 1;
00864                 }
00865 
00866                 if (dazuko_get_value("\nFL=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00867                 {
00868                         temp_acc->flags = atoi(buffer);
00869                         temp_acc->set_flags = 1;
00870                 }
00871 
00872                 if (dazuko_get_value("\nMD=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00873                 {
00874                         temp_acc->mode = atoi(buffer);
00875                         temp_acc->set_mode = 1;
00876                 }
00877 
00878                 if (dazuko_get_value("\nUI=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00879                 {
00880                         temp_acc->uid = atoi(buffer);
00881                         temp_acc->set_uid = 1;
00882                 }
00883 
00884                 if (dazuko_get_value("\nPI=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00885                 {
00886                         temp_acc->pid = atoi(buffer);
00887                         temp_acc->set_pid = 1;
00888                 }
00889 
00890                 if (dazuko_get_value("\nFS=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00891                 {
00892                         temp_acc->file_size = atol(buffer);
00893                         temp_acc->set_file_size = 1;
00894                 }
00895 
00896                 if (dazuko_get_value("\nFU=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00897                 {
00898                         temp_acc->file_uid = atoi(buffer);
00899                         temp_acc->set_file_uid = 1;
00900                 }
00901 
00902                 if (dazuko_get_value("\nFG=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00903                 {
00904                         temp_acc->file_gid = atoi(buffer);
00905                         temp_acc->set_file_gid = 1;
00906                 }
00907 
00908                 if (dazuko_get_value("\nDT=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00909                 {
00910                         temp_acc->file_device = atoi(buffer);
00911                         temp_acc->set_file_device = 1;
00912                 }
00913 
00914                 if (dazuko_get_value("\nFM=", request->reply_buffer, buffer, sizeof(buffer)) == 0)
00915                 {
00916                         temp_acc->file_mode = atoi(buffer);
00917                         temp_acc->set_file_mode = 1;
00918                 }
00919         }
00920 
00921         free_request(&request);
00922 
00923         *acc = temp_acc;
00924 
00925         return 0;
00926 }

int dazukoRegister const char *  groupName,
const char *  mode
 

Definition at line 258 of file dazukoio_core.c.

References dazukoRegister_TS().

00259 {
00260         return dazukoRegister_TS(&_GLOBAL_DAZUKO, groupName, mode);
00261 }

int dazukoRegister_TS dazuko_id_t **  dazuko,
const char *  groupName,
const char *  mode
 

Definition at line 546 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, _GLOBAL_WITH_DEVWRITE, _GLOBAL_WITH_REQSTREAM, and dazukoRegister_TS_inner().

Referenced by dazukoRegister().

00547 {
00548         int     rc;
00549 
00550         /* prep: enable highest available mode */
00551         _GLOBAL_WITH_REQSTREAM = 1;
00552 
00553         _GLOBAL_WITH_DEVWRITE = 0;
00554 #if !defined(NO_COMPAT1)
00555         _GLOBAL_DAZUKO_COMPAT1 = 0;
00556 #endif
00557 
00558         /* try to register until success or methods are exhausted */
00559         while (1)
00560         {
00561                 /* stop if we succeeded to register */
00562                 rc = dazukoRegister_TS_inner(dazuko_id, groupName, mode);
00563                 if (rc == 0)
00564                         break;
00565 
00566                 /* try to fallback if possible */
00567 
00568                 if (_GLOBAL_WITH_REQSTREAM)
00569                 {
00570                         /* the "ra=" method failed, fallback to "RA=" */
00571 
00572                         _GLOBAL_WITH_REQSTREAM = 0;
00573                         _GLOBAL_WITH_DEVWRITE = 1;
00574                         continue;
00575                 }
00576 
00577 #if !defined(NO_COMPAT1)
00578                 if (_GLOBAL_WITH_DEVWRITE)
00579                 {
00580                         /* the "RA=" method failed, fallback to compat1 */
00581 
00582                         _GLOBAL_WITH_DEVWRITE = 0;
00583                         _GLOBAL_DAZUKO_COMPAT1 = 1;
00584                         continue;
00585                 }
00586 #endif
00587 
00588                 /* we ran out of alternatives, return with an error */
00589                 break;
00590         }
00591 
00592         return rc;
00593 }

int dazukoRemoveAllPaths void   ) 
 

Definition at line 716 of file dazukoio_core.c.

References dazukoRemoveAllPaths_TS().

00717 {
00718         return dazukoRemoveAllPaths_TS(_GLOBAL_DAZUKO);
00719 }

int dazukoRemoveAllPaths_TS dazuko_id_t dazuko  ) 
 

Definition at line 721 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoRemoveAllPaths_TS_compat1(), free_request(), ITOA_SIZE, NULL, process_request(), REMOVE_ALL_PATHS, and xp_verify_id().

Referenced by dazukoRemoveAllPaths().

00722 {
00723         struct dazuko_request   *request;
00724         size_t                  size;
00725         char                    buffer[ITOA_SIZE];
00726 
00727         if (dazuko_id == NULL)
00728                 return -1;
00729 
00730 #if !defined(NO_COMPAT1)
00731         if (_GLOBAL_DAZUKO_COMPAT1)
00732                 return dazukoRemoveAllPaths_TS_compat1(dazuko_id);
00733 #endif
00734 
00735         if (dazuko_id->id < 0)
00736                 return -1;
00737 
00738         if (xp_verify_id(dazuko_id) != 0)
00739                 return -1;
00740 
00741         size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00742                 + 1 /* \0 */
00743                 ;
00744 
00745         request = alloc_request(REMOVE_ALL_PATHS, size, 0);
00746         if (request == NULL)
00747                 return -1;
00748 
00749         snprintf(request->buffer, size, "\nID=%d", dazuko_id->id);
00750         request->buffer[size - 1] = 0;
00751         request->buffer_size = strlen(request->buffer) + 1;
00752 
00753         if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
00754         {
00755                 free_request(&request);
00756                 return -1;
00757         }
00758 
00759         free_request(&request);
00760 
00761         return 0;
00762 }

int dazukoReturnAccess struct dazuko_access **  acc  ) 
 

Definition at line 928 of file dazukoio_core.c.

References dazukoReturnAccess_TS().

00929 {
00930         return dazukoReturnAccess_TS(_GLOBAL_DAZUKO, acc);
00931 }

int dazukoReturnAccess_TS dazuko_id_t dazuko,
struct dazuko_access **  acc
 

Definition at line 933 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoReturnAccess_TS_compat1_wrapper(), free_request(), ITOA_SIZE, NULL, process_request(), RETURN_AN_ACCESS, and xp_verify_id().

Referenced by dazukoReturnAccess().

00934 {
00935         struct dazuko_request   *request;
00936         size_t                  size;
00937         char                    buffer[ITOA_SIZE];
00938 
00939         if (dazuko_id == NULL)
00940                 return -1;
00941 
00942 #if !defined(NO_COMPAT1)
00943         if (_GLOBAL_DAZUKO_COMPAT1)
00944                 return dazukoReturnAccess_TS_compat1_wrapper(dazuko_id, acc, dazuko_id->write_mode, 1);
00945 #endif
00946 
00947         if (dazuko_id->id < 0)
00948                 return -1;
00949 
00950         if (xp_verify_id(dazuko_id) != 0)
00951                 return -1;
00952 
00953         if (acc == NULL)
00954                 return -1;
00955 
00956         if (*acc == NULL)
00957                 return -1;
00958 
00959         if (dazuko_id->write_mode)
00960         {
00961                 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00962                         + 1 + 2 + 1 + ITOA_SIZE /* \nDN=deny */
00963                         + 1 /* \0 */
00964                         ;
00965 
00966                 request = alloc_request(RETURN_AN_ACCESS, size, 0);
00967                 if (request == NULL)
00968                         return -1;
00969 
00970                 snprintf(request->buffer, size, "\nID=%d\nDN=%d", dazuko_id->id, (*acc)->deny == 0 ? 0 : 1);
00971                 request->buffer[size - 1] = 0;
00972                 request->buffer_size = strlen(request->buffer) + 1;
00973 
00974                 if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
00975                 {
00976                         /* there could be big problems if this happens */
00977 
00978                         if ((*acc)->filename != NULL)
00979                                 free((*acc)->filename);
00980                         free(*acc);
00981                         *acc = NULL;
00982                         free_request(&request);
00983                         return -1;
00984                 }
00985 
00986                 free_request(&request);
00987         }
00988 
00989         if ((*acc)->filename != NULL)
00990                 free((*acc)->filename);
00991         free(*acc);
00992         *acc = NULL;
00993 
00994         return 0;
00995 }

int dazukoSetAccessMask unsigned long  accessMask  ) 
 

Definition at line 595 of file dazukoio_core.c.

References dazukoSetAccessMask_TS().

00596 {
00597         return dazukoSetAccessMask_TS(_GLOBAL_DAZUKO, accessMask);
00598 }

int dazukoSetAccessMask_TS dazuko_id_t dazuko,
unsigned long  accessMask
 

Definition at line 600 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoSetAccessMask_TS_compat1(), free_request(), ITOA_SIZE, NULL, process_request(), SET_ACCESS_MASK, and xp_verify_id().

Referenced by dazukoSetAccessMask().

00601 {
00602         struct dazuko_request   *request;
00603         size_t                  size;
00604         char                    buffer[ITOA_SIZE];
00605 
00606         if (dazuko_id == NULL)
00607                 return -1;
00608 
00609 #if !defined(NO_COMPAT1)
00610         if (_GLOBAL_DAZUKO_COMPAT1)
00611                 return dazukoSetAccessMask_TS_compat1(dazuko_id, accessMask);
00612 #endif
00613 
00614         if (dazuko_id->id < 0)
00615                 return -1;
00616 
00617         if (xp_verify_id(dazuko_id) != 0)
00618                 return -1;
00619 
00620         size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
00621                 + 1 + 2 + 1 + ITOA_SIZE /* \nAM=accessMask */
00622                 + 1 /* \0 */
00623                 ;
00624 
00625         request = alloc_request(SET_ACCESS_MASK, size, 0);
00626         if (request == NULL)
00627                 return -1;
00628 
00629         snprintf(request->buffer, size, "\nID=%d\nAM=%lu", dazuko_id->id, accessMask);
00630         request->buffer[size - 1] = 0;
00631         request->buffer_size = strlen(request->buffer) + 1;
00632 
00633         if (process_request(dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
00634         {
00635                 free_request(&request);
00636                 return -1;
00637         }
00638 
00639         free_request(&request);
00640 
00641         return 0;
00642 }

int dazukoUnregister void   ) 
 

Definition at line 997 of file dazukoio_core.c.

References dazukoUnregister_TS().

00998 {
00999         return dazukoUnregister_TS(&_GLOBAL_DAZUKO);
01000 }

int dazukoUnregister_TS dazuko_id_t **  dazuko  ) 
 

Definition at line 1002 of file dazukoio_core.c.

References _GLOBAL_DAZUKO_COMPAT1, alloc_request(), dazuko_request::buffer, dazuko_request::buffer_size, dazukoUnregister_TS_compat1_wrapper(), free_request(), ITOA_SIZE, NULL, process_request(), UNREGISTER, xp_connection_close(), and xp_verify_id().

Referenced by dazukoUnregister().

01003 {
01004         struct dazuko_request   *request;
01005         size_t                  size;
01006         char                    buffer[ITOA_SIZE];
01007         int                     error = 0;
01008 
01009         if (dazuko_id == NULL)
01010                 return -1;
01011 
01012 #if !defined(NO_COMPAT1)
01013         if (_GLOBAL_DAZUKO_COMPAT1)
01014                 return dazukoUnregister_TS_compat1_wrapper(dazuko_id);
01015 #endif
01016 
01017         if (*dazuko_id == NULL)
01018                 return -1;
01019 
01020         if (xp_verify_id(*dazuko_id) == 0)
01021         {
01022                 size = 1 + 2 + 1 + ITOA_SIZE /* \nID=id */
01023                         + 1 /* \0 */
01024                         ;
01025 
01026                 request = alloc_request(UNREGISTER, size, 0);
01027                 if (request == NULL)
01028                         return -1;
01029 
01030                 snprintf(request->buffer, size, "\nID=%d", (*dazuko_id)->id);
01031                 request->buffer[size - 1] = 0;
01032                 request->buffer_size = strlen(request->buffer) + 1;
01033 
01034                 if (process_request(*dazuko_id, buffer, sizeof(buffer), request, 0) != 0)
01035                 {
01036                         /* there could be big problems if this happens */
01037 
01038                         error = -1;
01039                 }
01040 
01041                 free_request(&request);
01042         }
01043 
01044         xp_connection_close(*dazuko_id);
01045         free(*dazuko_id);
01046         *dazuko_id = NULL;
01047 
01048         return error;
01049 }


Generated on Sun May 21 14:31:02 2006 for RSBAC by  doxygen 1.4.2