static int server_subconnect(void) { struct afp_connection_request * conn_req; #define BUFFER_SIZE 2048 conn_req = malloc(sizeof(struct afp_connection_request)); memset(conn_req, 0,sizeof(struct afp_connection_request)); conn_req->url=url; conn_req->url.requested_version=31; if (strlen(url.uamname)>0) { if ((conn_req->uam_mask = find_uam_by_name(url.uamname))==0) { printf("I don't know about UAM %s\n",url.uamname); return -1; } } else { conn_req->uam_mask=default_uams_mask(); } if ((server=afp_server_full_connect(NULL, conn_req))==NULL) { goto error; } printf("Connected to server %s using UAM \"%s\"\n", server->server_name_printable, uam_bitmap_to_string(server->using_uam)); free(conn_req); return 0; error: free(conn_req); printf("Could not connect\n"); return -1; }
static int server_subconnect(struct afp_url url) { struct afp_connection_request *conn_req; struct afp_server * server = NULL; conn_req = malloc( sizeof(struct afp_connection_request) ); server = malloc( sizeof(struct afp_server) ); memset(conn_req, 0, sizeof(struct afp_connection_request)); conn_req->url=url; conn_req->url.requested_version=31; writeError(ERR_DEBUG_MODULE, "[%s] AFP connection - username: %s password: %s server: %s", MODULE_NAME, url.username, url.password, url.servername); if (strlen(url.uamname) > 0) { if ((conn_req->uam_mask = find_uam_by_name(url.uamname)) == 0) { writeError(ERR_ERROR, "[%s] Unknown UAM: %s", MODULE_NAME, url.uamname); FREE(conn_req); FREE(server); return FAILURE; } } else { conn_req->uam_mask=default_uams_mask(); } writeError(ERR_DEBUG_MODULE, "[%s] Initiating connection attempt.", MODULE_NAME); if ((server = afp_server_full_connect(NULL, conn_req)) == NULL) { FREE(conn_req); FREE(server); return FAILURE; } writeError(ERR_DEBUG_MODULE, "[%s] Connected to server: %s via UAM: %s", MODULE_NAME, server->server_name_printable, uam_bitmap_to_string(server->using_uam)); FREE(conn_req); FREE(server); return SUCCESS; }
static int server_subconnect(struct afp_url url) { struct afp_connection_request *conn_req; struct afp_server *server = NULL; conn_req = malloc(sizeof(struct afp_connection_request)); // server = malloc(sizeof(struct afp_server)); memset(conn_req, 0, sizeof(struct afp_connection_request)); conn_req->url = url; conn_req->url.requested_version = 31; //fprintf(stderr, "AFP connection - username: %s password: %s server: %s\n", url.username, url.password, url.servername); if (strlen(url.uamname) > 0) { if ((conn_req->uam_mask = find_uam_by_name(url.uamname)) == 0) { fprintf(stderr, "[ERROR] Unknown UAM: %s", url.uamname); FREE(conn_req); FREE(server); return -1; } } else { conn_req->uam_mask = default_uams_mask(); } //fprintf(stderr, "Initiating connection attempt.\n"); if ((server = afp_server_full_connect(NULL, conn_req)) == NULL) { FREE(conn_req); // FREE(server); return -1; } //fprintf(stderr, "Connected to server: %s via UAM: %s\n", server->server_name_printable, uam_bitmap_to_string(server->using_uam)); FREE(conn_req); FREE(server); return 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; }
static int do_mount(int argc, char ** argv) { int c; int option_index=0; struct afp_server_mount_request * req; int optnum; unsigned int uam_mask=default_uams_mask(); struct option long_options[] = { {"afpversion",1,0,'v'}, {"volumepassword",1,0,'V'}, {"user",1,0,'u'}, {"pass",1,0,'p'}, {"port",1,0,'o'}, {"uam",1,0,'a'}, {"map",1,0,'m'}, {0,0,0,0}, }; if (argc<4) { usage(); return -1; } outgoing_len=sizeof(struct afp_server_mount_request)+1; req = (void *) outgoing_buffer+1; memset(outgoing_buffer,0,outgoing_len); outgoing_buffer[0]=AFP_SERVER_COMMAND_MOUNT; req->url.port=548; req->map=AFP_MAPPING_UNKNOWN; while(1) { optnum++; c = getopt_long(argc,argv,"a:u:m:o:p:v:V:", long_options,&option_index); if (c==-1) break; switch(c) { case 'a': if (strcmp(optarg,"guest")==0) uam_mask=UAM_NOUSERAUTHENT; else uam_mask=uam_string_to_bitmap(optarg); break; case 'm': req->map=map_string_to_num(optarg); break; case 'u': snprintf(req->url.username,AFP_MAX_USERNAME_LEN,"%s",optarg); break; case 'o': req->url.port=strtol(optarg,NULL,10); break; case 'p': snprintf(req->url.password,AFP_MAX_PASSWORD_LEN,"%s",optarg); break; case 'V': snprintf(req->url.volpassword,9,"%s",optarg); break; case 'v': req->url.requested_version=strtol(optarg,NULL,10); break; } } if (strcmp(req->url.password, "-") == 0) { char *p = getpass("AFP Password: "******"%s",p); } if (strcmp(req->url.volpassword, "-") == 0) { char *p = getpass("Password for volume: "); if (p) snprintf(req->url.volpassword,9,"%s",p); } optnum=optind+1; if (optnum>=argc) { printf("No volume or mount point specified\n"); return -1; } if (sscanf(argv[optnum++],"%[^':']:%[^':']", req->url.servername,req->url.volumename)!=2) { printf("Incorrect server:volume specification\n"); return -1; } if (uam_mask==0) { printf("Unknown UAM\n"); return -1; } req->uam_mask=uam_mask; req->volume_options=DEFAULT_MOUNT_FLAGS; if (optnum>=argc) { printf("No mount point specified\n"); return -1; } snprintf(req->mountpoint,255,"%s",argv[optnum++]); return 0; }