1*99ebb4caSwyllys /* 2*99ebb4caSwyllys * CDDL HEADER START 3*99ebb4caSwyllys * 4*99ebb4caSwyllys * The contents of this file are subject to the terms of the 5*99ebb4caSwyllys * Common Development and Distribution License (the "License"). 6*99ebb4caSwyllys * You may not use this file except in compliance with the License. 7*99ebb4caSwyllys * 8*99ebb4caSwyllys * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*99ebb4caSwyllys * or http://www.opensolaris.org/os/licensing. 10*99ebb4caSwyllys * See the License for the specific language governing permissions 11*99ebb4caSwyllys * and limitations under the License. 12*99ebb4caSwyllys * 13*99ebb4caSwyllys * When distributing Covered Code, include this CDDL HEADER in each 14*99ebb4caSwyllys * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*99ebb4caSwyllys * If applicable, add the following below this CDDL HEADER, with the 16*99ebb4caSwyllys * fields enclosed by brackets "[]" replaced with your own identifying 17*99ebb4caSwyllys * information: Portions Copyright [yyyy] [name of copyright owner] 18*99ebb4caSwyllys * 19*99ebb4caSwyllys * CDDL HEADER END 20*99ebb4caSwyllys */ 21*99ebb4caSwyllys /* 22*99ebb4caSwyllys * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*99ebb4caSwyllys * Use is subject to license terms. 24*99ebb4caSwyllys */ 25*99ebb4caSwyllys 26*99ebb4caSwyllys #pragma ident "%Z%%M% %I% %E% SMI" 27*99ebb4caSwyllys 28*99ebb4caSwyllys #include <cryptoutil.h> 29*99ebb4caSwyllys #include <strings.h> 30*99ebb4caSwyllys #include <stdio.h> 31*99ebb4caSwyllys #include <tzfile.h> 32*99ebb4caSwyllys 33*99ebb4caSwyllys /* 34*99ebb4caSwyllys * This function returns a fullpath based on the "dir" and "filepath" input 35*99ebb4caSwyllys * arugments. 36*99ebb4caSwyllys * - If the filepath specified does not start with a "/" and the directory 37*99ebb4caSwyllys * is also given, prepend the directory to the filename. 38*99ebb4caSwyllys * - If only dir or filepath is given, this function returns a copy of the 39*99ebb4caSwyllys * given argument. 40*99ebb4caSwyllys * - If the filepath is fully qualified already and the "dir" is also 41*99ebb4caSwyllys * given, return NULL to indicate an error. 42*99ebb4caSwyllys */ 43*99ebb4caSwyllys char * 44*99ebb4caSwyllys get_fullpath(char *dir, char *filepath) 45*99ebb4caSwyllys { 46*99ebb4caSwyllys char *fullpath = NULL; 47*99ebb4caSwyllys int pathlen = 0; 48*99ebb4caSwyllys int dirlen = 0; 49*99ebb4caSwyllys 50*99ebb4caSwyllys if (filepath != NULL) 51*99ebb4caSwyllys pathlen = strlen(filepath); 52*99ebb4caSwyllys 53*99ebb4caSwyllys if (dir != NULL) 54*99ebb4caSwyllys dirlen = strlen(dir); 55*99ebb4caSwyllys 56*99ebb4caSwyllys if (pathlen > 0 && dirlen > 0) { 57*99ebb4caSwyllys if (filepath[0] != '/') { 58*99ebb4caSwyllys int len = pathlen + dirlen + 2; 59*99ebb4caSwyllys fullpath = (char *)malloc(len); 60*99ebb4caSwyllys if (fullpath != NULL) 61*99ebb4caSwyllys (void) snprintf(fullpath, len, "%s/%s", 62*99ebb4caSwyllys dir, filepath); 63*99ebb4caSwyllys } else { 64*99ebb4caSwyllys return (NULL); 65*99ebb4caSwyllys } 66*99ebb4caSwyllys } else if (pathlen > 0) { 67*99ebb4caSwyllys fullpath = (char *)strdup(filepath); 68*99ebb4caSwyllys } else if (dirlen > 0) { 69*99ebb4caSwyllys fullpath = (char *)strdup(dir); 70*99ebb4caSwyllys } 71*99ebb4caSwyllys 72*99ebb4caSwyllys return (fullpath); 73*99ebb4caSwyllys } 74*99ebb4caSwyllys 75*99ebb4caSwyllys /* 76*99ebb4caSwyllys * This function converts the input string to the value of time 77*99ebb4caSwyllys * in seconds. 78*99ebb4caSwyllys * - If the input string is NULL, return zero second. 79*99ebb4caSwyllys * - The input string needs to be in the form of: 80*99ebb4caSwyllys * number-second(s), number-minute(s), number-hour(s) or 81*99ebb4caSwyllys * number-day(s). 82*99ebb4caSwyllys */ 83*99ebb4caSwyllys int 84*99ebb4caSwyllys str2lifetime(char *ltimestr, uint32_t *ltime) 85*99ebb4caSwyllys { 86*99ebb4caSwyllys int num; 87*99ebb4caSwyllys char timetok[10]; 88*99ebb4caSwyllys 89*99ebb4caSwyllys if (ltimestr == NULL || !strlen(ltimestr)) { 90*99ebb4caSwyllys *ltime = 0; 91*99ebb4caSwyllys return (0); 92*99ebb4caSwyllys } 93*99ebb4caSwyllys 94*99ebb4caSwyllys (void) memset(timetok, 0, sizeof (timetok)); 95*99ebb4caSwyllys if (sscanf(ltimestr, "%d-%08s", &num, timetok) != 2) 96*99ebb4caSwyllys return (-1); 97*99ebb4caSwyllys 98*99ebb4caSwyllys if (!strcasecmp(timetok, "second") || 99*99ebb4caSwyllys !strcasecmp(timetok, "seconds")) { 100*99ebb4caSwyllys *ltime = num; 101*99ebb4caSwyllys } else if (!strcasecmp(timetok, "minute") || 102*99ebb4caSwyllys !strcasecmp(timetok, "minutes")) { 103*99ebb4caSwyllys *ltime = num * SECSPERMIN; 104*99ebb4caSwyllys } else if (!strcasecmp(timetok, "day") || 105*99ebb4caSwyllys !strcasecmp(timetok, "days")) { 106*99ebb4caSwyllys *ltime = num * SECSPERDAY; 107*99ebb4caSwyllys } else if (!strcasecmp(timetok, "hour") || 108*99ebb4caSwyllys !strcasecmp(timetok, "hours")) { 109*99ebb4caSwyllys *ltime = num * SECSPERHOUR; 110*99ebb4caSwyllys } else { 111*99ebb4caSwyllys *ltime = 0; 112*99ebb4caSwyllys return (-1); 113*99ebb4caSwyllys } 114*99ebb4caSwyllys 115*99ebb4caSwyllys return (0); 116*99ebb4caSwyllys } 117