35 #define ADMIN_ERR_MSG_SIZE BROKER_PATH_MAX * 2 36 #define ACCESS_FILE_DELIMITER ":" 37 #define IP_FILE_DELIMITER "," 47 unsigned char *address);
61 char *access_file_name;
65 MAKE_ACL_SEM_NAME (sem_name, br_info_p->
name);
69 sprintf (admin_err_msg,
"%s: cannot initialize acl semaphore", br_info_p->
name);
75 sprintf (admin_err_msg,
"%s: cannot initialize acl semaphore", br_info_p->
name);
100 for (i = 0; i < size; i++)
102 if (strcmp (ai[i].dbname, dbname) == 0 && strcmp (ai[i].dbuser, dbuser) == 0)
115 FILE *fd_access_list;
116 int num_access_list = 0, line = 0;
119 bool is_current_broker_section;
124 fd_access_list = fopen (filename,
"r");
126 if (fd_access_list ==
NULL)
128 sprintf (admin_err_msg,
"%s: error while loading access control file(%s)", shm_appl->
broker_name, filename);
132 is_current_broker_section =
false;
134 memset (new_access_info,
'\0',
sizeof (new_access_info));
136 while (fgets (buf, 1024, fd_access_list))
141 p = strchr (buf,
'#');
154 if (is_current_broker_section ==
false && strncmp (buf,
"[%", 2) == 0 && buf[
strlen (buf) - 1] ==
']')
156 buf[
strlen (buf) - 1] =
'\0';
157 if (strcasecmp (shm_appl->
broker_name, buf + 2) == 0)
159 is_current_broker_section =
true;
163 if (is_current_broker_section ==
false)
168 if (strncmp (buf,
"[%", 2) == 0 && buf[
strlen (buf) - 1] ==
']')
170 buf[
strlen (buf) - 1] =
'\0';
171 if (strcasecmp (shm_appl->
broker_name, buf + 2) != 0)
179 sprintf (admin_err_msg,
"%s: error while loading access control file(%s)" " - max item count(%d) exceeded.",
187 sprintf (admin_err_msg,
188 "%s: error while loading access control file(%s:%d)" " - Database name is empty or too long.",
196 sprintf (admin_err_msg,
197 "%s: error while loading access control file(%s:%d)" " - Database user is empty or too long.",
205 sprintf (admin_err_msg,
206 "%s: error while loading access control file(%s:%d)" " - IP list file paths are empty.",
212 if (access_info ==
NULL)
214 access_info = &new_access_info[num_access_list];
220 if (access_info->
ip_files[0] !=
'\0')
222 strncat (access_info->
ip_files,
",", LINE_MAX - 1);
224 strncat (access_info->
ip_files, ip_file, LINE_MAX - 1);
225 for (files = ip_file;; files =
NULL)
236 "%s: error while loading access control file(%s)" " - a IP file path(%s) is too long",
250 fclose (fd_access_list);
252 #if defined (WINDOWS) 253 MAKE_ACL_SEM_NAME (acl_sem_name, shm_appl->
broker_name);
259 memcpy (shm_appl->
access_info, new_access_info, sizeof (new_access_info));
272 fclose (fd_access_list);
293 #if !defined(CAS_FOR_ORACLE) && !defined(CAS_FOR_MYSQL) 310 fd_ip_list = fopen (filename,
"r");
312 if (fd_ip_list ==
NULL)
314 sprintf (admin_err_msg,
"Could not open ip info file(%s)", filename);
318 buf[LINE_MAX - 2] = 0;
319 while (fgets (buf, LINE_MAX, fd_ip_list))
325 if (buf[LINE_MAX - 2] != 0 && buf[LINE_MAX - 2] !=
'\n')
327 sprintf (admin_err_msg,
"Error while loading ip info file(%s)" " - %d line is too long", filename, ln);
331 p = strchr (buf,
'#');
345 sprintf (admin_err_msg,
"Error while loading ip info file(%s) line(%d)" " - max ip count(%d) exceeded.",
350 token = strtok_r (buf,
".", &save);
353 for (i = 0; i < 4; i++)
357 sprintf (admin_err_msg,
"Error while loading ip info file(%s) line(%d)", filename, ln);
361 if (strcmp (token,
"*") == 0)
371 if (result != 0 || adr > 255 || adr < 0)
373 sprintf (admin_err_msg,
"Error while loading ip info file(%s) line(%d)", filename, ln);
377 ip_info->
address_list[address_index + 1 +
i] = (
unsigned char) adr;
380 token = strtok_r (
NULL,
".", &save);
381 if (i == 3 && token !=
NULL)
383 sprintf (admin_err_msg,
"Error while loading ip info file(%s) line(%d)", filename, ln);
405 #if defined (WINDOWS) 408 MAKE_ACL_SEM_NAME (acl_sem_name, shm_as_p->
broker_name);
413 memcpy (access_info, shm_as_p->
access_info, sizeof (access_info));
416 #if defined (WINDOWS) 432 bool local_ip_flag =
false;
434 if (address[0] == 127 && address[1] == 0 && address[2] == 0 && address[3] == 1)
436 local_ip_flag =
true;
439 address_ptr = strchr (dbname,
'@');
440 if (address_ptr !=
NULL)
447 if ((strcmp (access_info[i].dbname,
"*") == 0
449 && (strcmp (access_info[i].dbuser,
"*") == 0
458 if (local_ip_flag ==
true 466 if (address_ptr !=
NULL)
471 if (local_ip_flag ==
true)
484 assert (ip_info && address);
486 for (i = 0; i < ip_info->
num_list; i++)
497 ((
void *) &ip_info->
address_list[address_index + 1], (
void *) address,
511 #if defined (WINDOWS) 518 #if defined (WINDOWS) 519 MAKE_ACL_SEM_NAME (acl_sem_name, shm_as_p->
broker_name);
525 #if defined (WINDOWS) unsigned char address_list[ACL_MAX_IP_COUNT *IP_BYTE_COUNT]
int access_control_read_config_file(T_SHM_APPL_SERVER *shm_appl, char *filename, char *admin_err_msg)
unsigned char local_ip_addr[4]
int parse_int(int *ret_p, const char *str_p, int base)
#define MAKE_FILEPATH(dest, src, dest_len)
int access_control_check_right(T_SHM_APPL_SERVER *shm_as_p, char *dbname, char *dbuser, unsigned char *address)
static T_BROKER_INFO * br_info_p
int uw_sem_post(sem_t *sem)
int uw_sem_init(sem_t *sem)
ACCESS_INFO access_info[ACL_MAX_ITEM_COUNT]
unsigned char my_ip_addr[4]
ACCESS_INFO access_info[ACL_MAX_ITEM_COUNT]
char broker_name[BROKER_NAME_LEN]
int access_control_set_shm(T_SHM_APPL_SERVER *shm_as_p, T_BROKER_INFO *br_info_p, T_SHM_BROKER *shm_br, char *admin_err_msg)
static void access_control_repath_file(char *path)
static int access_control_check_right_internal(T_SHM_APPL_SERVER *shm_as_p, char *dbname, char *dbuser, unsigned char *address)
#define ACL_MAX_DBNAME_LENGTH
static int access_control_read_ip_info(IP_INFO *ip_info, char *filename, char *admin_err_msg)
#define IP_FILE_DELIMITER
#define ACCESS_FILE_DELIMITER
static int access_control_check_ip(T_SHM_APPL_SERVER *shm_as_p, IP_INFO *ip_info, unsigned char *address, int info_index)
static T_SHM_APPL_SERVER * shm_appl
#define ACL_MAX_ITEM_COUNT
static T_SHM_BROKER * shm_br
char admin_err_msg[ADMIN_ERR_MSG_SIZE]
static void error(const char *msg)
#define ACL_MAX_DBUSER_LENGTH
char dbname[ACL_MAX_DBNAME_LENGTH]
static ACCESS_INFO * access_control_find_access_info(ACCESS_INFO ai[], int size, char *dbname, char *dbuser)
char name[BROKER_NAME_LEN]
#define ADMIN_ERR_MSG_SIZE
int uw_sem_wait(sem_t *sem)
void set_cubrid_file(T_CUBRID_FILE_ID fid, char *value)
char * get_cubrid_file_ptr(T_CUBRID_FILE_ID fid)
T_SHM_APPL_SERVER * shm_as_p
char dbuser[ACL_MAX_DBUSER_LENGTH]
char access_control_file[SHM_BROKER_PATH_MAX]
time_t last_access_time[ACL_MAX_IP_COUNT]
char ip_files[LINE_MAX+1]
static int record_ip_access_time(T_SHM_APPL_SERVER *shm_as_p, int info_index, int list_index)
char * envvar_confdir_file(char *path, size_t size, const char *filename)