hello everyone. i have a question regaurding fopen() system call in C (this program is a CGI)..
well, for some reason, this snippet of code errors... every other fopen() seems to work 'cept for this one, and i don't think i've done anything differently from my other fopen() calls
Code:
#define HASHES "/path/to/hashes"
/* arg1-arg6 + user + pass are parsed out elsewhere from
getenv("QUERY_STRING")
*/
/* massive part of code omitted */
c_adduser(C_PARAM)
{
if(atoi(arg3) == 1)
{
char hashbuff[1024];
char hash[1024];
FILE *HashFile;
char* HashArrayTable[2];
sprintf(hash, "%s/%s", HASHES, arg5);
/***************** this is the problem **************************************/
if((HashFile=fopen(hash, "r")) == NULL);
{
fprintf(stderr, "[%s] [error] [client: %s] ", ctime(time(NULL)), getenv("REMOTE_ADDR"));
fprintf(stderr, "%s:", hash);
perror("Unable to open");
printf("Invalid service<p><p>\n");
printf("<form method=\"GET\" action=\"http://futurenet.ath.cx/cgi-bin/webmin\">\n");
printf("<input type=\"hidden\" name=\"page\" value=\"admin\">\n");
printf("<input type=\"hidden\" name=\"arg1\" value=\"%s\">\n", arg1);
printf("<input type=\"hidden\" name=\"arg2\" value=\"adduser\">\n");
printf("<input type=\"hidden\" name=\"arg3\" value=\"1\">\n");
printf("<b>Add User</b><p>\n");
printf("User Name: <input type=\"text\" name=\"user\" size=\"20\" value=\"%s\"><p>\n", user);
printf("Password: <input type=\"password\" name=\"pass\" size=\"20\"><p>\n");
printf("Level: <input type=\"text\" name=\"arg4\" size=\"20\" value=\"%s\"><p>\n", arg4);
printf("<b>*</b>Service: <select size=\"1\" name=\"arg5\">\n");
dp=opendir(HASHES);
while((dirp = readdir(dp)) != NULL){
if(strcasecmp(dirp->d_name, " ") && strcasecmp(dirp->d_name, ".") && strcasecmp(dirp->d_name, ".."))
{
printf("<option>%s</option>\n", dirp->d_name);
}
}
printf("</select>\n");
closedir(dp);
printf("<p><input type=\"submit\" name=\"arg6\" value=\"Add User\"><p>\n</form>\n");
return(0);
}
// code ommited
}
// lots more code omitted
for some reason, i get a "Numerical result out of range" when i try to fopen().. could anyone shed some light on the subject