components/openscap/patches/zz_oval_fts.c.patch
changeset 6294 ff05e37b1eac
parent 6122 aacbdaa3a38b
equal deleted inserted replaced
6293:f3245760f53f 6294:ff05e37b1eac
     1 This patch fixes the issue with using the private
     1 --- openscap-1.2.9/src/OVAL/probes/oval_fts.c.~1~	2016-04-21 04:51:58.300491814 -0700
     2 interfaces from libzonecfg and avl.h and use the
     2 +++ openscap-1.2.9/src/OVAL/probes/oval_fts.c	2016-06-08 12:59:52.982814231 -0700
     3 rad interfaces to obtain the zonepath information.
     3 @@ -45,8 +45,9 @@
     4 This patch has not been contribute upstream.
       
     5 --- openscap-1.2.6/src/OVAL/probes/oval_fts.c.~1~	2015-10-02 08:22:02.487343649 -0700
       
     6 +++ openscap-1.2.6/src/OVAL/probes/oval_fts.c	2016-05-27 11:23:22.612830759 -0700
       
     7 @@ -45,14 +45,16 @@
       
     8  #if defined(__SVR4) && defined(__sun)
     4  #if defined(__SVR4) && defined(__sun)
     9  #include "fts_sun.h"
     5  #include "fts_sun.h"
    10  #include <sys/mntent.h>
     6  #include <sys/mntent.h>
    11 -#include <libzonecfg.h>
     7 -#include <libzonecfg.h>
    12 -#include <sys/avl.h>
     8 -#include <sys/avl.h>
    14 +#include <rad/radclient_basetypes.h>
    10 +#include <rad/radclient_basetypes.h>
    15 +#include <rad/client/1/zonemgr.h>
    11 +#include <rad/client/1/zonemgr.h>
    16  #else
    12  #else
    17  #include <fts.h>
    13  #include <fts.h>
    18  #endif
    14  #endif
    19  
    15 @@ -137,12 +138,7 @@
    20  #undef OSCAP_FTS_DEBUG
       
    21  
       
    22 +
       
    23  static OVAL_FTS *OVAL_FTS_new()
       
    24  {
       
    25  	OVAL_FTS *ofts;
       
    26 @@ -140,12 +142,7 @@
       
    27  #ifndef MNTTYPE_PROC
    16  #ifndef MNTTYPE_PROC
    28  #define MNTTYPE_PROC	"proc"
    17  #define MNTTYPE_PROC	"proc"
    29  #endif
    18  #endif
    30 -
    19 -
    31 -typedef struct zone_path {
    20 -typedef struct zone_path {
    35 -static avl_tree_t avl_tree_list;
    24 -static avl_tree_t avl_tree_list;
    36 +char *top = NULL;
    25 +char *top = NULL;
    37  
    26  
    38  
    27  
    39  static bool valid_remote_fs(char *fstype)
    28  static bool valid_remote_fs(char *fstype)
    40 @@ -171,80 +168,124 @@
    29 @@ -168,79 +164,123 @@
    41  	return (true);
    30  	return (true);
    42  }
    31  }
    43  
    32  
    44 -/* function to compare two avl nodes in the avl tree */
    33 -/* function to compare two avl nodes in the avl tree */
    45 -static int compare_zoneroot(const void *entry1, const void *entry2)
    34 -static int compare_zoneroot(const void *entry1, const void *entry2)
    71 -	    sizeof(zone_path_t), offsetof(zone_path_t, avl_link_next));
    60 -	    sizeof(zone_path_t), offsetof(zone_path_t, avl_link_next));
    72 -	while ((name = getzoneent(cookie)) != NULL) {
    61 -	while ((name = getzoneent(cookie)) != NULL) {
    73 -		if (strcmp(name, "global") == 0)
    62 -		if (strcmp(name, "global") == 0)
    74 -			continue;
    63 -			continue;
    75 -		if (zone_get_state(name, &state_num) != Z_OK) {
    64 -		if (zone_get_state(name, &state_num) != Z_OK) {
    76 -			dE("Could not get zone state for %s\n", name);
    65 -			dE("Could not get zone state for %s", name);
    77 -			continue;
    66 -			continue;
    78 -		} else if (state_num > ZONE_STATE_CONFIGURED) {
    67 -		} else if (state_num > ZONE_STATE_CONFIGURED) {
    79 -			temp = malloc(sizeof(zone_path_t));
    68 -			temp = malloc(sizeof(zone_path_t));
    80 -			if (temp == NULL) {
    69 -			if (temp == NULL) {
    81 -				dE("Memory alloc failed\n");
    70 -				dE("Memory alloc failed");
    82 -				return(1);
    71 -				return(1);
    83 -			}
    72 -			}
    84 -			if (zone_get_zonepath(name, rpath,
    73 -			if (zone_get_zonepath(name, rpath,
    85 -			    sizeof(rpath)) != Z_OK) {
    74 -			    sizeof(rpath)) != Z_OK) {
    86 -				dE("Could not get zone path for %s\n",
    75 -				dE("Could not get zone path for %s",
    87 -				    name);
    76 -				    name);
    88 -				continue;
    77 -				continue;
    89 +        rc_conn_t *conn;
    78 -			}
    90 +        rc_err_t status;
       
    91 +        rc_instance_t *zone_inst;
       
    92 +        adr_name_t **name_list;
       
    93 +        int name_count, i, prop_count;
       
    94 +        char *zone_name;
       
    95 +        char *zone_state;
       
    96 +        zonemgr_Resource_t global = { .zr_type = "global" };
       
    97 +        zonemgr_Property_t **result;
       
    98 +        zonemgr_Result_t *error;
       
    99 +	const char *prop[] = {"zonepath"};
       
   100 +        char *zonepath;
       
   101 +        char *p;
       
   102 +	char rpath[PATH_MAX];
       
   103 +
       
   104 +        /* Connect to rad */
       
   105 +        conn = rc_connect_unix(NULL, NULL);
       
   106 +        if (conn == NULL) {
       
   107 +        	dE("Unable to connect to rad.\n");
       
   108 +        	return (1);
       
   109 +        }
       
   110 +        status = zonemgr_Zone__rad_list(conn, _B_TRUE, NS_GLOB, &name_list,
       
   111 +	    &name_count, 0);
       
   112 +        if (status != RCE_OK) {
       
   113 +		dE("Zonemgr lookup failed.\n");
       
   114 +		goto error;
       
   115 +	}
       
   116 +	if (name_count > 0) {
       
   117 +		top = calloc(name_count + 1, PATH_MAX);
       
   118 +		if (top == NULL) {
       
   119 +			dE("Memory error.\n");
       
   120 +			return (1);
       
   121 +		}
       
   122 +	}
       
   123 +	for (i = 0; i < name_count; i++) {
       
   124 +		int rc;
       
   125 +                status = rc_lookup(conn, name_list[i], NULL,  _B_TRUE,
       
   126 +                    &zone_inst);
       
   127 +                if (status != RCE_OK) {
       
   128 +                        goto error;
       
   129 +                }
       
   130 +                status = zonemgr_Zone_get_name(zone_inst, &zone_name);
       
   131 +                if (status != RCE_OK) {
       
   132 +                        goto error;
       
   133 +                }
       
   134 +                dE("zone name:%s\n", zone_name);
       
   135 +                status = zonemgr_Zone_get_state(zone_inst, &zone_state);
       
   136 +		if (status != RCE_OK) {
       
   137 +			dE("Failed to get state\n");
       
   138 +                        return(1);
       
   139 +                }
       
   140 +                dE("zone state:%s\n", zone_state);
       
   141 +                if (strcmp(zone_state, "incomplete") != 0 &&
       
   142 +                    strcmp(zone_state, "running") != 0 &&
       
   143 +                    strcmp(zone_state, "installed") != 0) {
       
   144 +			free(zone_name);
       
   145 +			free(zone_state);
       
   146 +                        continue;
       
   147 +		}
       
   148 +                status = zonemgr_Zone_getResourceProperties(zone_inst, &global,
       
   149 +                    prop, 1, &result, &prop_count, &error);
       
   150 +		if (status == RCE_SERVER_OBJECT) {
       
   151 +		    dE("error code:%d: %s\n",
       
   152 +			 error->zr_code ? *error->zr_code : 0,
       
   153 +			 error->zr_str ? error->zr_str : "");
       
   154 +		} else if (status != RCE_OK) {
       
   155 +		    dE("Internal RAD error: %s\n", rc_err_string(status));
       
   156 +		}
       
   157 +		zonepath = strdup(result[0]->zp_value);
       
   158 +		dE("zonepath :%s\n", zonepath);
       
   159 +		assert(prop_count == 1);
       
   160 +		rpath[0] = '\0';
       
   161 +		if (zonepath != NULL && strlen(zonepath) > 0 ) {
       
   162 +			if ((p = strstr(zonepath, "%{zonename}")) != NULL) {
       
   163 +				*p = '\0';
       
   164 +				snprintf(rpath, sizeof(rpath), "%s%s",zonepath,
       
   165 +				    strdup(zone_name));
       
   166 +			} else {
       
   167 +				snprintf(rpath, sizeof(rpath), "%s", zonepath);
       
   168  			}
       
   169 -			if (realpath(rpath, temp->zpath) != NULL)
    79 -			if (realpath(rpath, temp->zpath) != NULL)
   170 -				avl_add(&avl_tree_list, temp);
    80 -				avl_add(&avl_tree_list, temp);
   171 +			resolvepath(rpath, &(top[i*PATH_MAX]), ((size_t) PATH_MAX -1));
    81 -		}
   172 +			dE("zonepath after resolvepath:%s\n", &(top[i*PATH_MAX]));
    82 -	}
       
    83 -	endzoneent(cookie);
       
    84 -	return (0);
       
    85 +       rc_conn_t *conn;
       
    86 +       rc_err_t status;
       
    87 +       rc_instance_t *zone_inst;
       
    88 +       adr_name_t **name_list;
       
    89 +       int name_count, i, prop_count;
       
    90 +       char *zone_name;
       
    91 +       char *zone_state;
       
    92 +       zonemgr_Resource_t global = { .zr_type = "global" };
       
    93 +       zonemgr_Property_t **result;
       
    94 +       zonemgr_Result_t *error;
       
    95 +       const char *prop[] = {"zonepath"};
       
    96 +       char *zonepath;
       
    97 +       char *p;
       
    98 +       char rpath[PATH_MAX];
   173 +
    99 +
   174  		}
   100 +       /* Connect to rad */
   175 +		zonemgr_Result_free(error);
   101 +       conn = rc_connect_unix(NULL, NULL);
   176 +		zonemgr_Property_array_free(result, prop_count);
   102 +       if (conn == NULL) {
   177 +		free(zone_name);
   103 +              dE("Unable to connect to rad.\n");
   178 +		free(zone_state);
   104 +              return (1);
   179  	}
   105 +       }
   180 -	endzoneent(cookie);
   106 +       status = zonemgr_Zone__rad_list(conn, _B_TRUE, NS_GLOB, &name_list,
   181  	return (0);
   107 +          &name_count, 0);
       
   108 +       if (status != RCE_OK) {
       
   109 +              dE("Zonemgr lookup failed.\n");
       
   110 +              goto error;
       
   111 +      }
       
   112 +      if (name_count > 0) {
       
   113 +              top = calloc(name_count + 1, PATH_MAX);
       
   114 +              if (top == NULL) {
       
   115 +                      dE("Memory error.\n");
       
   116 +                      return (1);
       
   117 +              }
       
   118 +      }
       
   119 +      for (i = 0; i < name_count; i++) {
       
   120 +               int rc;
       
   121 +               status = rc_lookup(conn, name_list[i], NULL,  _B_TRUE,
       
   122 +                   &zone_inst);
       
   123 +               if (status != RCE_OK) {
       
   124 +                       goto error;
       
   125 +               }
       
   126 +               status = zonemgr_Zone_get_name(zone_inst, &zone_name);
       
   127 +               if (status != RCE_OK) {
       
   128 +                       goto error;
       
   129 +               }
       
   130 +               dE("zone name:%s\n", zone_name);
       
   131 +               status = zonemgr_Zone_get_state(zone_inst, &zone_state);
       
   132 +               if (status != RCE_OK) {
       
   133 +                      dE("Failed to get state\n");
       
   134 +                      return(1);
       
   135 +               }
       
   136 +              dE("zone state:%s\n", zone_state);
       
   137 +              if (strcmp(zone_state, "incomplete") != 0 &&
       
   138 +                  strcmp(zone_state, "running") != 0 &&
       
   139 +                  strcmp(zone_state, "installed") != 0) {
       
   140 +                      free(zone_name);
       
   141 +                      free(zone_state);
       
   142 +                      continue;
       
   143 +              }
       
   144 +               status = zonemgr_Zone_getResourceProperties(zone_inst, &global,
       
   145 +                   prop, 1, &result, &prop_count, &error);
       
   146 +              if (status == RCE_SERVER_OBJECT) {
       
   147 +                  dE("error code:%d: %s\n",
       
   148 +                       error->zr_code ? *error->zr_code : 0,
       
   149 +                       error->zr_str ? error->zr_str : "");
       
   150 +              } else if (status != RCE_OK) {
       
   151 +                  dE("Internal RAD error: %s\n", rc_err_string(status));
       
   152 +              }
       
   153 +              zonepath = strdup(result[0]->zp_value);
       
   154 +              dE("zonepath :%s\n", zonepath);
       
   155 +              assert(prop_count == 1);
       
   156 +              rpath[0] = '\0';
       
   157 +              if (zonepath != NULL && strlen(zonepath) > 0 ) {
       
   158 +                      if ((p = strstr(zonepath, "%{zonename}")) != NULL) {
       
   159 +                              *p = '\0';
       
   160 +                              snprintf(rpath, sizeof(rpath), "%s%s",zonepath,
       
   161 +                                  strdup(zone_name));
       
   162 +                      } else {
       
   163 +                              snprintf(rpath, sizeof(rpath), "%s", zonepath);
       
   164 +                      }
       
   165 +                      resolvepath(rpath, &(top[i*PATH_MAX]), ((size_t) PATH_MAX -1));
       
   166 +                      dE("zonepath after resolvepath:%s\n", &(top[i*PATH_MAX]));
       
   167 +              }
       
   168 +              zonemgr_Result_free(error);
       
   169 +              zonemgr_Property_array_free(result, prop_count);
       
   170 +              free(zone_name);
       
   171 +              free(zone_state);
       
   172 +        }
       
   173 +        return (0);
   182 +error:
   174 +error:
   183 +	/* disconnect from rad */
   175 +      /* disconnect from rad */
   184 +	rc_disconnect(conn);
   176 +      rc_disconnect(conn);
   185 +	return (1);
   177 +      return(1);
   186  }
   178  }
   187  
   179  
   188  static void free_zones_path_list()
   180  static void free_zones_path_list()
   189  {
   181  {
   190 -	zone_path_t *temp;
   182 -	zone_path_t *temp;
   199  
   191  
   200  static bool valid_local_zone(char *path)
   192  static bool valid_local_zone(char *path)
   201  {
   193  {
   202 -	zone_path_t temp;
   194 -	zone_path_t temp;
   203 -	avl_index_t where;
   195 -	avl_index_t where;
   204 -
   196 +      int i;
       
   197 +      char *zonepath;
       
   198  
   205 -	strlcpy(temp.zpath, path, sizeof(temp.zpath));
   199 -	strlcpy(temp.zpath, path, sizeof(temp.zpath));
   206 -	if (avl_find(&avl_tree_list, &temp, &where) != NULL)
   200 -	if (avl_find(&avl_tree_list, &temp, &where) != NULL)
   207 -		return (true);
   201 -		return (true);
   208 +	int i;
   202 +      i = 0;
   209 +	char *zonepath;
   203 +      if (top == NULL)
   210  
   204 +              return (false);
   211 +	i = 0;
   205 +      zonepath = &(top[0]);
   212 +	if (top == NULL)
   206 +      while (*zonepath != '\0') {
   213 +		return (false);
   207 +              if (strcmp(path, zonepath) == 0)
   214 +	zonepath = &(top[0]);
   208 +                      return (true);
   215 +	while (*zonepath != '\0') {
   209 +              i++;
   216 +		if (strcmp(path, zonepath) == 0)
   210 +              zonepath = &(top[i*PATH_MAX]);
   217 +			return (true);
   211 +      }
   218 +		i++;
   212  
   219 +		zonepath = &(top[i*PATH_MAX]);
       
   220 +	}
       
   221  	return (false);
   213  	return (false);
   222  }
   214  }
   223  
   215 @@ -884,7 +924,6 @@
   224 @@ -890,7 +931,6 @@
       
   225  #if defined(__SVR4) && defined(__sun)
   216  #if defined(__SVR4) && defined(__sun)
   226  	if (load_zones_path_list() != 0) {
   217  	if (load_zones_path_list() != 0) {
   227  		dE("Failed to load zones path info. Recursing non-global zones.");
   218  		dE("Failed to load zones path info. Recursing non-global zones.");
   228 -		free_zones_path_list();
   219 -		free_zones_path_list();
   229  	}
   220  	}