Example #1
0
int com_rmdir(char *arg)
{
	
	int ret;
	char server_fullname[AFP_MAX_PATH];
	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("Syntax: rmdir <dirname>\n");
		goto error;
	}

	get_server_path(filename,server_fullname);

	if ((ret=ml_rmdir(vol,server_fullname))) {
		printf("Could not remove directory %s, error code is %d\n",
			filename,ret);
		goto error;
	}
	printf("Removed directory %s\n",filename);
	return 0;
error:
	return -1;
}
Example #2
0
int com_chmod(char * arg)
{
	unsigned int mode;
	char basename[PATH_MAX];
	char server_fullname[AFP_MAX_PATH];
	char modestring[100];
	int ret;

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

	if (escape_paths(modestring,basename,arg)) {
		printf("expecting format: chmod <privs> <filename>\n");
		goto error;
	}

	if (sscanf(modestring,"%o",&mode)!=1) {
		printf("Mode of %s isn't octal\n");
		goto error;
	}

	get_server_path(basename,server_fullname);

	printf("Changing mode of %s to %o\n",server_fullname,mode);
	ret=ml_chmod(vol,server_fullname,mode);
	return 0;
error:
	return -1;
}
Example #3
0
int com_touch(char * arg)
{
	char server_fullname[AFP_MAX_PATH];
	int ret;
	char filename[AFP_MAX_PATH];
	char * basename = filename;

	if (escape_paths(filename,NULL,arg)) {
		printf("Syntax: touch <newfile>\n");
		goto error;
	}

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

	get_server_path(basename,server_fullname);

	ret=ml_creat(vol,server_fullname,0600);
	return 0;
error:
	return -1;

	return 0;
}
Example #4
0
int com_delete (char *arg)
{
	
	int ret;
	char server_fullname[AFP_MAX_PATH];
	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("Syntax: del <filename>\n");
		goto error;
	}

	get_server_path(filename,server_fullname);

	if ((ret=afp_ml_unlink(vol,server_fullname))) {
		printf("Could not remove %s, error code is %d\n",
			filename,ret);
		goto error;
	}
	printf("Removed file %s\n",filename);
	return (1);
error:
	return -1;
}
Example #5
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 #6
0
int com_rename (char * arg)
{

	char from_path[AFP_MAX_PATH], to_path[AFP_MAX_PATH];
	char full_from_path[AFP_MAX_PATH], full_to_path[AFP_MAX_PATH];
	struct stat stbuf;
	int ret;

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

	if (escape_paths(from_path,to_path,arg)) {
		printf("Syntax: mv <fromfile> <tofile>\n");
		goto error;
	}

	get_server_path(from_path,full_from_path);
	get_server_path(to_path,full_to_path);
	printf("Moving from %s to %s\n",full_from_path,full_to_path);

	/* Make sure from_file exists */
	if ((ret=ml_getattr(vol,full_from_path,&stbuf))) {
		printf("Could not find file %s, error was %d\n",
			full_from_path,ret);
		goto error;
	}

	/* Make sure to_file doesn't exist */
	ret=ml_getattr(vol,full_to_path,&stbuf);
	if ((ret==0) && ((stbuf.st_mode & S_IFDIR)==0)) {
		printf("File %s already exists, error: %d\n", 
			full_to_path,ret);
		goto error;
	}

	if ((ret=ml_rename(vol,full_from_path, full_to_path))) goto error;

	return 0;
error:
	return -1;
}
Example #7
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 #8
0
int com_put(char *arg)
{
	int ret, amount_read;
	struct afp_file_info *fp;
	int offset=0;
#define PUT_BUFSIZE 102400
	char buf[PUT_BUFSIZE];
	int fd;
	char server_fullname[AFP_MAX_PATH];
	char * basename;
	uid_t uid;
	gid_t gid;
	struct stat localstat;
	unsigned long long amount_written=0;
	struct timeval starttv,endtv;
	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: put <filename>\n");
		goto error;
	}

	/* FIXME find basename */
	basename=filename;

	get_server_path(basename,server_fullname);

	/* FIXME need a better way to get server's uid/gid */

	uid=getuid();
	gid=getgid();

	if (stat(filename, &localstat)!=0) {
		perror("Opening local file");
	}

	fd = open(filename,O_RDONLY);

	if (fd<0) {
		perror("Opening local file");
		goto error;
	}

	gettimeofday(&starttv,NULL);

	ret = ml_open(vol,server_fullname,O_CREAT | O_RDWR,&fp);

	if (ret<0) {
		printf("Problem opening file %s on server\n",basename);
		goto out;
	}

	/* Now set various permissions */

	ret=ml_chmod(vol,server_fullname,localstat.st_mode);
	if (ret==-ENOSYS) printf("cannot change permissions\n");
	if (ret) {
		printf("Could not change permissions to 0%o\n",
			localstat.st_mode);
	}

	while (1) {
		amount_read=read(fd,buf,PUT_BUFSIZE);
		if (amount_read<0) {
			perror("Reading");
			goto out;
		}
		if (amount_read==0) goto out;
		ret=ml_write(vol,server_fullname,buf,amount_read,
			offset,fp,uid,gid);
		offset+=amount_read;
		amount_written+=amount_read;
		if (ret<0) {
			printf("IO error when writing to server, error %d\n", 
				ret);
			goto out;
		}
	}

/* FIXME time */

out:
	gettimeofday(&endtv,NULL);
	printdiff(&starttv, &endtv,&amount_written);

	close(fd);
	ml_close(vol,server_fullname,fp);
	return 0;

error:
	return -1;

}