summaryrefslogtreecommitdiffstats
path: root/sys/netsmb/smb_conn.c
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2003-08-23 21:43:33 +0000
committermarcel <marcel@FreeBSD.org>2003-08-23 21:43:33 +0000
commit5d4c069fc5b5446c1e88acf5a04255215d85a15a (patch)
tree9740f1cb5fa3620cec720b3ec06817bb11d02a6c /sys/netsmb/smb_conn.c
parent7aa303c874a0cec013236a47988ea5ea3809c622 (diff)
downloadFreeBSD-src-5d4c069fc5b5446c1e88acf5a04255215d85a15a.zip
FreeBSD-src-5d4c069fc5b5446c1e88acf5a04255215d85a15a.tar.gz
Rewrite the code that uses the try/catch paradigm implemented by
goto and abstracted by the itry, ithrow and icatch macros (among others). The problem with this code is that it doesn't compile on ia64. The compiler is sufficiently confused that it inserts a call to __ia64_save_stack_nonlock(). This is a magic function that saves enough of the stack to allow for non-local gotos, such as would be the case for nested functions. Since it's not a compiler defined function, it needs a runtime implementation. This we have not in a standalone compilation as is the kernel. There's no indication that the compiler is not confused on other platforms. It's likely that saving the stack in those cases is trivial enough that the compiler doesn't need to off-load the complexity to a runtime function. The code is believed to be correctly translated, but has not been tested. The overall structure remained the same, except that it's made explicit. The macros that implement the try/catch construct have been removed to avoid reintroduction of their use. It's not a good idea. In general the rewritten code is slightly more optimal in that it doesn't need as much stack space and generally is smaller in size. Found by: LINT
Diffstat (limited to 'sys/netsmb/smb_conn.c')
-rw-r--r--sys/netsmb/smb_conn.c151
1 files changed, 83 insertions, 68 deletions
diff --git a/sys/netsmb/smb_conn.c b/sys/netsmb/smb_conn.c
index 9542160..23eb4be 100644
--- a/sys/netsmb/smb_conn.c
+++ b/sys/netsmb/smb_conn.c
@@ -128,46 +128,47 @@ smb_sm_lookupint(struct smb_vcspec *vcspec, struct smb_sharespec *shspec,
error = smb_vc_lock(vcp, LK_EXCLUSIVE, td);
if (error)
continue;
- itry {
- if ((vcp->obj.co_flags & SMBV_PRIVATE) ||
- !CONNADDREQ(vcp->vc_paddr, vcspec->sap) ||
- strcmp(vcp->vc_username, vcspec->username) != 0)
- ithrow(1);
- if (vcspec->owner != SMBM_ANY_OWNER) {
- if (vcp->vc_uid != vcspec->owner)
- ithrow(1);
- } else
- exact = 0;
- if (vcspec->group != SMBM_ANY_GROUP) {
- if (vcp->vc_grp != vcspec->group)
- ithrow(1);
- } else
- exact = 0;
-
- if (vcspec->mode & SMBM_EXACT) {
- if (!exact ||
- (vcspec->mode & SMBM_MASK) != vcp->vc_mode)
- ithrow(1);
- }
- if (smb_vc_access(vcp, scred, vcspec->mode) != 0)
- ithrow(1);
- vcspec->ssp = NULL;
- if (shspec)
- ithrow(smb_vc_lookupshare(vcp, shspec, scred, &vcspec->ssp));
- error = 0;
- break;
- } icatch(error) {
- smb_vc_unlock(vcp, 0, td);
- } ifinally {
- } iendtry;
- if (error == 0)
- break;
+
+ if ((vcp->obj.co_flags & SMBV_PRIVATE) ||
+ !CONNADDREQ(vcp->vc_paddr, vcspec->sap) ||
+ strcmp(vcp->vc_username, vcspec->username) != 0)
+ goto err1;
+ if (vcspec->owner != SMBM_ANY_OWNER) {
+ if (vcp->vc_uid != vcspec->owner)
+ goto err1;
+ } else
+ exact = 0;
+ if (vcspec->group != SMBM_ANY_GROUP) {
+ if (vcp->vc_grp != vcspec->group)
+ goto err1;
+ } else
+ exact = 0;
+ if (vcspec->mode & SMBM_EXACT) {
+ if (!exact || (vcspec->mode & SMBM_MASK) !=
+ vcp->vc_mode)
+ goto err1;
+ }
+ if (smb_vc_access(vcp, scred, vcspec->mode) != 0)
+ goto err1;
+ vcspec->ssp = NULL;
+ if (shspec) {
+ error = (int)smb_vc_lookupshare(vcp, shspec, scred,
+ &vcspec->ssp);
+ if (error)
+ goto fail;
+ }
+ error = 0;
+ break;
+ err1:
+ error = 1;
+ fail:
+ smb_vc_unlock(vcp, 0, td);
}
if (vcp) {
smb_vc_ref(vcp);
*vcpp = vcp;
}
- return error;
+ return (error);
}
int
@@ -413,39 +414,53 @@ smb_vc_create(struct smb_vcspec *vcspec,
vcp->vc_grp = gid;
smb_sl_init(&vcp->vc_stlock, "vcstlock");
- error = 0;
- itry {
- vcp->vc_paddr = dup_sockaddr(vcspec->sap, 1);
- ierror(vcp->vc_paddr == NULL, ENOMEM);
-
- vcp->vc_laddr = dup_sockaddr(vcspec->lap, 1);
- ierror(vcp->vc_laddr == NULL, ENOMEM);
-
- ierror((vcp->vc_pass = smb_strdup(vcspec->pass)) == NULL, ENOMEM);
-
- vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain : "NODOMAIN");
- ierror(vcp->vc_domain == NULL, ENOMEM);
-
- ierror((vcp->vc_srvname = smb_strdup(vcspec->srvname)) == NULL, ENOMEM);
- ierror((vcp->vc_username = smb_strdup(vcspec->username)) == NULL, ENOMEM);
-
- ithrow(iconv_open("tolower", vcspec->localcs, &vcp->vc_tolower));
- ithrow(iconv_open("toupper", vcspec->localcs, &vcp->vc_toupper));
- if (vcspec->servercs[0]) {
- ithrow(iconv_open(vcspec->servercs, vcspec->localcs,
- &vcp->vc_toserver));
- ithrow(iconv_open(vcspec->localcs, vcspec->servercs,
- &vcp->vc_tolocal));
- }
-
- ithrow(smb_iod_create(vcp));
- *vcpp = vcp;
- smb_co_addchild(&smb_vclist, VCTOCP(vcp));
- } icatch(error) {
- smb_vc_put(vcp, scred);
- } ifinally {
- } iendtry;
- return error;
+ error = ENOMEM;
+
+ vcp->vc_paddr = dup_sockaddr(vcspec->sap, 1);
+ if (vcp->vc_paddr == NULL)
+ goto fail;
+ vcp->vc_laddr = dup_sockaddr(vcspec->lap, 1);
+ if (vcp->vc_laddr == NULL)
+ goto fail;
+ vcp->vc_pass = smb_strdup(vcspec->pass);
+ if (vcp->vc_pass == NULL)
+ goto fail;
+ vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain :
+ "NODOMAIN");
+ if (vcp->vc_domain == NULL)
+ goto fail;
+ vcp->vc_srvname = smb_strdup(vcspec->srvname);
+ if (vcp->vc_srvname == NULL)
+ goto fail;
+ vcp->vc_username = smb_strdup(vcspec->username);
+ if (vcp->vc_username == NULL)
+ goto fail;
+ error = (int)iconv_open("tolower", vcspec->localcs, &vcp->vc_tolower);
+ if (error)
+ goto fail;
+ error = (int)iconv_open("toupper", vcspec->localcs, &vcp->vc_toupper);
+ if (error)
+ goto fail;
+ if (vcspec->servercs[0]) {
+ error = (int)iconv_open(vcspec->servercs, vcspec->localcs,
+ &vcp->vc_toserver);
+ if (error)
+ goto fail;
+ error = (int)iconv_open(vcspec->localcs, vcspec->servercs,
+ &vcp->vc_tolocal);
+ if (error)
+ goto fail;
+ }
+ error = (int)smb_iod_create(vcp);
+ if (error)
+ goto fail;
+ *vcpp = vcp;
+ smb_co_addchild(&smb_vclist, VCTOCP(vcp));
+ return (0);
+
+ fail:
+ smb_vc_put(vcp, scred);
+ return (error);
}
static void
OpenPOWER on IntegriCloud