components/openscap/patches/smfproperty.patch
changeset 7343 a6cfc180f5e8
parent 5111 e68e059c3456
equal deleted inserted replaced
7342:3291c8473ecd 7343:a6cfc180f5e8
     1 This patch provides the implementation of the smfproperty probe
     1 This patch provides the implementation of the smfproperty probe
     2 on solaris.
     2 on solaris.
     3 This patch has not been contributed upstream but is planned to be contributed
     3 This patch has not been contributed upstream but is planned to be contributed
     4 upstream.  Hoping to have it accepted by 2015-Dec-15.
     4 upstream.  Hoping to have it accepted by 2016-Dec-15.
     5 --- openscap-1.2.1/configure.ac.~3~	2015-04-22 16:20:53.433875799 -0700
     5 --- openscap-1.2.1/configure.ac.~3~	2015-04-22 16:20:53.433875799 -0700
     6 +++ openscap-1.2.1/configure.ac	2015-04-22 16:25:56.053053597 -0700
     6 +++ openscap-1.2.1/configure.ac	2015-04-22 16:25:56.053053597 -0700
     7 @@ -257,6 +257,10 @@
     7 @@ -257,6 +257,10 @@
     8  probe_systemdunitdependency_req_deps_missing=
     8  probe_systemdunitdependency_req_deps_missing=
     9  probe_systemdunitdependency_opt_deps_ok=yes
     9  probe_systemdunitdependency_opt_deps_ok=yes
    59 +endif
    59 +endif
    60 +
    60 +
    61  endif
    61  endif
    62  
    62  
    63  #
    63  #
    64 --- openscap-1.2.3/src/OVAL/probes/unix/solaris/smfproperty.c.~1~	2015-06-02 21:28:41.068464123 -0700
    64 --- openscap-1.2.9/src/OVAL/probes/unix/solaris/smfproperty.c.~1~	2016-11-09 09:54:40.194926041 +0000
    65 +++ openscap-1.2.3/src/OVAL/probes/unix/solaris/smfproperty.c	2015-06-03 09:48:55.973035835 -0700
    65 +++ openscap-1.2.9/src/OVAL/probes/unix/solaris/smfproperty.c	2016-11-10 08:36:22.209408705 +0000
    66 @@ -0,0 +1,385 @@
    66 @@ -0,0 +1,468 @@
    67 +/**
    67 +/**
    68 + * @file smfproperty.c
    68 + * @file smfproperty.c
    69 + * @brief smfproperty probe
    69 + * @brief smfproperty probe
    70 + * @author "Jacob Varughese" <[email protected]>
    70 + * @author "Jacob Varughese" <[email protected]>
    71 + *
    71 + *
   102 +#ifndef	SCF_SNAPSHOT_RUNNING
   102 +#ifndef	SCF_SNAPSHOT_RUNNING
   103 +#define	SCF_SNAPSHOT_RUNNING	"running"
   103 +#define	SCF_SNAPSHOT_RUNNING	"running"
   104 +#endif
   104 +#endif
   105 +
   105 +
   106 +#define	MAX_SCF_VALUE_LENGTH	1024
   106 +#define	MAX_SCF_VALUE_LENGTH	1024
       
   107 +#define	STR(x)	((x == NULL) ? "" : x)
   107 +/* Convenience structure for the results being reported */
   108 +/* Convenience structure for the results being reported */
   108 +
   109 +
   109 +/*
   110 +/*
   110 + * smfproperty probe:
   111 + * smfproperty probe:
   111 + *
   112 + *
   159 +}
   160 +}
   160 +
   161 +
   161 +
   162 +
   162 +static int
   163 +static int
   163 +convert_prop(scf_handle_t *hdl, const scf_property_t *prop,
   164 +convert_prop(scf_handle_t *hdl, const scf_property_t *prop,
   164 +    struct result_info *res, probe_ctx *ctx)
   165 +    struct result_info *res)
   165 +{
   166 +{
   166 +	char propname[256];
   167 +	char propname[256];
   167 +	scf_iter_t *iter = NULL;
   168 +	scf_iter_t *iter = NULL;
   168 +	scf_value_t *value = NULL;
   169 +	scf_value_t *value = NULL;
   169 +	ssize_t size = 0, len = 0, i = 0;
   170 +	ssize_t size = 0, len = 0, i = 0;
   231 +		}
   232 +		}
   232 +		scf_value_get_as_string(value, tmp, size);
   233 +		scf_value_get_as_string(value, tmp, size);
   233 +		len += size;
   234 +		len += size;
   234 +	}
   235 +	}
   235 +	res->value = buffer;
   236 +	res->value = buffer;
   236 +	report_smfproperty(res, ctx);
       
   237 +	dI("fmri=% service=%s instance=%s property=%s value=%s\n",
       
   238 +	    res->fmri, res->service, res->instance, res->property, res->value);
       
   239 +	free(buffer);
       
   240 +	return 0;
   237 +	return 0;
       
   238 +}
       
   239 +
       
   240 +static int get_smf_nested_pg(scf_handle_t *h, scf_propertygroup_t *apg, char*aprop_name, scf_propertygroup_t **appg, char**app_prop)
       
   241 +{
       
   242 +        char *propgrp;
       
   243 +        char *prop;
       
   244 +        char props[2048];
       
   245 +	 static int count = 0;
       
   246 +
       
   247 +        props[0] = '\0';
       
   248 +        snprintf(props, sizeof(props), "%s", aprop_name); 
       
   249 +	dI("In get_smf_nested_pg %s\n ", props);
       
   250 +	if ((prop = strstr(props, SCF_FMRI_NESTED_PROPERTYGRP_PREFIX)) != NULL) {
       
   251 +		scf_propertygroup_t *pg = scf_pg_create(h);
       
   252 +		*prop = '\0';
       
   253 +		prop += strlen(SCF_FMRI_NESTED_PROPERTYGRP_PREFIX);
       
   254 +		propgrp = props;
       
   255 +		dI("property-grp:%s\tproperty:%s\n", propgrp, prop);
       
   256 +		if (scf_pg_get_pg(apg, propgrp, pg) == -1 ) {
       
   257 +			dE("Error: Could not read %s/%s property group \n",
       
   258 +			    propgrp, prop);
       
   259 +                        scf_pg_destroy(pg);
       
   260 +			count = 0;
       
   261 +			return 1;
       
   262 +		} else {
       
   263 +			count++;
       
   264 +			*appg = pg;
       
   265 +			*app_prop = prop;
       
   266 +			 if (count > 1)
       
   267 +                            scf_pg_destroy(apg);
       
   268 +			return get_smf_nested_pg(h, pg, prop, appg, app_prop);
       
   269 +                }
       
   270 +        } else {
       
   271 +                *appg = apg;
       
   272 +                *app_prop = aprop_name;
       
   273 +		 count = 0;
       
   274 +                return 0;
       
   275 +        }
       
   276 +}
       
   277 +
       
   278 +static int
       
   279 +get_smf_prop_from_pg(scf_handle_t *h, scf_propertygroup_t *pg, char *prop_name, 
       
   280 + struct result_info *res)
       
   281 +{
       
   282 +	scf_propertygroup_t *apg = scf_pg_create(h);
       
   283 +	scf_property_t *prop = scf_property_create(h);
       
   284 +	int rc=0;
       
   285 +	char *aprop;
       
   286 + 
       
   287 + 	if ((rc = get_smf_nested_pg(h, pg, prop_name, &apg, &aprop)) == 0) {
       
   288 +		char grp[1024];
       
   289 +		dI("prop_name:%s\n", aprop);
       
   290 +		if (scf_pg_get_name(apg, grp, sizeof(grp)) > 0)
       
   291 +			dI("prop_grp_name:%s\n", grp);
       
   292 +		if (scf_pg_get_property(apg, aprop, prop) == -1 ) {
       
   293 +			dE("Error: Could not read %s property %s\n",
       
   294 +		                prop_name, res->fmri);
       
   295 +			rc = 1;
       
   296 +			goto cleanup;
       
   297 +		} else {
       
   298 +			rc = convert_prop(h, prop, res);
       
   299 +                }
       
   300 +	}
       
   301 +cleanup:
       
   302 +	scf_property_destroy(prop);
       
   303 +	if (apg != pg)
       
   304 +		scf_pg_destroy(apg);
       
   305 +	return rc;
   241 +}
   306 +}
   242 +
   307 +
   243 +static int
   308 +static int
   244 +get_smf_prop(scf_handle_t *h, const scf_service_t *service,
   309 +get_smf_prop(scf_handle_t *h, const scf_service_t *service,
   245 +    const scf_instance_t *instance, const char *prop_grp_name,
   310 +    const scf_instance_t *instance, const char *prop_grp_name,
   246 +    const char *prop_name, struct result_info *res, probe_ctx *ctx)
   311 +    const char *prop_name, struct result_info *res, probe_ctx *ctx)
   247 +{
   312 +{
   248 +	scf_propertygroup_t *pg = scf_pg_create(h);
   313 +	scf_propertygroup_t *pg = scf_pg_create(h);
   249 +	scf_property_t *prop = scf_property_create(h);
   314 +	scf_property_t *prop = scf_property_create(h);
   250 +	int rc;
   315 +	int rc = 0;
   251 +
   316 +
   252 +	if (pg == NULL) {
   317 +	if (pg == NULL) {
   253 +		dE("Unable to create property group from handle.\n");
   318 +		dE("Unable to create property group from handle.\n");
   254 +		dE("prop_grp_name=%s prop_name=%s.\n",
   319 +		dE("prop_grp_name=%s prop_name=%s.\n",
   255 +		    prop_grp_name, prop_name);
   320 +		    prop_grp_name, prop_name);
   294 +		if (scf_instance_get_pg_composed(instance, snap,
   359 +		if (scf_instance_get_pg_composed(instance, snap,
   295 +		    prop_grp_name, pg) == -1) {
   360 +		    prop_grp_name, pg) == -1) {
   296 +			dE("Error: Could not read "
   361 +			dE("Error: Could not read "
   297 +			    " %s/%s property from snapshot for %s\n",
   362 +			    " %s/%s property from snapshot for %s\n",
   298 +			    prop_grp_name, prop_name, res->fmri);
   363 +			    prop_grp_name, prop_name, res->fmri);
       
   364 +			if (scf_instance_get_pg_composed(instance, NULL,
       
   365 +                            prop_grp_name, pg) == -1) {
       
   366 +                                dE( "Error: Could not read "
       
   367 +                                    " %s/%s property for %s\n",
       
   368 +                                    prop_grp_name, prop_name, res->fmri);
       
   369 +                                goto cleanup;
       
   370 +                        }
       
   371 +
       
   372 +		}
       
   373 +		scf_snapshot_destroy(snap);
       
   374 +	}
       
   375 + 	if ((rc = get_smf_prop_from_pg(h, pg, prop_name, res)) != 0) {
       
   376 +		if (scf_instance_get_pg_composed(instance, NULL, prop_grp_name,
       
   377 +		    pg) == -1) {
       
   378 +			printf(
       
   379 +			    "Error: Could not read "
       
   380 +			    " %s/%s property for %s\n",
       
   381 +			    prop_grp_name,
       
   382 +			    prop_name, res->fmri);
   299 +			rc = 1;
   383 +			rc = 1;
   300 +			scf_snapshot_destroy(snap);
       
   301 +			goto cleanup;
   384 +			goto cleanup;
   302 +		}
   385 +		}
   303 +		scf_snapshot_destroy(snap);
   386 +		rc = get_smf_prop_from_pg(h, pg, prop_name, res);
   304 +	}
   387 +	}
   305 +	if (scf_pg_get_property(pg, prop_name, prop) == -1) {
       
   306 +		dE("Error: Could not read %s/%s property %s\n",
       
   307 +		    prop_grp_name, prop_name, res->fmri);
       
   308 +		rc = 1;
       
   309 +		goto cleanup;
       
   310 +	}
       
   311 +	rc = convert_prop(h, prop, res, ctx);
       
   312 +cleanup:
   388 +cleanup:
   313 +	scf_property_destroy(prop);
   389 +	scf_property_destroy(prop);
   314 +	scf_pg_destroy(pg);
   390 +	scf_pg_destroy(pg);
   315 +	return rc;
   391 +	return rc;
   316 +}
   392 +}
   355 +	}
   431 +	}
   356 +
   432 +
   357 +	tmp = strdup_check(aprop);
   433 +	tmp = strdup_check(aprop);
   358 +	if ((p = strstr(tmp, SCF_FMRI_PROPERTY_PREFIX)) != NULL) {
   434 +	if ((p = strstr(tmp, SCF_FMRI_PROPERTY_PREFIX)) != NULL) {
   359 +		*p = '\0';
   435 +		*p = '\0';
   360 +		p++;
   436 +		p +=  strlen(SCF_FMRI_PROPERTY_PREFIX);
   361 +		prop = p;
   437 +		prop = p;
   362 +	}
   438 +	}
   363 +	propgrp = tmp;
   439 +	propgrp = tmp;
   364 +	dI("r.service_name=%s\n", r.service);
   440 +	dI("r.service_name=%s\n", r.service);
   365 +	dI("service:%s instance:%s propgrp:%s prop:%s\n",
   441 +	dI("service:%s instance:%s propgrp:%s prop:%s\n",
   366 +	    STR(asvc), STR(ainst), STR(propgrp), STR(prop));
   442 +	    STR(asvc), STR(ainst), STR(propgrp), STR(prop));
   367 +	r.instance = ainst;
   443 +	r.instance = ainst;
   368 +	r.property = aprop;
   444 +	r.property = aprop;
   369 +	if (get_smf_prop(scf_hdl, svc, inst, propgrp, prop, &r, ctx) > 0) {
   445 +	if (get_smf_prop(scf_hdl, svc, inst, propgrp, prop, &r, ctx) > 0) {
   370 +		r.fmri = NULL;
   446 +		r.value = "";
       
   447 +               probe_cobj_set_flag(probe_ctx_getresult(ctx), SYSCHAR_FLAG_NOT_APPLICABLE);
   371 +		dE("get_smf_prop failed.\n");
   448 +		dE("get_smf_prop failed.\n");
   372 +	}
   449 +	}
       
   450 +	report_smfproperty(&r, ctx);
       
   451 +	dI("fmri=%s service=%s instance=%s property=%s value=%s\n",
       
   452 +	    STR(r.fmri), STR(r.service), STR(r.instance), STR(r.property),
       
   453 +	    STR(r.value));
       
   454 +        if (r.value != NULL && strlen(r.value) > 0)
       
   455 +	    free(r.value);
   373 +	dI("Service exists:%s\n", r.service);
   456 +	dI("Service exists:%s\n", r.service);
   374 +cleanup:
   457 +cleanup:
   375 +	free(tmp);
   458 +	free(tmp);
   376 +	free(r.fmri);
   459 +	free(r.fmri);
       
   460 +	scf_handle_unbind(scf_hdl);
   377 +	scf_handle_destroy(scf_hdl);
   461 +	scf_handle_destroy(scf_hdl);
   378 +	scf_handle_unbind(scf_hdl);
       
   379 +	scf_service_destroy(svc);
   462 +	scf_service_destroy(svc);
   380 +	scf_instance_destroy(inst);
   463 +	scf_instance_destroy(inst);
   381 +	return rc;
   464 +	return rc;
   382 +}
   465 +}
   383 +
   466 +
   447 +probe_main(probe_ctx *ctx, void *probe_arg)
   530 +probe_main(probe_ctx *ctx, void *probe_arg)
   448 +{
   531 +{
   449 +	return PROBE_EOPNOTSUPP;
   532 +	return PROBE_EOPNOTSUPP;
   450 +}
   533 +}
   451 +#endif
   534 +#endif
   452 --- openscap-1.2.3/src/OVAL/probes/unix/solaris/smfproperty.c.~2~	2015-11-10 10:00:28.564892744 -0800
       
   453 +++ openscap-1.2.3/src/OVAL/probes/unix/solaris/smfproperty.c	2015-11-10 10:03:34.496610180 -0800
       
   454 @@ -38,6 +38,7 @@
       
   455  #endif
       
   456  
       
   457  #define	MAX_SCF_VALUE_LENGTH	1024
       
   458 +#define	STR(x)	((x == NULL) ? "" : x)
       
   459  /* Convenience structure for the results being reported */
       
   460  
       
   461  /*