Example #1
0
/*
 * parameters are tag value pairs. This function returns the tag or label (the
 * value before the equal size.
 */
char *
NSSUTIL_ArgGetLabel(const char *inString, int *next)
{
    char *name = NULL;
    const char *string;
    int len;

    /* look for the end of the <label>= */
    for (string = inString; *string; string++) {
        if (*string == '=') {
            break;
        }
        if (NSSUTIL_ArgIsBlank(*string))
            break;
    }

    len = string - inString;

    *next = len;
    if (*string == '=')
        (*next) += 1;
    if (len > 0) {
        name = PORT_Alloc(len + 1);
        PORT_Strncpy(name, inString, len);
        name[len] = 0;
    }
    return name;
}
Example #2
0
static char *
sftk_argGetName(char *inString, int *next) 
{
    char *name=NULL;
    char *string;
    int len;

    /* look for the end of the <name>= */
    for (string = inString;*string; string++) {
	if (*string == '=') { break; }
	if (sftk_argIsBlank(*string)) break;
    }

    len = string - inString;

    *next = len; 
    if (*string == '=') (*next) += 1;
    if (len > 0) {
	name = PORT_Alloc(len+1);
	PORT_Strncpy(name,inString,len);
	name[len] = 0;
    }
    return name;
}
Example #3
0
/*
 * read one file out of either /etc or the user's home directory.
 * fileToRead tells which file to read.
 *
 * return 1 if it's time to reset the fileToRead (no more files to read).
 */
static int
ReadOneFile(int fileToRead)
{
    char *dir = "/etc";
    DIR *fd = opendir(dir);
    int resetCount = 0;
    struct dirent *entry;
#if defined(__sun)
    char firstName[256];
#else
    char firstName[NAME_MAX + 1];
#endif
    const char *name = NULL;
    int i;

    if (fd == NULL) {
	dir = PR_GetEnvSecure("HOME");
	if (dir) {
	    fd = opendir(dir);
	}
    }
    if (fd == NULL) {
	return 1;
    }

    firstName[0] = '\0';
    for (i=0; i <= fileToRead; i++) {
	do {
            /* readdir() isn't guaranteed to be thread safe on every platform;
             * this code assumes the same directory isn't read concurrently.
             * This usage is confirmed safe on Linux, see bug 1254334. */
	    entry = readdir(fd);
	} while (entry != NULL && !ReadFileOK(dir, &entry->d_name[0]));
	if (entry == NULL)  {
	    resetCount = 1; /* read to the end, start again at the beginning */
	    if (firstName[0]) {
		/* ran out of entries in the directory, use the first one */
	 	name = firstName;
	    }
	    break;
	}
        name = entry->d_name;
	if (i == 0) {
	    /* copy the name of the first in case we run out of entries */
            PORT_Assert(PORT_Strlen(name) < sizeof(firstName));
            PORT_Strncpy(firstName, name, sizeof(firstName) - 1);
            firstName[sizeof(firstName) - 1] = '\0';
	}
    }

    if (name) {
	char filename[PATH_MAX];
	int count = snprintf(filename, sizeof(filename), "%s/%s",dir, name);
	if (count >= 1) {
	    ReadSingleFile(filename);
	}
    } 

    closedir(fd);
    return resetCount;
}