Esempio n. 1
0
int main (int argc, char *argv[])
{
    int ch;
    const char *type = NULL;
    const char *directory = NULL;
    const char *key;
    flux_t *h;

    log_init ("getas");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 't': /* --type TYPE  */
                type = optarg;
                break;
            case 'd': /* --directory DIR */
                directory = optarg;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind != argc - 1)
        usage ();
    key = argv[optind++];

    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    if (directory)
        dirgetas (h, directory, key, type);
    else
        getas (h, key, type);
    flux_close (h);
}
Esempio n. 2
0
/*
 * This routine will update the in-house information using the data
 * read from license file.
 */
void
update_lic_info(lic_data_t *data, bool daemon)
{
	void		*p, *p1;
	struct timespec abstime;
	double		exptime;
	char		*prod;
	char		*maj = NULL;
	lic_type	type = 0;
	lic_inst_type inst_type = 0;

	clock_gettime(CLOCK_REALTIME, &abstime);

	/*
	 * If we couldn't read license details due to internall error, say
	 * insufficient memory, let us not fail or decide license status.
	 * Instead, read the license details again as soon as possible.
	 */
	ld_state = data->fld_state;
	if (daemon && (data->fld_state == LS_INTERNAL_ERR)) {
		ld_valid = true;
		adjust_chk_prd(-1);
		if (is_btree_loaded()) {
			ext_cbs->zs_lic_cb((ld_valid == true) ? 1 : 0);
		}
		return;
	}

	/*
	 * Only if license is valid or expired, let us check whether the license
	 * is for ZS. Else, let us mark the license as invalid and fail the
	 * application.
	 */
	if ((ld_state == LS_VALID) || (ld_state == LS_EXPIRED)) {
		// We always expect license type and product to be set.
		p = getptr(data, LDI_LIC_TYPE);
		plat_assert(p);
		if (p) {
			type = getas(p, lic_type);
		} else {
			ld_state = LS_INVALID;
			goto print;
		}

		p = getptr(data, LDI_INST_TYPE);
		plat_assert(p);
		if (p) {
			inst_type = getas(p, lic_inst_type);
		} else {
			ld_state = LS_INVALID;
			goto print;
		}

		p = getptr(data, LDI_PROD_NAME);
		plat_assert(p);
		if (p) {
			prod = getasstr(p);
			p1 = getptr(data, LDI_PROD_MAJ);
			if (p1) {
				maj = getasstr(p1);
			}
			/*
			 * If product matches, check whether the version
			 * matches. If both, then this is a valid license.
			 */
			if ( (!strcmp(prod, ZS_PRODUCT_NAME)) || (!strcmp(prod, "Flash Data Fabric")) ) {
#ifdef ZS_REVISION
				if (p1) {
					if (strncmp(p1, "all", strlen(p1))) {
						char	*tmp;
						if (!zs_version) {
							zs_version = malloc(strlen(ZS_REVISION) + 1);
						}

						if (zs_version) {
							bzero(zs_version, strlen(ZS_REVISION) + 1);
							strncpy(zs_version, ZS_REVISION, strlen(ZS_REVISION));
							tmp = strstr(zs_version, ".");

							if (tmp) {
								int len = tmp - zs_version;
								if (len) {
									if (strncmp(zs_version, maj, len)){
										ld_state = LS_VER_MISMATCH;
									}
								} else {
									if (strncmp(zs_version, maj, strlen(zs_version))){
										ld_state = LS_VER_MISMATCH;
									}
								}
							}
						} else {
							plat_log_msg(160256, LOG_CAT, LOG_WARN,
									"Internal error, skipped version check");
						}
					}
				} else {
					ld_state = LS_PROD_MISMATCH;
				}
#endif
			} else {
				ld_state = LS_PROD_MISMATCH;
			}
		} else {
			ld_state = LS_INVALID;
		}

		//If license is valid, update ld_vtime with current time.
		if (ld_state == LS_VALID) {
			ld_vtime = abstime.tv_sec;
		}
	}

	/*
	 * Print any info/warning messages based on status of license.
	 */
print:
	ld_cktime = abstime.tv_sec; 

	if (ld_state == LS_VALID) {
		// Print any warning, if we are near to expiry.
		check_validity_left(data, inst_type, type, daemon);
	} else if (ld_state == LS_EXPIRED) {
		// If license has expired, then it has to be periodic.
		plat_assert(type != LPT_PERPETUAL);
		if (daemon) {
			plat_log_msg(160155, LOG_CAT, LOG_WARN, 
				"License has expired. Renew the license.");
		}
		p = getptr(data, LDI_DIFF_TO);
		plat_assert(p);
		if (p) {
			exptime = getas(p, double);
			plat_assert(exptime < 0);
			exptime = -exptime;

			//Get the grce period of license file supports
			//Print warning & find period we need to make next check
			p = getptr(data, LDI_GRACE_PRD);
			if (p) {
				check_time_left(exptime, getas(p, double), daemon);
			} else {
				check_time_left(exptime, ZS_EXP_GPRD, daemon);
			}
		}
	} else {