コード例 #1
0
ファイル: authenticate_auth.c プロジェクト: MhdAlyan/courier
static char *send_auth_reply(const char *q, void *dummy)
{
	struct imaptoken *tok;
	char	*p;

#if SMAP
	const char *cp=getenv("PROTOCOL");

	if (cp && strcmp(cp, "SMAP1") == 0)
		writes("> ");
	else
#endif

	{
		writes("+ ");
	}
	writes(q);
	writes("\r\n");
	writeflush();
	read_timeout(SOCKET_TIMEOUT);
	tok=nexttoken_nouc();

	switch (tok->tokentype)	{
	case IT_ATOM:
	case IT_NUMBER:
		p=my_strdup(tok->tokenbuf);
		break;
	case IT_EOL:
		p=my_strdup("");
		break;
	default:
		return (0);
	}
	if (!p)
	{
		perror("malloc");
		return (0);
	}

	if (nexttoken()->tokentype != IT_EOL)
	{
		free(p);
		fprintf(stderr, "Invalid SASL response\n");
		return (0);
	}
	read_eol();
	return (p);
}
コード例 #2
0
ファイル: parser.c プロジェクト: davsebamse/TapeV2
int parse_config_file(char *filename, int open_or_die)
{
 int fd, i,j, n, err, in_sensor, s_start_line=0;
 float fl;
 int xyz[] = { 0, 0, 0 };
 char *s;

 for(i=0;i<3;i++)
    for(j=0;j<CARRIER_SUBCHANS;j++)
       carrier_remap[i][j]=-1;

 if(!(sensor=malloc(sensors_max*sizeof(struct sensor_def))))
    diag(SS_PARSER|DIE,"Out of memory (sensor array)\n");

 if((fd=open(filename,O_RDONLY))==-1) {
    if(open_or_die)
       diag(SS_PARSER|DIERR,"Cannot open config file `%s'",filename);
    else {
       diag(SS_PARSER|INFO,"Default config file `%s' not found\n",filename);
       return 0;
       }
    }

 in_sensor=0;
 config.need_serial=config.need_pipe=0;

 if(!fetch(fd)) return 0;

 while(read_token(fd,1)==1) {

    if(*token=='#') {
       read_eol(fd);
       continue;
       }

    if(TOKEN("VideoDevice")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_STRING(config.video_device)) {
          if(!(config.video_device=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("VideoNorm")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_INT(config.norm)) {
          if(TOKEN("PAL")) config.norm=VIDEO_MODE_PAL;
          else if(TOKEN("NTSC")) config.norm=VIDEO_MODE_NTSC;
          else if(TOKEN("SECAM")) config.norm=VIDEO_MODE_SECAM;
          else if(TOKEN("PAL-NC")) config.norm=3;
          else if(TOKEN("PAL-M")) config.norm=4;
          else if(TOKEN("PAL-N")) config.norm=5;
          else if(TOKEN("NTSC-JP")) config.norm=6;
          else if(TOKEN("AUTO")) config.norm=VIDEO_MODE_AUTO;
          else error("Invalid TV norm");
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("AudioCaptureDevice")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_STRING(config.audio_in_device)) {
          if(!(config.audio_in_device=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("AudioPlaybackDevice")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_STRING(config.audio_out_device)) {
          if(!(config.audio_out_device=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          }
       CHECK_EOL(fd);
       continue;
       }

    TEST_PARAM("Channel",config.channel,n>=0 && n<=65535);

    TEST_PARAM("FrameRate",config.frame_rate,n>=0 && n<=65535);

    TEST_PARAM("VideoAudioInput",config.video_audio_input,n>=0 && n<=65535);

    TEST_PARAM("VideoAudioVolume",config.video_audio_volume,n>=0 && n<=65535);

    if(TOKEN("Palette")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_INT(config.monochrome)) {
          if(TOKEN("Mono")) config.monochrome=1;
          else if(!TOKEN("Color")) {
             error("Invalid palette");
             break;
             }
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("FrameSize")) {
       if(READ(fd)!=1) { synerr(); break; }
       if((s=strchr(token,'x'))==0) { synerr(); break; }
       *s=0;
       if(UNSET_INT(config.capx)) {
          if((config.capx=atoi(token))<=0 || (config.capy=atoi(s+1))<=0)
             error("Invalid FrameSize parameter");
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("ImageFilters")) {
       while(READ(fd)==1) {
          if(TOKEN("UpsideDown"))
             config.image_filters^=IMAGE_FILTER_INVERT|IMAGE_FILTER_FLIP;
          else if(TOKEN("Invert"))
             config.image_filters^=IMAGE_FILTER_INVERT;
          else if(TOKEN("Flip"))
             config.image_filters^=IMAGE_FILTER_FLIP;
          else error("Invalid ImageFilters parameter");
          }
       /*CHECK_EOL(fd);*/
       continue;
       }

    TEST_PARAM("JpegQuality",config.jpeg_quality,n>=0 && n<=100);

    if(TOKEN("TunerFreq")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_FLOAT(config.tuner_freq)) {
          if(sscanf(token,"%f",&fl)==1) {
             if(fl<=0) error("Invalid TunerFreq parameter");
             else config.tuner_freq=fl;
             }
          else synerr();
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("Audio")) {
       while(READ(fd)==1) ;
       diag(SS_PARSER|INFO,"Ignoring deprecated `Audio' directive at line %d\n",
          line);
       continue;
       }

    if(TOKEN("AddressFamily")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_INT(config.address_family)) { // AF_* are >=0
          if(TOKEN("any")) config.address_family=AF_UNSPEC;
          else if(TOKEN("inet")) config.address_family=AF_INET;
          else if(TOKEN("inet6")) config.address_family=AF_INET6;
          else error("Invalid AddressFamily parameter");
          }
       CHECK_EOL(fd);
       continue;
       }

    TEST_PARAM("TCPPort",config.tcp_base_port,n>0 && n<=65535);

    TEST_PARAM("TCPAudioPort",config.tcp_audio_port,n>0 && n<=65535);

    if(TOKEN("SerialPort")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_STRING(config.serial_port)) {
          if(!(config.serial_port=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          }
       CHECK_EOL(fd);
       continue;
       }

    TEST_PARAM("MaxStreamingClients",config.max_clients,n>=0);

    TEST_PARAM("ControlTimeout",config.control_timeout,n>0);

    TEST_PARAM("ClientTimeout",config.client_timeout,n>0);

    TEST_PARAM("ClientAckTimeout",config.client_ack_timeout,n>0);

    if(TOKEN("Greeting")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_STRING(config.greeting)) {
          if(!(config.greeting=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("NamedPipe")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_STRING(config.named_pipe)) {
          if(!(config.named_pipe=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("LogFile")) {
       if(READ(fd)!=1) { synerr(); break; }
       if(UNSET_STRING(config.log_file)) {
          if(!(config.log_file=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          }
       CHECK_EOL(fd);
       continue;
       }

    if(TOKEN("Device")) {
       if(in_sensor) { synerr(); break; }
       in_sensor=1;
       continue;
       }
    if(TOKEN("{")) {
       if(in_sensor==1) {
          in_sensor=2;
          s_start_line=line;
          if(sensors==sensors_max) {
             sensors_max+=15;
             diag(SS_PARSER|DEBUG,"expanding device array to %d\n",sensors_max);
             sensor=realloc(sensor,sizeof(struct sensor_def)*sensors_max);
             if(!sensor) diag(SS_PARSER|DIE,"Out of memory (device array)\n");
             }
          sensor[sensors].link=-1;
          sensor[sensors].widget='\0';
          sensor[sensors].cfmin=sensor[sensors].cfmax=0;
          sensor[sensors].imin=0;
          sensor[sensors].imax=65535;
          sensor[sensors].name=sensor[sensors].hint="";
          sensor[sensors].dir=SD_R;
          sensor[sensors].notifier=-1;
          CHECK_EOL(fd);
          continue;
          }
       else { synerr(); break; }
       }
    if(in_sensor==2) {
       if(TOKEN("Direction")) {
          if(READ(fd)!=1) { synerr(); break; }
          if(TOKEN("readwrite") || TOKEN("rw"))
             sensor[sensors].dir=SD_RW;
          else if(TOKEN("read") ||TOKEN("r")) sensor[sensors].dir=SD_R;
          /*else if(TOKEN("write")||TOKEN("w")) sensor[sensors].dir=SD_W;*/
          else { error("Invalid direction"); break; }
          CHECK_EOL(fd);
          continue;
          }
       if(TOKEN("Notifier")) {
          if(READ(fd)!=1) { synerr(); break; }
          if(TOKEN("Device")) sensor[sensors].notifier=NT_DEVICE;
          else if(TOKEN("Client")) sensor[sensors].notifier=NT_CLIENT;
          else if(!TOKEN("None")) { error("Invalid notifier value"); break; }
          CHECK_EOL(fd);
          continue;
          }
       if(TOKEN("Name")) {
          if(READ(fd)!=1) { synerr(); break; }
          if(!(sensor[sensors].name=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          CHECK_EOL(fd);
          continue;
          }
       if(TOKEN("Hint")) {
          if(READ(fd)!=1) { synerr(); break; }
          if(!(sensor[sensors].hint=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          CHECK_EOL(fd);
          continue;
          }
       if(TOKEN("Visual")) {
          if(READ(fd)!=1) { synerr(); break; }
          if(TOKEN("slider")) sensor[sensors].widget='t';
          else if(TOKEN("slider_x")) {
             if(xyz[0]) error("Multiple assignments to slider_x");
             xyz[0]=1;
             sensor[sensors].widget='x';
             }
          else if(TOKEN("slider_y")) {
             if(xyz[1]) error("Multiple assignments to slider_y");
             xyz[1]=1;
             sensor[sensors].widget='y';
             }
          else if(TOKEN("slider_z")) {
             if(xyz[2]) error("Multiple assignments to slider_z");
             xyz[2]=1;
             sensor[sensors].widget='z';
             }
          else if(TOKEN("gauge")) sensor[sensors].widget='p';
          else { error("Invalid visual"); break; }
          CHECK_EOL(fd);
          continue;
          }
       if(TOKEN("Range")) {
          if(READ(fd)!=1) { synerr(); break; }
          if(sscanf(token,"%d",&sensor[sensors].imin)==0) { synerr(); break; }
          if(READ(fd)!=1) { synerr(); break; }
          if(sscanf(token,"%d",&sensor[sensors].imax)==0) { synerr(); break; }
          CHECK_EOL(fd);
          if(sensor[sensors].imax<=sensor[sensors].imin) {
             error("Invalid device range");
             }
          continue;
          }
       if(TOKEN("Remap")) {
          if(READ(fd)!=1) { synerr(); break; }
          if(!(sensor[sensors].cfmin=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          if(READ(fd)!=1) { synerr(); break; }
          if(!(sensor[sensors].cfmax=strdup(token)))
             diag(SS_PARSER|DIE,"Out of memory\n");
          CHECK_EOL(fd);
          continue;
          }
#if 0
       if(TOKEN("Init")) {
          if(READ(fd)!=1) { synerr(); break; }
          CHECK_EOL(fd);
          continue;
          }
#endif
       if(TOKEN("Carrier")) {
          int link, id;
          if(READ(fd)!=1) { synerr(); break; }
          if(TOKEN("pipe")) {
             link=LINK_PIPE;
             config.need_pipe=1;
             }
          else if(TOKEN("serial")) {
             link=LINK_SERIAL;
             config.need_serial=1;
             }
          else if(TOKEN("internal")) link=LINK_INTERNAL;
          else { error("Invalid link type"); break; }
          if(READ(fd)!=1) { synerr(); break; }
          if(sscanf(token,"%d",&id)==0) { synerr(); break; }
          if(id<0||id>=CARRIER_SUBCHANS) error("Channel out of range");
          carrier_remap[link][id]=sensors;
          sensor[sensors].link=link;
          sensor[sensors].channel=id;
          /*diag(SS_PARSER|DEBUG,"Mapping link %d subchan %d to device %d\n",
             link,id,sensors);*/
          CHECK_EOL(fd);
          continue;
          }

       if(!TOKEN("}")) {
          error("Unrecognized token");
          read_eol(fd);
          }
       }
    if(TOKEN("}")) {
       if(in_sensor==2) {
          in_sensor=0;

          err=0;

          if(sensor[sensors].notifier==-1) {
             if(sensor[sensors].link==LINK_INTERNAL)
                sensor[sensors].notifier=NT_CLIENT;
             else
                sensor[sensors].notifier=NT_DEVICE;
             }

          if(sensor[sensors].link==-1) {
             diag(SS_PARSER|ERROR,"Undefined link for device %d (starting at line %d)\n",
                sensors,s_start_line);
             err=1;
             }
          if(sensor[sensors].link==LINK_PIPE && sensor[sensors].dir!=SD_R) {
             diag(SS_PARSER|ERROR,"Illegal direction for device %d (starting at line %d): only `Read' allowed here\n",
                sensors,s_start_line);
             err=1;
             }
#if 0
          if(sensor[sensors].name==0) {
             diag(SS_PARSER|ERROR,"Missing name for device %d (starting at line %d)\n",
                sensors,s_start_line);
             err=1;
             }
#endif
          if(sensor[sensors].widget=='\0') {
             if(!strcasecmp(sensor[sensors].name,"Pan")) {
                if(xyz[0]) error("Multiple assignments to slider_x");
                sensor[sensors].widget='x';
                xyz[0]=1;
                }
             else if(!strcasecmp(sensor[sensors].name,"Tilt")) {
                if(xyz[1]) error("Multiple assignments to slider_y");
                sensor[sensors].widget='y';
                xyz[1]=1;
                }
             else if(!strcasecmp(sensor[sensors].name,"Zoom")) {
                if(xyz[2]) error("Multiple assignments to slider_z");
                sensor[sensors].widget='z';
                xyz[2]=1;
                }
             }

          if(sensor[sensors].widget=='\0') {
             diag(SS_PARSER|ERROR,
                "Undefined visual for device %d (starting at line %d)\n",
                sensors,s_start_line);
             err=1;
             }
          if(sensor[sensors].cfmin==0) { /* .cfmax==0 too */
             char buff[12];
             snprintf(buff,12,"%d",sensor[sensors].imin);
             if(!(sensor[sensors].cfmin=strdup(buff)))
                diag(SS_PARSER|DIE,"Out of memory\n");
             snprintf(buff,12,"%d",sensor[sensors].imax);
             if(!(sensor[sensors].cfmax=strdup(buff)))
                diag(SS_PARSER|DIE,"Out of memory\n");
             }

          if(err) return 1;
          sensors++;
          continue;
          }
       else { synerr(); break; }
       }
    error("Unrecognized token");
    read_eol(fd);
    }

 if(!syn && in_sensor) {
    diag(SS_PARSER|ERROR,"Incomplete definition for device %d (starting at line %d)\n",
       sensors,s_start_line);
    syn=1;
    }

 close(fd);
 line--;
 /* diag(SS_PARSER|DEBUG,"Parsed %d line%s\n",line,line==1?"":"s"); */
 return syn;
}
コード例 #3
0
ファイル: authenticate_auth.c プロジェクト: MhdAlyan/courier
int authenticate(const char *tag, char *methodbuf, int methodbuflen)
{
struct imaptoken *tok=nexttoken();
char	*authmethod;
char	*initreply=0;
char	*authtype, *authdata;
char	authservice[40];
char	*p ;
int	rc;

	switch (tok->tokentype)	{
	case IT_ATOM:
	case IT_QUOTED_STRING:
		break;
	default:
		return (0);
	}

	authmethod=my_strdup(tok->tokenbuf);
	if (methodbuf)
		snprintf(methodbuf, methodbuflen, "%s", authmethod);

	tok=nexttoken_nouc();
	if (tok->tokentype != IT_EOL)
	{
		switch (tok->tokentype)	{
		case IT_ATOM:
		case IT_NUMBER:
			break;
		default:
			return (0);
		}
		initreply=my_strdup(tok->tokenbuf);
		if (strcmp(initreply, "=") == 0)
			*initreply=0;
		tok=nexttoken_nouc();
	}

	if (tok->tokentype != IT_EOL)	return (0);

	read_eol();
	if ((rc = auth_sasl_ex(authmethod, initreply, imap_externalauth(),
			       &send_auth_reply, NULL,
			       &authtype, &authdata)) != 0)
	{
		free(authmethod);
		if (initreply)
			free(initreply);
		return (rc);
	}

	free(authmethod);
	if (initreply)
		free(initreply);

	strcat(strcpy(authservice, "AUTHSERVICE"),
			 getenv("TCPLOCALPORT"));
	p=getenv(authservice);

	if (!p || !*p)
		p="imap";

	rc=auth_generic(p, authtype, authdata, login_callback, (void *)tag);
	free(authtype);
	free(authdata);
	return (rc);
}