Beispiel #1
0
static int test_one_url(char * url_string, 
	enum {TCPIP,AT} protocol, 
	char * username, 
	char * uamname,
	char * password,
	char * servername, 	
	int port,
	char * volumename, 
	char * path)
{
	struct afp_url valid_url;
	afp_default_url(&valid_url);
	valid_url.protocol=protocol;
	sprintf(valid_url.servername,servername);
	sprintf(valid_url.volumename,volumename);
	sprintf(valid_url.path,path);
	sprintf(valid_url.username,username);
	sprintf(valid_url.password,password);
	sprintf(valid_url.uamname,uamname);
	valid_url.port=port;

	if (afp_url_validate(url_string,&valid_url)) 
		printf("* Could not parse %s\n",url_string);
	else
		printf("* Parsed %s correctly\n",url_string);

	return 0;
}
Beispiel #2
0
int tryLogin(int hSocket, _MODULE_DATA* _psSessionData, sLogin** psLogin, char* szLogin, char* szPassword)
{
  int iRet;
  unsigned char* szTmp = NULL;
  unsigned char* szEncodedAuth = NULL;
  int nSendBufferSize = 0;
  struct afp_url tmpurl;
 
  /* Build AFP authentication request */ 
  libafpclient_register(&afpclient);  
  afp_main_quick_startup(NULL);  
  init_uams();
  afp_default_url(&tmpurl);

  memcpy(&tmpurl.servername, (*psLogin)->psServer->pHostIP, AFP_SERVER_NAME_LEN); 
  memcpy(&tmpurl.username, szLogin, AFP_MAX_USERNAME_LEN);
  memcpy(&tmpurl.password, szPassword, AFP_MAX_PASSWORD_LEN);

  if ( server_subconnect(tmpurl) == SUCCESS )
  {
    writeError(ERR_DEBUG_MODULE, "[%s] Login attempt successful.", MODULE_NAME);
    (*psLogin)->iResult = LOGIN_RESULT_SUCCESS;
    iRet = MSTATE_EXITING;
  } 
  else
  {
    writeError(ERR_DEBUG_MODULE, "[%s] Login attempt failed.", MODULE_NAME);
    (*psLogin)->iResult = LOGIN_RESULT_FAIL;
    iRet = MSTATE_RUNNING;
  }

  setPassResult((*psLogin), szPassword);
  
  return(iRet);
}
Beispiel #3
0
int com_connect(char * arg)
{
	struct afp_url tmpurl;
	if (!arg)
		arg = "";

	if (server) {
		printf("You're already connected to a server\n");
		goto error;
	}

	afp_default_url(&tmpurl);

	/* First, try to parse the URL */
	
	if (afp_parse_url(&tmpurl,arg,0)!=0) {
		/* Okay, this isn't a real URL */
		printf("Could not parse url, let me see if this is a server name...\n");
		if (gethostbyname(arg)) 
			memcpy(&url.servername,arg,AFP_SERVER_NAME_LEN);
		else {
			printf("Cannot understand server name or url %s\n",arg);
			return -1;
		}
	} else {
		url=tmpurl;

	}
	cmdline_getpass();


	if (server_subconnect()) {
		printf("Could not connect\n");
		goto error;
	};

	connect_volume(url.volumename);

	return 0;
error:
	return -1;

}
Beispiel #4
0
int start_afp(int s, char *ip, int port, unsigned char options, char *miscptr, FILE * fp) {
  char *empty = "";
  char *login, *pass, mlogin[AFP_MAX_USERNAME_LEN], mpass[AFP_MAX_PASSWORD_LEN];
  struct afp_url tmpurl;

  /* Build AFP authentication request */
  libafpclient_register(&afpclient);
  afp_main_quick_startup(NULL);
  init_uams();
  afp_default_url(&tmpurl);


  if (strlen(login = hydra_get_next_login()) == 0)
    login = empty;
  if (strlen(pass = hydra_get_next_password()) == 0)
    pass = empty;

  strncpy(tmpurl.servername, hydra_address2string(ip), AFP_SERVER_NAME_LEN - 1);
  tmpurl.servername[AFP_SERVER_NAME_LEN] = 0;
  strncpy(mlogin, login, AFP_MAX_USERNAME_LEN - 1);
  mlogin[AFP_MAX_USERNAME_LEN - 1] = 0;
  strncpy(mpass, pass, AFP_MAX_PASSWORD_LEN - 1);
  mpass[AFP_MAX_PASSWORD_LEN - 1] = 0;
  memcpy(&tmpurl.username, mlogin, AFP_MAX_USERNAME_LEN);
  memcpy(&tmpurl.password, mpass, AFP_MAX_PASSWORD_LEN);

  if (server_subconnect(tmpurl) == 0) {
    hydra_report_found_host(port, ip, "afp", fp);
    hydra_completed_pair_found();
    if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
      return 3;
    return 2;
  } else {

    hydra_completed_pair();
    if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
      return 2;
  }
  return 1;
}
Beispiel #5
0
static int handle_mount_afp(int argc, char * argv[])
{
	struct afp_server_mount_request * req = (void *) outgoing_buffer+1;
	unsigned int uam_mask=default_uams_mask();
	char * urlstring, * mountpoint;
	char * volpass = NULL;
	int readonly=0;

	if (argc<2) {
		mount_afp_usage();
		return -1;
	}
	if (strncmp(argv[1],"-o",2)==0) {
		char * p = argv[2], *q;
		char command[256];
		struct passwd * passwd;
		struct group * group;
		
		do {
			memset(command,0,256);
			
			if ((q=strchr(p,','))) 
				strncpy(command,p,(q-p));
			else 
				strcpy(command,p);

			if (strncmp(command,"volpass="******"user="******"Unknown user %s\n",p);
					return -1;
				}
				uid=passwd->pw_uid;
				if (geteuid()!=uid)
					changeuid=1;
			} else if (strncmp(command,"group=",6)==0) {
				p=command+6;
				if ((group=getgrnam(p))==NULL) {
					printf("Unknown group %s\n",p);
					return -1;
				}
				gid=group->gr_gid;
				changegid=1;
			} else if (strcmp(command,"rw")==0) {
				/* Don't do anything */
			} else if (strcmp(command,"ro")==0) {
				readonly=1;
			} else {
				printf("Unknown option %s, skipping\n",command);
			}
		

			if (q) p=q+1;
			else p=NULL;

		} while (p);

		urlstring=argv[3];
		mountpoint=argv[4];
	} else {
		urlstring=argv[1];
		mountpoint=argv[2];
	}


	outgoing_len=sizeof(struct afp_server_mount_request)+1;
	memset(outgoing_buffer,0,outgoing_len);

	afp_default_url(&req->url);

	req->changeuid=changeuid;

	req->volume_options|=DEFAULT_MOUNT_FLAGS;
	if (readonly) req->volume_options |= VOLUME_EXTRA_FLAGS_READONLY;
	req->uam_mask=uam_mask;

	outgoing_buffer[0]=AFP_SERVER_COMMAND_MOUNT;
	req->map=AFP_MAPPING_UNKNOWN;
	snprintf(req->mountpoint,255,"%s",mountpoint);
	if (afp_parse_url(&req->url,urlstring,0) !=0) 
	{
		printf("Could not parse URL\n");
		return -1;
	}
	if (strcmp(req->url.password,"-")==0) {
		char *p = getpass("AFP Password: "******"%s",p);
	}

	if (volpass && (strcmp(volpass,"-")==0)) {
		volpass  = getpass("Password for volume: ");
	}
	if (volpass)
		snprintf(req->url.volpassword,9,"%s",volpass);

        return 0;
}