/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include "packer.h"
/*
* This file steers the creation of the Crack Dictionary Database.
* Based on a list of source dictionaries specified by the administrator,
* we create the Database by sorting each dictionary (in memory, one at
* a time), writing the sorted result to a temporary file, and merging
* all the temporary files into the Database.
*
* The current implementation has a number of limitations
* - each single source dictionary has to fit in memory
* - each single source dictionary has to be smaller than 2GByte
* - each single source dictionary can only hold up to 4GB words
* None of these seem real, practical, problems to me.
*
* All of this is meant to be run by one thread per host. The caller is
* responsible for locking things appropriately (as make_dict_database
* in dict.c does).
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
/* Stuff used for sorting the dictionary */
/* stuff to keep track of the temporary files */
/*
* int writeout(void)
*
* Write the sorted wordlist to disk. We create a temporary file
* FILE pointer to it in tmpfp[] for later use.
*
*/
int
writeout(void)
{
int i = 0;
int fd;
"files (maximum %d exceeded)", MAXTMP);
return (-1);
}
return (-1);
}
return (-1);
}
/* write words to file */
while (i < off_idx) {
return (-1);
}
}
/* we have one extra tmpfp */
tmpfp_idx++;
return (0);
}
/*
* int insert_word(int off)
*
* insert an offset into the offsets-array. If the offsets-array is out of
* space, we allocate additional space (in CHUNKs)
*
* returns 0 on success, -1 on failure (out of memory)
*/
int
{
return (-1);
}
}
return (0);
}
/*
* translate(buf, size)
*
* perform "tr '[A-Z]' '[a-z]' | tr -cd '\012[a-z][0-9]'" on the
* words in "buf" and insert each of them into the offsets-array.
* We refrain from using 'isupper' and 'islower' to keep this strictly
* ASCII-only, as is the original Cracklib code.
*
* returns 0 on success, -1 on failure (failure of insert_word)
*/
int
{
char *p, *q, *e;
char c;
int wordstart;
wordstart = 0;
c = *q;
if (c >= 'A' && c <= 'Z') {
*(p++) = tolower(c);
} else if (c == '\n') {
*(p++) = '\0';
/*
* make sure we only insert words consisting of
* MAXWORDLEN-1 bytes or less
*/
if (insert_word(wordstart) != 0)
return (-1);
} else if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) {
*(p++) = c;
}
}
return (0);
}
/*
* int compare(a, b)
*
* helper-routine used for quicksort. we compate two words in the
* buffer, one start starts at index "a", and the other one that starts
* at index "b"
*/
int
compare(const void *a, const void *b)
{
}
/*
*
* int sort_file(fname)
*
* We sort the file in memory: we read the dictionary file, translate all
* newlines to '\0's, all uppercase ASCII characters to lowercase characters
* and removing all characters but '[a-z][0-9]'.
* We maintain an array of offsets into the buffer where each word starts
* and sort this array using qsort().
*
* This implements the original cracklib code that did an execl of
* sort -o tmfpfile
*
* returns 0 on success, -1 on failure.
*/
int
{
int fd;
ssize_t n;
return (-1);
}
return (-1);
}
goto error;
}
if (n == -1) {
"Split the file into smaller files.", fname);
else
goto error;
}
if (writeout() == 0)
ret = 0;
}
off_size = 0;
off_idx = 0;
return (ret);
}
/*
* We merge the temporary files created by previous calls to sort_file()
* and insert the thus sorted words into the cracklib database
*
* returns 0 on success, -1 on failure.
*/
int
{
int ti;
int choice;
lastword[0] = '\0';
while (--ti >= 0)
return (-1);
}
/*
* we read the first word of each of the temp-files into words[].
*/
}
/*
* next, we emit the word that comes first (lexicographically),
* and replace that word with a new word from the file it
* came from. If the file is exhausted, we close the fp and
* swap the fp with the last fp in tmpfp[].
* we then decrease tmpfp_idx and continue with what's left until
* we run out of open FILE pointers.
*/
while (tmpfp_idx != 0) {
choice = 0;
/* Insert word in Cracklib database */
}
tmpfp_idx--;
} else
}
return (0);
}
/*
* int packer(list)
*
* sort all dictionaries in "list", and feed the words into the Crack
* Password Database.
*
* returns 0 on sucess, -1 on failure.
*/
int
{
int ret = 0;
return (-1);
}
return (-1);
}
}
if (ret == 0)
return (ret);
}