// OTT mirror
// Copyright (C) 2014, 2022 Balthasar Szczepański
-// post.cpp automatically generated from post.1.cpp
+// post.c automatically generated from post.1.c
// write posts from the mirror.
-// 24.09.2022
+// 29.09.2022
//
// This file is part of OTT mirror.
//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <errno.h>
#include <string.h>
#include <sys/wait.h>
int r;
FILE *tempfile;
FILE *postfile;
-bool tf=false;
-bool pf=false;
+char tf=0;
+char pf=0;
char temppath[N_STRBUF]="";
char postpath[N_STRBUF]="";
void submit();
void preview (const char *text);
-void writeArg(FILE *file,const char *name,const char *value, bool all);
-void writeArg(FILE *file,const char *name,const char *value, char *insert);
-void writeArgH(FILE *file,const char *name,const char *value, unsigned char br);
+void writeArgA(FILE *file,const char *name,const char *value, char all);
+void writeArgI(FILE *file,const char *name,const char *value, char *insert);
+void writeArgHN(FILE *file,const char *name,const char *value, unsigned char br);
void writeArgH(FILE *file,const char *value);
void end(int m);
exit(m);
}
-void writeArg(FILE *file,const char *name,const char *value, bool all=false)
+void writeArgA(FILE *file,const char *name,const char *value, char all)
{
unsigned short length, i, v;
fprintf(file,"%s=",name);
fputc('\n',file);
}
-void writeArg(FILE *file,const char *name,const char *value, char *insert)
+void writeArgI(FILE *file,const char *name,const char *value, char *insert)
{
unsigned short length, i, v;
fprintf(file,"%s=",name);
fputc('\n',file);
}
-void writeArgH(FILE *file,const char *name,const char *value, unsigned char br=0)
+void writeArgHN(FILE *file,const char *name,const char *value, unsigned char br)
{
unsigned short length, i, v;
fprintf(file,"%s=",name);
tempfile=fopen(temppath,"wt");
if(tempfile==NULL)
preview("Couldn't create file.");
- tf=true;
- writeArgH(tempfile,"timenumber",timenumber);
- writeArgH(tempfile,"timetext",timetext);
- writeArgH(tempfile,"BBHTML",message,1);
- writeArgH(tempfile,"BB",message,3);
- writeArgH(tempfile,"username_h",username);
- writeArgH(tempfile,"subject_h",subject);
- writeArg (tempfile,"username",username);
- writeArg (tempfile,"password",password,1);
- writeArg (tempfile,"subject",subject);
- writeArg (tempfile,"addbbcode20",addbbcode20);
- writeArg (tempfile,"message",message,botinfo);
+ tf=1;
+ writeArgHN(tempfile,"timenumber",timenumber,0);
+ writeArgHN(tempfile,"timetext", timetext, 0);
+ writeArgHN(tempfile,"BBHTML", message, 1);
+ writeArgHN(tempfile,"BB", message, 3);
+ writeArgHN(tempfile,"username_h",username, 0);
+ writeArgHN(tempfile,"subject_h", subject, 0);
+ writeArgA (tempfile,"username", username, 0);
+ writeArgA (tempfile,"password", password, 1);
+ writeArgA (tempfile,"subject", subject, 0);
+ writeArgA (tempfile,"addbbcode20",addbbcode20,0);
+ writeArgI (tempfile,"message", message, botinfo);
if(disable_bbcode[0]!='\0')
- writeArg(tempfile,"disable_bbcode",disable_bbcode);
+ writeArgA(tempfile,"disable_bbcode",disable_bbcode,0);
if(disable_smilies[0]!='\0')
- writeArg(tempfile,"disable_smilies",disable_smilies);
+ writeArgA(tempfile,"disable_smilies",disable_smilies,0);
if(disable_magic_url[0]!='\0')
- writeArg(tempfile,"disable_magic_url",disable_magic_url);
+ writeArgA(tempfile,"disable_magic_url",disable_magic_url,0);
if(attach_sig[0]!='\0')
- writeArg(tempfile,"attach_sig",attach_sig);
+ writeArgA(tempfile,"attach_sig",attach_sig,0);
if(notify[0]!='\0')
- writeArg(tempfile,"notify",notify);
+ writeArgA(tempfile,"notify",notify,0);
fclose(tempfile);
- tf=false;
+ tf=0;
snprintf(arg1,N_STRBUF,"outfile=%s",temppath);
fflush(stdout);
}
else
{
- tf=true;
+ tf=1;
if(fgets(listpath,N_STRBUF-1,tempfile))
sscanf(listpath,"%lu",&lastpage);
if(fgets(listpath,N_STRBUF-1,tempfile))
else
++postslast;
fclose(tempfile);
- tf=false;
+ tf=0;
}
tempfile=fopen(MLAST_PATH,"wt");
if(tempfile==NULL)
{
- pf=true;
+ pf=1;
preview("Couldn't update list.");
}
fprintf(tempfile,"%lu\n%hu\n%s\n",lastpage,postslast,timenumber);
tempfile=fopen(listpath,"at");
if(tempfile==NULL)
{
- pf=true;
+ pf=1;
preview("Couldn't update list.");
}
fprintf(tempfile,"%s\n",timenumber);
tempfile=fopen(temppath,"wt");
if(tempfile==NULL)
end(1);
- tf=true;
-
- writeArgH(tempfile,"HTML",message,1);
- writeArgH(tempfile,"BB",message,3);
- writeArgH(tempfile,"wrong",text);
- writeArgH(tempfile,"username",username);
- writeArgH(tempfile,"subject",subject);
- writeArgH(tempfile,"message",message);
- // writeArgH(tempfile,"addbbcode20",addbbcode20);
- writeArgH(tempfile,"disable_bbcode",disable_bbcode);
- writeArgH(tempfile,"disable_smilies",disable_smilies);
- writeArgH(tempfile,"disable_magic_url",disable_magic_url);
- writeArgH(tempfile,"attach_sig",attach_sig);
- writeArgH(tempfile,"notify",notify);
- writeArgH(tempfile,"addquote",addquote);
- writeArgH(tempfile,"edit",edit);
- writeArgH(tempfile,"forceID",forceID);
- // writeArgH(tempfile,"Preview",Preview);
- // writeArgH(tempfile,"post",post);
+ tf=1;
+
+ writeArgHN(tempfile,"HTML", message, 1);
+ writeArgHN(tempfile,"BB", message, 3);
+ writeArgHN(tempfile,"wrong", text, 0);
+ writeArgHN(tempfile,"username", username, 0);
+ writeArgHN(tempfile,"subject", subject, 0);
+ writeArgHN(tempfile,"message", message, 0);
+ // writeArgHN(tempfile,"addbbcode20",addbbcode20, 0);
+ writeArgHN(tempfile,"disable_bbcode", disable_bbcode, 0);
+ writeArgHN(tempfile,"disable_smilies", disable_smilies, 0);
+ writeArgHN(tempfile,"disable_magic_url",disable_magic_url,0);
+ writeArgHN(tempfile,"attach_sig", attach_sig, 0);
+ writeArgHN(tempfile,"notify", notify, 0);
+ writeArgHN(tempfile,"addquote", addquote, 0);
+ writeArgHN(tempfile,"edit", edit, 0);
+ writeArgHN(tempfile,"forceID", forceID, 0);
+ // writeArgHN(tempfile,"Preview", Preview, 0);
+ // writeArgHN(tempfile,"post", post, 0);
fclose(tempfile);
- tf=false;
+ tf=0;
printf("Content-type: text/html\n\n");
end(0);
}
-int main()
+int main(int argc, char **argv)
{
- bool missing=false;
-
+ char missing=0;
+ uid_t euid;
+ gid_t egid;
+ int r;
char *arg;
+ /* always be yourself in your total life */
+ euid = geteuid();
+ egid = getegid();
+ if ((r = setreuid(euid, euid)))
+ return (r = errno);
+ if ((r = setregid(egid, egid)))
+ return (r = errno);
+
cgi=cgiInit();
snprintf(temppath,N_STRBUF,"%s%lu",TEMP_PATH,(unsigned long)getpid());
password=arg;
else
{
- missing=true;
+ missing=1;
strcpy(wrong,"Password is missing.");
}
username=arg;
else
{
- missing=true;
+ missing=1;
strcpy(wrong,"Username is missing.");
}
subject=arg;
else
{
- missing=true;
+ missing=1;
strcpy(wrong,"Subject was missing. Replaced with default value.");
}
message=arg;
else
{
- missing=true;
+ missing=1;
strcpy(wrong,"Post is empty.");
}
arg=cgiGetValue(cgi,"password2");
if(arg!=NULL)
{
- missing=true;
+ missing=1;
strcpy(wrong,"Please don't write in the \"Leave this empty\" field.");
}