[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tpop3d-discuss] a silly question
From: |
Ivan Matveyev |
Subject: |
Re: [tpop3d-discuss] a silly question |
Date: |
Thu, 20 Feb 2003 16:36:34 +0300 (MSK) |
On Tue, 18 Feb 2003, Chris Lightfoot wrote:
> > > > > How so? Can you not parse a string containing embedded \0
> > > > > with PHP? That sounds a bit unlikely.
> > > > Maybe I'm dumb, but the '\0' symbol ceased input to stdin.
> > > Hmm. Interesting. Probably a question for a PHP group -- I
> > > know very little about it.
> > To say truth, that would be a 'once made and forgotten' thing.
> > Are you still interested in php script example?
> > I could attach the modification of the function in auth_other.c
> Yeah, if you could send a patch to the list, that may be
> useful for future PHP / tpop3d users.
Here is the script and auth_other_send_request modifications. Do not ask
me questions on the code - I am satisfied that it even works. :-)
#!/usr/local/bin/php -q
<?
// That's the script which gets auth info from http url. I had to modify
auth_other_send_request function
// (auth_other.c) to get the result. If you have any questions, mail
address@hidden
/* auth_other_send_request:
* Send the auth child a request consisting of several key/value pairs, as
* above. Returns 1 on success or 0 on failure.
int auth_other_send_request(const int nvars, ...) {
va_list ap;
int i, ret = 0;
char buffer[MAX_DATA_SIZE] = {0};
char *p;
size_t nn;
if (!authchild_pid) return 0;
va_start(ap, nvars);
for (i = 0, p = buffer, nn = 0; i < nvars; ++i) {
const char *key, *val;
key = va_arg(ap, const char *);
nn += strlen(key) + 1;
if (nn > sizeof(buffer)) goto fail;
memcpy(p, key, strlen(key));
p += strlen(key);
memcpy(p,"=",1);
p++;
val = va_arg(ap, const char *);
nn += strlen(val) + 1;
if (nn > sizeof(buffer)) goto fail;
memcpy(p, val, strlen(val));
p += strlen(val);
memcpy(p,"\t",1);
p++;
}
if(strlen(buffer)<400)
{
for(i=strlen(buffer);i<400;i++)
{
memcpy(p,"\0",1);
p++;
nn++;
}
}
if (nn > sizeof(buffer)) {
log_print(LOG_ERR, _("auth_other_send_request: total size of request
would exceed %d bytes"), sizeof(buffer));
goto fail;
}
/* Since write operations are atomic, this will either succeed entirely or
* fail. In the latter case, it may be with EAGAIN because the child
* process is blocking; we interpret this as a protocol error.
if (try_write(authchild_wr, buffer, nn)) ret = 1;
else {
if (errno == EAGAIN)
log_print(LOG_ERR, _("auth_other_send_request: write: write on pipe
blocked; killing child"));
else
log_print(LOG_ERR, _("auth_other_send_request: write: %m; killing
child"));
auth_other_kill_child();
}
fail:
va_end(ap);
return ret;
}
*/
error_reporting(0);
set_time_limit(0);
function array_get($what,$array)
{
foreach($array as $val)
{
if(ereg("^".$what,$val))
{
list($none,$value)=split("=",$val);
return $value;
}
}
}
function logs($in)
{
$what=date("D M j G:i:s T Y ").$in."\n";
$fp = fopen ("pop-auth.log","a");
fwrite ($fp,$what);
fclose($fp);
}
function stdout($what)
{
$stdout=fopen("php://stdout","w");
fwrite($stdout,$what);
fclose($stdout);
}
$stdin=fopen("php://stdin","r");
$term=fgets($stdin,399);
while($term)
{
$vars=split("\t",$term);
$username=array_get("user",$vars);
$password=array_get("pass",$vars);
$ip=array_get("clienthost",$vars);
$string="http://some.url/which/echoes/YES_or_NO_via_get_vars.php?username=$username&password=$password";
$tmp=file($string);
$answer=str_replace("\n","",$tmp[0]);
if($answer=="YES")
{
stdout("result\0YES\0uid\0mail\0gid\0mail\0\0");
}
if($answer=="NO")
{
stdout("result\0NO\0\0");
}
$term=fgets($stdin,399);
}
fclose($stdin);
?>
--
Ivan Matveyev, Zebra Telecom
Tech Dept, +7(095)741-0001
- [tpop3d-discuss] a silly question, Ivan Matveyev, 2003/02/18
- Re: [tpop3d-discuss] a silly question, Chris Lightfoot, 2003/02/18
- Re: [tpop3d-discuss] a silly question, Ivan Matveyev, 2003/02/18
- Re: [tpop3d-discuss] a silly question, Chris Lightfoot, 2003/02/18
- Re: [tpop3d-discuss] a silly question, Ivan Matveyev, 2003/02/18
- Re: [tpop3d-discuss] a silly question, Chris Lightfoot, 2003/02/18
- Re: [tpop3d-discuss] a silly question, Ivan Matveyev, 2003/02/18
- Re: [tpop3d-discuss] a silly question, Chris Lightfoot, 2003/02/18
- Re: [tpop3d-discuss] a silly question,
Ivan Matveyev <=