mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-10 16:43:35 +02:00
2020-11-06 Fred Gleason <fredg@paravelsystems.com>
* Consolidated ticket processing operations in new 'RDUser::createTicket()' and 'RDUser::ticketIsValid()' methods. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -402,52 +401,27 @@ bool Xport::Authenticate()
|
||||
|
||||
void Xport::TryCreateTicket(const QString &name)
|
||||
{
|
||||
QString ticket;
|
||||
QString passwd;
|
||||
int command;
|
||||
char rawstr[1024];
|
||||
unsigned char sha1[SHA_DIGEST_LENGTH];
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
|
||||
if(xport_post->getValue("COMMAND",&command)) {
|
||||
if(command==RDXPORT_COMMAND_CREATETICKET) {
|
||||
struct timeval tv;
|
||||
memset(&tv,0,sizeof(tv));
|
||||
gettimeofday(&tv,NULL);
|
||||
srandom(tv.tv_usec);
|
||||
for(int i=0;i<5;i++) {
|
||||
long r=random();
|
||||
unsigned ipv4_addr=xport_post->clientAddress().toIPv4Address();
|
||||
snprintf(rawstr+i*8,8,"%c%c%c%c%c%c%c%c",
|
||||
0xff&((int)r>>24),0xff&(ipv4_addr>>24),
|
||||
0xff&((int)r>>16),0xff&(ipv4_addr>>16),
|
||||
0xff&((int)r>>8),0xff&(ipv4_addr>>8),
|
||||
0xff&(int)r,0xff&ipv4_addr);
|
||||
}
|
||||
SHA1((const unsigned char *)rawstr,40,sha1);
|
||||
ticket="";
|
||||
for(int i=0;i<SHA_DIGEST_LENGTH;i++) {
|
||||
ticket+=QString().sprintf("%02x",0xFF&rawstr[i]);
|
||||
}
|
||||
QDateTime now=QDateTime::currentDateTime();
|
||||
sql=QString("insert into WEBAPI_AUTHS set ")+
|
||||
"TICKET=\""+RDEscapeString(ticket)+"\","+
|
||||
"LOGIN_NAME=\""+RDEscapeString(name)+"\","+
|
||||
"IPV4_ADDRESS=\""+xport_post->clientAddress().toString()+"\","+
|
||||
"EXPIRATION_DATETIME=\""+
|
||||
now.addSecs(rda->user()->webapiAuthTimeout()).
|
||||
toString("yyyy-MM-dd hh:mm:ss")+"\"";
|
||||
q=new RDSqlQuery(sql);
|
||||
delete q;
|
||||
printf("Content-type: application/xml\n\n");
|
||||
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
||||
printf("<ticketInfo>\n");
|
||||
printf(" %s\n",(const char *)RDXmlField("ticket",ticket).utf8());
|
||||
printf(" %s\n",(const char *)
|
||||
RDXmlField("expires",now.addSecs(rda->user()->webapiAuthTimeout())).utf8());
|
||||
printf("</ticketInfo>\n");
|
||||
exit(0);
|
||||
QString ticket;
|
||||
QDateTime expire_datetime;
|
||||
if(rda->user()->createTicket(&ticket,&expire_datetime,
|
||||
xport_post->clientAddress(),now)) {
|
||||
printf("Content-type: application/xml\n\n");
|
||||
printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
||||
printf("<ticketInfo>\n");
|
||||
printf(" %s\n",RDXmlField("ticket",ticket).utf8().constData());
|
||||
printf(" %s\n",
|
||||
(const char *)RDXmlField("expires",expire_datetime).utf8());
|
||||
printf("</ticketInfo>\n");
|
||||
exit(0);
|
||||
}
|
||||
else {
|
||||
XmlExit("Ticket creation failed",500,"rdxport.cpp",LINE_NUMBER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user