LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-03-2003, 12:58 PM   #1
Sm0k3
Member
 
Registered: Sep 2003
Location: Chicago
Distribution: Slackware 13 x86_64
Posts: 58

Rep: Reputation: 15
a CGI written in C, problem with an fopen() system call


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:&nbsp; <input type=\"text\" name=\"user\" size=\"20\" value=\"%s\"><p>\n", user);
     printf("Password:&nbsp; <input type=\"password\" name=\"pass\" size=\"20\"><p>\n");
     printf("Level:&nbsp; <input type=\"text\" name=\"arg4\" size=\"20\" value=\"%s\"><p>\n", arg4);
     printf("<b>*</b>Service:&nbsp; <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
 
Old 10-03-2003, 02:11 PM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint Debian Edition (LMDE)
Posts: 212

Rep: Reputation: 31
Re: a CGI written in C, problem with an fopen() system call

I don't know if this is related, but you probably don't want that semicolon on end of the if statement.

Code:
   if((HashFile=fopen(hash, "r")) == NULL);
 
Old 10-03-2003, 02:18 PM   #3
Sm0k3
Member
 
Registered: Sep 2003
Location: Chicago
Distribution: Slackware 13 x86_64
Posts: 58

Original Poster
Rep: Reputation: 15
errrr..... that would help :-P... see what happens when a person codes half asleep at 3:30 in the morning...

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with adding a system call newcat Programming 17 04-08-2006 06:50 AM
Problem using 'read' system call buckles Programming 6 05-10-2005 11:45 AM
Problem w/ 'read' system call - RH 7.3 buckles Linux - Newbie 3 05-07-2005 12:03 AM
Problem in setgroups system call ppy Programming 1 11-04-2004 08:52 AM
how to configure apache in Suse 9.1 t run cgi programmes written in python drako123 Linux - Software 0 08-21-2004 07:27 AM


All times are GMT -5. The time now is 12:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration