Exemple #1
0
int
xp_getpwent(Xpnode *nd, char *adminkey, char ***pwent)
{
	char *buf = NULL, **toks;
	int n, bufsize = 8192;
	Xkey *akey = NULL;
	Spuser *auser = NULL;
        Spcfsys *fs = NULL;
        Spcfid *fid = NULL;

	if (adminkey) {
		akey = xauth_privkey_create(adminkey);
		if (!akey)
			goto error;
	}

	if (xp_defaultuser(&auser, &akey) < 0)
		goto error;
	
	fs = xp_node_mount(nd, auser, akey);
	if (!fs) {
		fs = xp_node_mount(nd, NULL, akey);
		if (!fs)
			goto error;
	}

	fid = spc_open(fs, "pwent", Oread);
	if (!fid)
                goto error;

        buf = sp_malloc(sizeof(*buf) * bufsize);
        if (!buf)
                goto error;

	n = spc_read(fid, (u8 *) buf, bufsize-1, 0);
	if (n < 0)
		goto error;
        buf[bufsize] = '\0';
	spc_close(fid);
	spc_umount(fs);
	
	n = tokenize(buf, &toks);
	if (n < 0)
		goto error;
	free(buf);
	xauth_destroy(akey);
	*pwent = toks;
	return n;
error:
	if (fid)
		spc_close(fid);
	if (fs)
		spc_umount(fs);
	if (buf)
		free(buf);
	if (akey)
		xauth_destroy(akey);

        return -1;
}
Exemple #2
0
int
xp_file_copy_finish(Xpcopy *c)
{
	Xpfile *f;

	for(f = c->files; f != NULL; f = f->next) {
		if (f->spcfd) {
			spcfd_remove(f->spcfd);
			f->spcfd = NULL;
		}

		if (f->fid) {
			spc_close(f->fid);
			f->fid = NULL;
		}

		if (f->path) {
			free(f->buf);
			f->buf = NULL;
		}
	}

	free(c);
	return 0;
}
Exemple #3
0
/*----------------------------------------------------------------------+*/
void SPC_Close_Unused(void)
/*----------------------------------------------------------------------+*/
{
  /* Close any and all unused file descriptors */
  int fd;
 
  for (fd = STDERR + 1; fd < max_fds; fd++) spc_close(fd);
}
Exemple #4
0
/*----------------------------------------------------------------------+*/
SPC_Channel_Ptr open_pty_channel_object(SPC_Channel_Ptr channel,
					int iomode,
					XeString hostname)
/*----------------------------------------------------------------------+*/
{

  Wire *tmpwire, *newwire;
  SPC_Channel_Ptr result;
  
  call_parent_method(channel, open, (channel, iomode, hostname), result);

  if(result==SPC_ERROR)
    return(SPC_ERROR);

  /* We know that we are going to use one of STDIN, STDOUT, or STDERR
     (or else we would be a NOIO channel), so allocate at least one
     pty pair */

  if(!(tmpwire=getpty(NULL)))
    return(SPC_ERROR);

  if (IS_SPCIO_STDIN(iomode)) {
    channel->wires[STDIN]=tmpwire;
  }
  
  if (IS_SPCIO_STDOUT(iomode)) {
    channel->wires[STDOUT]=tmpwire;
  }
  
  if (IS_SPCIO_SEPARATE(iomode)) {
    if(!(newwire=getpty(tmpwire))) {
      spc_close(tmpwire->fd[MASTER_SIDE]);
      free_wire(tmpwire);
      return(SPC_ERROR);
    } else
      tmpwire=newwire;
  }
  
  if (IS_SPCIO_STDERR(iomode)) {
    channel->wires[STDERR]=tmpwire;
  }
  
  channel->wire_list=tmpwire;
  
  /* set up the channel file descriptors */

  channel->file_descs[STDIN]  = (channel->wires[STDIN]) ->fd[MASTER_SIDE];
  channel->file_descs[STDOUT] = (channel->wires[STDOUT])->fd[MASTER_SIDE];
  channel->file_descs[STDERR] = (channel->wires[STDERR])->fd[MASTER_SIDE];

  for(tmpwire=channel->wire_list; tmpwire; tmpwire=tmpwire->next) {
    init_termio(&tmpwire->master_termio);
    init_termio(&tmpwire->slave_termio);
  }
  
  return(channel);

}
Exemple #5
0
/*----------------------------------------------------------------------+*/
void SPC_Close_Connection(SPC_Connection_Ptr connection)
/*----------------------------------------------------------------------+*/
{
  SPC_Channel_Ptr channel;
  SPC_Channel_Ptr next;
  SPC_Connection_Ptr trail, ptr;

  /* We have to be careful here.  SPC_Input_Handler may call the users
     termination handler, which in turn might close the channel, which
     may deallocate the channel.  Therefore, we grab the next channel
     from the list while we are still alive. */

  _DtSvcProcessLock();
  channel=spc_activation_list;
  connection->connected = FALSE;
  
  while(channel) {
    next=channel->next;
    if(channel->connection == connection) {
      if(!IS_SPCIO_DELAY_CLOSE(channel->IOMode))
	SPC_Channel_Terminated(channel);
      channel->connection = NULL;
    }
    channel=next;
  }
  
  SPC_XtRemoveInput(&connection->termination_id, SPC_Terminator);

  spc_close(connection->sid);
  connection->sid = (-1);

  if (connection->hostinfo)
      XeFree(connection->hostinfo);

  /* Remove the connection from the connection list */

  if(connection_list == connection)
    connection_list = connection->next;
  else {
    trail = connection_list;
    while(trail) {
      ptr = trail->next;
      if(ptr == connection) {
	trail->next = ptr->next;
	break;
      }
      trail=ptr;
    }
    if(!trail) {
      /* Here if no such connection found. */
    }
  }

  free((char *)connection);
  _DtSvcProcessUnlock();
}
int
main(int argc, char **argv)
{
	int c;
	char *addr;
	char *uname, *path;
	Spuser *user;
	Spcfsys *fs;
	Spcfid *fid;

	user = sp_uid2user(geteuid());
	if (!user) {
		fprintf(stderr, "cannot retrieve user %d\n", geteuid());
		exit(1);
	}

	uname = user->uname;
	while ((c = getopt(argc, argv, "dp:")) != -1) {
		switch (c) {
		case 'd':
			spc_chatty = 1;
			break;

		case 'u':
			uname = optarg;
			break;

		default:
			usage();
		}
	}

	

	if (argc - optind < 2)
		usage();

	addr = argv[optind];
	path = argv[optind+1];

	fs = spc_netmount(addr, uname, 564);
	fid = spc_open(fs, path, Oread);
	if (!fid) {
		fprintf(stderr, "cannot open\n");
		exit(1);
	}

	ispcfd = spcfd_add(fid, in_notify, fid);
	spcfd_start_loop();
	spc_close(fid);
	spc_umount(fs);

	exit(0);
}
Exemple #7
0
void
xp_file_destroy(Xpfile *f)
{
	if (!f)
		return;

	if (f->spcfd)
		spcfd_remove(f->spcfd);
	if (f->fid)
		spc_close(f->fid);
	if (f->fd >= 0)
		close(f->fd);

	free(f->buf);
	free(f->name);
	free(f->path);
	free(f);
}
Exemple #8
0
int
main(int argc, char **argv)
{
	int ecode;
	int c;
	char *addr;
	char *ename, *path;
	Spuser *user;
	Spcfsys *fs;

	user = sp_unix_users->uid2user(sp_unix_users, geteuid());
	while ((c = getopt(argc, argv, "dp:")) != -1) {
		switch (c) {
		case 'd':
			spc_chatty = 1;
			break;

		case 'u':
			user = sp_unix_users->uname2user(sp_unix_users, optarg);
			break;

		default:
			usage();
		}
	}
	
	if (!user) {
		fprintf(stderr, "cannot retrieve user %d\n", geteuid());
		exit(1);
	}

	if (argc - optind < 2)
		usage();

	addr = argv[optind];
	path = argv[optind+1];

	fs = spc_netmount(addr, user, 564, NULL, NULL);
	fid = spc_open(fs, path, Oread);
	if (!fid) {
		fprintf(stderr, "cannot open\n");
		exit(1);
	}

	if (readnb(buf1) < 0)
		goto error;

	if (readnb(buf2) < 0)
		goto error;

	if (readnb(buf3) < 0)
		goto error;

	if (readnb(buf4) < 0)
		goto error;

	while (done < 4)
		sp_poll_once();

	spc_close(fid);
	spc_umount(fs);

	return 0;

error:
	sp_rerror(&ename, &ecode);
	fprintf(stderr, "Error: %s\n", ename);
	return -1;

}
Exemple #9
0
int
main(int argc, char **argv)
{
	int i, n, off;
	int c;
	char *addr;
	char *path;
	Spuser *user;
	Spcfsys *fs;
	Spcfid *fid;
	char buf[512];

	user = sp_unix_users->uid2user(sp_unix_users, geteuid());
	while ((c = getopt(argc, argv, "dp:")) != -1) {
		switch (c) {
		case 'd':
			spc_chatty = 1;
			break;

		case 'u':
			user = sp_unix_users->uname2user(sp_unix_users, optarg);
			break;

		default:
			usage();
		}
	}
	
	if (!user) {
		fprintf(stderr, "cannot retrieve user %d\n", geteuid());
		exit(1);
	}

	if (argc - optind < 2)
		usage();

	addr = argv[optind];
	path = argv[optind+1];

	fs = spc_netmount(addr, user, 564, NULL, NULL);
	fid = spc_open(fs, path, Oread);
	if (!fid) {
		fprintf(stderr, "cannot open\n");
		exit(1);
	}

	off = 0;
	while ((n = spc_read(fid, (u8*) buf, sizeof(buf), off)) > 0) {
		i = write(1, buf, n);
		if (i != n) {
			fprintf(stderr, "error writing\n");
			exit(1);
		}

		off += n;
	}
			
	spc_close(fid);
	spc_umount(fs);

	exit(0);
}