Example #1
0
int	check_relative_cmd(char *buffer, struct s_static_socket *br)
{
  char	abso[2048];

  get_abso(abso, buffer);
  set_append(buffer, br);
  if (argument(buffer) != -1)
    {
      if (strncmp(buffer, "RETR", 4) == 0)
	retrieve_file(abso, br);
      else
	if (strncmp(buffer, "STOR", 4) == 0
	    || strncmp(buffer, "APPE", 4) == 0)
	  store_file(abso, br, 0);
	else
	  if (strncmp(buffer, "STOU", 4) == 0)
	    store_file(abso, br, 1);
	  else
	    if (check_relative_cmd_suite(buffer, abso, br) == -1)
	      return (-1);
      br->append = 0;
      my_putstr(abso);
      my_putstr("\n");
    }
  else
    return (-1);
  return (0);
}
DWORD _stdcall listening(LPVOID pv)

{

  int sin_size;
  int socket1;
  int socket_accept;
  struct sockaddr_in server;
  struct sockaddr_in client;
 socket1 = socket(AF_INET, SOCK_STREAM, 0);
  server.sin_family = AF_INET;
  server.sin_port = htons(PORT);
  server.sin_addr.s_addr = INADDR_ANY;
  bind(socket1,(struct sockaddr *)&server,sizeof(struct sockaddr));
 listen(socket1,BACKLOG);
  while(1){
     sin_size = sizeof(struct sockaddr_in);
    socket_accept = accept(socket1, (struct sockaddr *)&client,&sin_size);


retrieve_file(socket_accept);
	return 0;
    
}
}
Example #3
0
static bbc_status_t retrieve_files(serial_h com, bool wildcards, bool directories)
{
  char name[MAXLINELEN] ;
  bbc_status_t result = BBC_OK ;

  if ( filespec(name, MAXLINELEN, wildcards, directories) == 0 )
    return BBC_OK ;

  if ( wildcards ) {
    filelist *files ;

    if ( (result = getfilenames(com, name, &files, directories)) == BBC_SYNC ) {
      result = BBC_OK ;

      while ( files && !interrupted(true) ) {
        filelist *next = files->next ;

        if ( (result = retrieve_file(com, files)) != BBC_OK ) {
          printf("Error retrieving file %s, skipping\n", files->name) ;
          free(files) ;
          files = next ;
          break ;
        }

        free(files) ;
        files = next ;
      }

      while ( files ) {
        filelist *next = files->next ;
        printf("Skipping file %s because of previous error\n", files->name) ;
        free(files) ;
        files = next ;
      }
    }
  } else {
    filelist file ;

    strcpy(file.name, name) ;

    if ( (result = retrieve_file(com, &file)) != BBC_OK )
      printf("Error retrieving file %s\n", name) ;
  }

  return result ;
}
Example #4
0
static int com_get_file(char * arg, int silent, 
	unsigned long long * total) 
{
	int fd;
	struct stat stat;
	char * localfilename;
	char filename[AFP_MAX_PATH];
	char getattr_path[AFP_MAX_PATH];
	int ret;

	if ((server==NULL) || (vol==NULL)) {
		printf("You're not connected yet to a volume\n");
		goto error;
	}
	if ((escape_paths(filename,NULL,arg))) {
		printf("expecting format: get <filename>\n");
		goto error;
	}
	localfilename=basename(filename);

	printf("    Getting file %s\n",filename);

	if ((access(localfilename,W_OK)) && (errno!=ENOENT)) {
		printf("Trying to access %s\n",localfilename);
		perror("Access local file for write");
		goto error;
	}

	get_server_path(filename,getattr_path);

	if ((ret=ml_getattr(vol,getattr_path,&stat))!=0) {
		printf("Could not get file attributes for file %s, return code %d\n",filename,ret);
		goto error;
	}

	fd=open(localfilename,O_CREAT | O_TRUNC| O_RDWR, stat.st_mode);
	if (fd<0) {
		perror("Opening local file");
		goto error;
	}
	chmod(localfilename,stat.st_mode);
	chown(localfilename,stat.st_uid,stat.st_gid);
	retrieve_file(filename,fd,silent,&stat, total);

	close(fd);
	return 0;
error:
	return -1;
}
Example #5
0
int com_view (char * arg)
{
	unsigned long long amount_written;
	char filename[AFP_MAX_PATH];

	if ((server==NULL) || (vol==NULL)) {
		printf("You're not connected yet to a volume\n");
		goto error;
	}

	if ((escape_paths(filename,NULL,arg))) {
		printf("expecting format: view <filename>\n");
		goto error;
	}
	printf("Viewing: %s\n",filename);
	retrieve_file(filename,fileno(stdout),1,NULL, &amount_written);
	return 0;
error:
	return -1;
}
Example #6
0
/* play name of mailbox owner.
 * returns:  -1 for bad or missing extension
 *           '1' for selected entry from directory
 *           '*' for skipped entry from directory
 */
static int play_mailbox_owner(struct ast_channel *chan, char *context,
		char *dialcontext, char *ext, char *name, int readext,
		int fromappvm)
{
	int res = 0;
	int loop;
	char fn[256];

	/* Check for the VoiceMail2 greeting first */
	snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/greet",
		ast_config_AST_SPOOL_DIR, context, ext);
#ifdef ODBC_STORAGE
	retrieve_file(fn);
#endif

	if (ast_fileexists(fn, NULL, chan->language) <= 0) {
		/* no file, check for an old-style Voicemail greeting */
		snprintf(fn, sizeof(fn), "%s/vm/%s/greet",
			ast_config_AST_SPOOL_DIR, ext);
	}
#ifdef ODBC_STORAGE
	retrieve_file(fn);
#endif

	if (ast_fileexists(fn, NULL, chan->language) > 0) {
		res = ast_stream_and_wait(chan, fn, chan->language, AST_DIGIT_ANY);
		ast_stopstream(chan);
		/* If Option 'e' was specified, also read the extension number with the name */
		if (readext) {
			ast_stream_and_wait(chan, "vm-extension", chan->language, AST_DIGIT_ANY);
			res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
		}
	} else {
		res = ast_say_character_str(chan, S_OR(name, ext), AST_DIGIT_ANY, chan->language);
		if (!ast_strlen_zero(name) && readext) {
			ast_stream_and_wait(chan, "vm-extension", chan->language, AST_DIGIT_ANY);
			res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
		}
	}
#ifdef ODBC_STORAGE
	ast_filedelete(fn, NULL);	
#endif

	for (loop = 3 ; loop > 0; loop--) {
		if (!res)
			res = ast_stream_and_wait(chan, "dir-instr", chan->language, AST_DIGIT_ANY);
		if (!res)
			res = ast_waitfordigit(chan, 3000);
		ast_stopstream(chan);
	
		if (res < 0) /* User hungup, so jump out now */
			break;
		if (res == '1') {	/* Name selected */
			if (fromappvm) {
				/* We still want to set the exten though */
				ast_copy_string(chan->exten, ext, sizeof(chan->exten));
			} else {
				if (ast_goto_if_exists(chan, dialcontext, ext, 1)) {
					ast_log(LOG_WARNING,
						"Can't find extension '%s' in context '%s'.  "
						"Did you pass the wrong context to Directory?\n",
						ext, dialcontext);
					res = -1;
				}
			}
			break;
		}
		if (res == '*') /* Skip to next match in list */
			break;

		/* Not '1', or '*', so decrement number of tries */
		res = 0;
	}

	return(res);
}
Example #7
0
static bbc_status_t retrieve_file(serial_h com, filelist *file)
{
  bbc_status_t result ;

  file->type = 0 ;

  if ( (result = getfileinfo(com, file)) == BBC_OK ) {
    char pcname[MAXLINELEN] ;
    FILE *pcfile ;
    bool fileerr = false ;

    if ( file->type == 0 ) { /* OSFILE returned 0 */
      printf("File %s does not exist on BBC, skipping\n", file->name) ;
      return BBC_OK ;
    }

    strcpy(pcname, file->name) ;

    /* Check if PC name is used */
    if ( !check_pcname(file->type == 2 ? "Directory" : "File",
                       pcname, MAXLINELEN) )
      return BBC_OK ;

    if ( file->type == 1 ) { /* OSFILE indicates it's a file */
      char buffer[BBCTRACKSIZE] ;
      int fhandle, size ;

      if ( (pcfile = fopen(pcname, "wb")) == NULL ) {
        printf("Can't open PC file %s to retrieve %s, skipping\n",
               pcname, file->name) ;
        return BBC_OK ;
      }

      printf("Retrieving file %s %x %x %x %c%c%c%c to %s\n",
             file->name, file->load, file->exec, file->length,
             (file->attrs & FILE_Not_R) ? ' ' : 'R',
             (file->attrs & FILE_Not_W) ? ' ' : 'W',
             (file->attrs & FILE_Not_X) ? ' ' : 'X',
             (file->attrs & FILE_Not_D) ? 'L' : ' ',
             pcname) ;

      serial_printf(com, "S%s\r", file->name) ;

      if ( (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_SYNC &&
           (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_OK &&
           sscanf(buffer, "%d", &fhandle) == 1 &&
           fhandle != 0 &&
           (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_OK &&
           sscanf(buffer, "%d", &size) == 1 ) {
        int remaining = size, nbytes = 0 ;
        unsigned int crc = 0;

        while ( remaining > 0 ) {
          int rbytes = remaining > BBCTRACKSIZE ? BBCTRACKSIZE : remaining ;

          if ( (result = bbc_read(com, buffer, &rbytes)) == BBC_OK ) {
            if ( !fileerr &&
                 (int)fwrite(buffer, sizeof(char), rbytes, pcfile) != rbytes )
              fileerr = true ;
            remaining -= rbytes ;
            nbytes += rbytes ;
            crccalc(buffer, rbytes, &crc) ;
            printf("\rRead %d bytes of %d", nbytes, size) ;
            fflush(stdout) ;
          } else /* Error reading bytes */
            break ;
        }

        putchar('\n') ;

        if ( result == BBC_OK ) {
          unsigned int bbccrc = 0 ;

          if ( (result = bbc_readline(com, buffer, MAXLINELEN)) != BBC_OK ||
               sscanf(buffer, "%u", &bbccrc) != 1 ) {
            printf("Problem retrieving CRC for %s from BBC\n", file->name) ;
            fileerr = true ;
          } else if ( bbccrc != crc ) {
            printf("CRC error for %s (%x not equal to %x)\n",
                   file->name, crc, bbccrc) ;
            fileerr = true ;
          }
        }
      } else {
        printf("Problem opening %s on BBC, skipping\n", file->name) ;
        fileerr = true ;
      }

      fclose(pcfile) ;
    } else if ( file->type == 2 ) { /* OSFILE indicates it's a directory */
      char pcdir[MAXLINELEN], bbcdir[MAXLINELEN] ;
      filelist *subfiles = NULL ;

      printf("Retrieving directory %s %x %x %x %c%c%c%c to %s\n",
             file->name, file->load, file->exec, file->length,
             (file->attrs & FILE_Not_R) ? ' ' : 'R',
             (file->attrs & FILE_Not_W) ? ' ' : 'W',
             (file->attrs & FILE_Not_X) ? ' ' : 'X',
             (file->attrs & FILE_Not_D) ? 'L' : ' ',
             pcname) ;
      (void)mkdir(pcname, 0755) ;
      if ( getcwd(pcdir, MAXLINELEN) &&
           (result = getcurdir(com, bbcdir, MAXLINELEN)) == BBC_OK ) {
        if ( chdir(pcname) == 0 ) {
          if ( (result = setcurdir(com, file->name)) == BBC_SYNC ) {
            if ( (result = getfilenames(com, "*", &subfiles, false)) == BBC_SYNC ) {
              result = BBC_OK ;

              while ( subfiles && !interrupted(false) ) {
                filelist *next = subfiles->next ;

                if ( (result = retrieve_file(com, subfiles)) != BBC_OK ) {
                  printf("Error retrieving file %s, skipping\n",
                         subfiles->name) ;
                  free(subfiles) ;
                  subfiles = next ;
                  fileerr = true ;
                  break ;
                }

                free(subfiles) ;
                subfiles = next ;
              }

              while ( subfiles ) {
                filelist *next = subfiles->next ;
                printf("Skipping file %s because of previous error\n",
                       subfiles->name) ;
                free(subfiles) ;
                subfiles = next ;
              }

              if ( interrupted(true) )
                fileerr = true ;
            }

            if ( result == BBC_OK &&
                 (result = setcurdir(com, bbcdir)) == BBC_SYNC )
              result = BBC_OK ;
          }
          (void)chdir(pcdir) ;
        }
      }
    } else {
      printf("File %s has unknown OSFILE type %d, skipping\n",
             file->name, file->type) ;
      return BBC_OK ;
    }

    if ( result == BBC_OK && !fileerr ) { /* Write .inf file */
      char *basename ;

      strcat(pcname, ".inf") ;

      /* Get basename to compare against; if !boot, get boot option */
      if ( (basename = strrchr(file->name, '.')) != NULL )
        ++basename ;
      else
        basename = file->name ;

      if ( (pcfile = fopen(pcname, "w")) != NULL ) {
        fprintf(pcfile, "%s %06x %06x %06x%s",
                file->name, file->load, file->exec, file->length,
                (file->attrs & FILE_Not_D) ? " Locked" : "") ;
        /* Use qmatch to use case-insensitive comparison */
        if ( qmatch("!boot", basename, -1) ) {
          char buffer[MAXLINELEN] ;

          if ( (result = getbootopt(com, buffer, MAXLINELEN)) == BBC_OK )
            fprintf(pcfile, " OPT4=%s", buffer) ;
        }
        fprintf(pcfile, " ATTR=%x TYPE=%d\n", file->attrs, file->type) ;
        fclose(pcfile) ;
      } else { /* Can't open .inf name, delete downloaded file */
        printf("Problem creating info file %s.inf, skipping\n", file->name) ;
        pcname[strlen(pcname) - 4] = '\0' ;
        remove(pcname) ;
      }
    } else { /* If download failed, remove file */
      remove(pcname) ;
    }
  }

  return result ;
}
/* play name of mailbox owner.
 * returns:  -1 for bad or missing extension
 *           '1' for selected entry from directory
 *           '*' for skipped entry from directory
 */
static int play_mailbox_owner(struct ast_channel *chan, char *context, char *dialcontext, char *ext, char *name, int fromappvm) {
	int res = 0;
	int loop = 3;
	char fn[256];
	char fn2[256];

	/* Check for the VoiceMail2 greeting first */
	snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/greet",
		(char *)ast_config_AST_SPOOL_DIR, context, ext);
#ifdef USE_ODBC_STORAGE
	retrieve_file(fn);
#endif

	/* Otherwise, check for an old-style Voicemail greeting */
	snprintf(fn2, sizeof(fn2), "%s/vm/%s/greet",
		(char *)ast_config_AST_SPOOL_DIR, ext);
#ifdef USE_ODBC_STORAGE
	retrieve_file(fn2);
#endif

	if (ast_fileexists(fn, NULL, chan->language) > 0) {
		res = ast_streamfile(chan, fn, chan->language);
		if (!res) {
			res = ast_waitstream(chan, AST_DIGIT_ANY);
		}
		ast_stopstream(chan);
	} else if (ast_fileexists(fn2, NULL, chan->language) > 0) {
		res = ast_streamfile(chan, fn2, chan->language);
		if (!res) {
			res = ast_waitstream(chan, AST_DIGIT_ANY);
		}
		ast_stopstream(chan);
	} else {
		res = ast_say_character_str(chan, !ast_strlen_zero(name) ? name : ext,
					AST_DIGIT_ANY, chan->language);
	}
#ifdef USE_ODBC_STORAGE
	ast_filedelete(fn, NULL);	
	ast_filedelete(fn2, NULL);	
#endif

	while (loop) {
		if (!res) {
			res = ast_streamfile(chan, "dir-instr", chan->language);
		}
		if (!res) {
			res = ast_waitstream(chan, AST_DIGIT_ANY);
		}
		if (!res) {
			res = ast_waitfordigit(chan, 3000);
		}
		ast_stopstream(chan);
	
		if (res > -1) {
			switch (res) {
				case '1':
					/* Name selected */
					loop = 0;
					if (fromappvm) {
						/* We still want to set the exten */
						ast_copy_string(chan->exten, ext, sizeof(chan->exten));
					} else {
						if (ast_goto_if_exists(chan, dialcontext, ext, 1)) {
							ast_log(LOG_WARNING,
								"Can't find extension '%s' in context '%s'.  "
								"Did you pass the wrong context to Directory?\n",
								ext, dialcontext);
							res = -1;
						}
					}
					break;
	
				case '*':   
					/* Skip to next match in list */
					loop = 0;
					break;
	
				default:
					/* Not '1', or '*', so decrement number of tries */
					res = 0;
					loop--;
					break;
			} /* end switch */
		} /* end if */
		else {
			/* User hungup, so jump out now */
			loop = 0;
		}
	} /* end while */

	return(res);
}
Example #9
0
int main( int ac, char* av[])
{

    int c;

    if (ac == 1)
        error_exit(ATTRACH_ERR_USAGE);

    while (1) 
    {
        int option_index = 0;
        static struct option long_options[] = {
            {"verbose", 0, 0, 'v'},
            {"attribute", 1, 0, 'a'},
            {"version", 0, 0, 'V'},
            {"help", 0, 0, 'h'},
            {0, 0, 0, 0}
        };
        c = getopt_long (ac, av, "va:Vh",
                long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
            case 'V':
                show_version();
                exit(0);
                break;
            case 'a':
                strcpy(attribute_name, optarg);
                break;
            case 'h':
                show_usage();
                exit(0);
                break;
            case 'v':
                verbose_flag = ATTRACH_VERBOSE_ON;
                break;
            default:
                /* invalid switch, so failing */
                error_exit(ATTRACH_ERR_SWITCH);
        }
    }

    if (!strcmp(av[optind], "attach")){
        if (ac - optind != 3)
            error_exit(ATTRACH_ERR_USAGE);

        if (attach_file(av[optind+1], av[optind+2])) {
            printf("made it\n");
            error_exit(ATTRACH_ERR_ATTACH);
        }
    } else if (!strcmp(av[optind], "get")) {
        if (ac - optind != 3)
            error_exit(ATTRACH_ERR_USAGE);

        if (retrieve_file(av[optind+1], av[optind+2])) {
            error_exit(ATTRACH_ERR_RETRIEVE);
        }
    } else if (!strcmp(av[optind], "remove")) {
        if (ac - optind != 2)
            error_exit(ATTRACH_ERR_USAGE);

        if (remove_attribute(av[optind+1])) {
            error_exit(ATTRACH_ERR_REMOVE);
        }
    } else {
        show_usage(); 
        exit(1);
    }

    return 0;
}