All pastes #10296 Raw Edit

Stuff

public text v1 · immutable
#10296 ·published 2005-04-25 21:04 UTC
rendered paste body
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#define FIELD_LEN  50 /* how long each value can be */

static char x2c(char *what)
{   
    register char digit;
    
    digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
    digit *= 16;
    digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
    return(digit);
}   

static void unescape_url(char *url)
{
    int x,y;

    for (x=0,y=0; url[y]; ++x,++y) {
        if ((url[x] = url[y]) == '%') {
            url[x] = x2c(&url[y+1]);
            y += 2;
        }
    }
    url[x] = '\0';
}

int main() {

    char *user;
    char *passwd;
    char *seperator;
    char post_params[FIELD_LEN];

    /* get post params from html form */
       if ((fgets(post_params,  FIELD_LEN, stdin)) == NULL) {     
//       printf("Content-Type: text/html\n\n<HTML><HEAD></HEAD><BODY><P>Error Lo
gging in.</P></BODY></HTML>");        

       return 0;
       }
     
user = strstr(post_params, "user=") + strlen("user=");
passwd = strstr(post_params, "passwd=") + strlen("passwd=");
       if ((seperator = strstr(post_params, "&"))); {
       *seperator = '\0';

        }
unescape_url(user);
unescape_url(passwd);

  //        printf("Content-Type: text/html\n\n<HTML><HEAD></HEAD><BODY><P>login
: \"%s\"<BR>\npasswd: \"%s\"\n</P></BODY></HTML>", user, passwd);
if (execl("/usr/bin/weblogin", "weblogin",user,passwd,(char *)0) == -1) {
    perror(errno);
    return 0;
}    
}