From 2f232087da6d513b6f8fcb42a1436ce917e5a613 Mon Sep 17 00:00:00 2001 From: Simon Vetter Date: Wed, 13 Mar 2013 17:00:12 -0700 Subject: [PATCH] use anonymous UAM if no user/password provided in connection request --- cmdline/cmdline_afp.c | 7 +++++-- lib/afp_url.c | 5 ++--- lib/connect.c | 9 +++++++++ lib/dsi.c | 5 ++++- lib/lowlevel.c | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cmdline/cmdline_afp.c b/cmdline/cmdline_afp.c index 5d9de6b..50511f6 100644 --- a/cmdline/cmdline_afp.c +++ b/cmdline/cmdline_afp.c @@ -215,11 +215,14 @@ static int server_subconnect(void) #define BUFFER_SIZE 2048 conn_req = malloc(sizeof(struct afp_connection_request)); + if(!conn_req) + return -1; - memset(conn_req, 0,sizeof(struct afp_connection_request)); + memset(conn_req, 0,sizeof(struct afp_connection_request)); - conn_req->url=url; + 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); diff --git a/lib/afp_url.c b/lib/afp_url.c index 6d4f693..689f0d3 100644 --- a/lib/afp_url.c +++ b/lib/afp_url.c @@ -1,4 +1,3 @@ - #include #include #include @@ -7,7 +6,7 @@ void afp_default_url(struct afp_url *url) { - memset(url,0,sizeof(*url)); + memset(url,0,sizeof(struct afp_url)); url->protocol=TCPIP; url->port=548; } @@ -294,7 +293,7 @@ int afp_parse_url(struct afp_url * url, const char * toparse, int verbose) snprintf(url->username,strlen(p)+1,"%s", p); if (check_username(url->username)) { if (verbose) printf("This isn't a valid username\n"); - return -1;; + return -1; } } diff --git a/lib/connect.c b/lib/connect.c index e35d03f..71a8ee5 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -107,6 +107,15 @@ struct afp_server * afp_server_full_connect (void * priv, struct afp_connection_ goto error; } + //if our user and password strings are both empty and if + //the server supports anonymous logins, pretend we only support + //that as auth will never succeed with such credentials + if(*req->url.username == '\0' && *req->url.password == '\0' + && (uams & UAM_NOUSERAUTHENT)) { + req->uam_mask = UAM_NOUSERAUTHENT; + } + + if ((afp_server_complete_connection(priv, s,address,(unsigned char *) &versions,uams, req->url.username, req->url.password, diff --git a/lib/dsi.c b/lib/dsi.c index 16eaa98..d82aac9 100644 --- a/lib/dsi.c +++ b/lib/dsi.c @@ -64,6 +64,9 @@ int dsi_getstatus(struct afp_server * server) struct afp_rx_buffer rx; int ret; rx.data=malloc(GETSTATUS_BUF_SIZE); + if(rx.data == NULL) + return -1; + rx.maxsize=GETSTATUS_BUF_SIZE; rx.size=0; dsi_setup_header(server,&header,DSI_DSIGetStatus); @@ -192,7 +195,7 @@ int dsi_send(struct afp_server *server, char * msg, int size,int wait,unsigned c afp_wait_for_started_loop(); /* Add request to the queue */ - if (!(new_request=malloc(sizeof(struct dsi_request)))) { + if ((new_request=malloc(sizeof(struct dsi_request))) == NULL) { log_for_client(NULL,AFPFSD,LOG_ERR, "Could not allocate for new request\n"); return -1; diff --git a/lib/lowlevel.c b/lib/lowlevel.c index 43f18df..94f94bc 100644 --- a/lib/lowlevel.c +++ b/lib/lowlevel.c @@ -581,7 +581,7 @@ int ll_getattr(struct afp_volume * volume, const char *path, struct stat *stbuf, if (volume->server->using_version->av_number>=30 && fp.unixprivs.permissions != 0) stbuf->st_mode |= fp.unixprivs.permissions; else - set_nonunix_perms((mode_t *)&stbuf->st_mode,&fp); + set_nonunix_perms((unsigned int *)&stbuf->st_mode,&fp); stbuf->st_uid=fp.unixprivs.uid; stbuf->st_gid=fp.unixprivs.gid;