smb - Tear out C++-wannabe exception magic
authorSamuel J. Greear <sjg@thesjg.com>
Tue, 20 Dec 2011 19:32:14 +0000 (12:32 -0700)
committerSamuel J. Greear <sjg@thesjg.com>
Tue, 20 Dec 2011 19:32:14 +0000 (12:32 -0700)
sys/netproto/smb/smb_conn.c
sys/netproto/smb/smb_iod.c
sys/netproto/smb/smb_subr.h

index 383a318..3ec6a74 100644 (file)
@@ -138,40 +138,40 @@ smb_sm_lookupint(struct smb_vcspec *vcspec, struct smb_sharespec *shspec,
                error = smb_vc_lock(vcp, LK_EXCLUSIVE);
                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);
-               } ifinally {
-               } iendtry;
-               if (error == 0)
-                       break;
+
+               error = 1;
+               if ((vcp->obj.co_flags & SMBV_PRIVATE) ||
+                   !CONNADDREQ(vcp->vc_paddr, vcspec->sap) ||
+                   strcmp(vcp->vc_username, vcspec->username) != 0)
+                       goto unlock;
+               if (vcspec->owner != SMBM_ANY_OWNER) {
+                       if (vcp->vc_uid != vcspec->owner)
+                               goto unlock;
+               } else
+                       exact = 0;
+               if (vcspec->group != SMBM_ANY_GROUP) {
+                       if (vcp->vc_grp != vcspec->group)
+                               goto unlock;
+               } else
+                       exact = 0;
+
+               if (vcspec->mode & SMBM_EXACT) {
+                       if (!exact ||
+                           (vcspec->mode & SMBM_MASK) != vcp->vc_mode)
+                               goto unlock;
+               }
+               if (smb_vc_access(vcp, scred, vcspec->mode) != 0)
+                       goto unlock;
+               vcspec->ssp = NULL;
+               if (shspec) {
+                       error = smb_vc_lookupshare(vcp, shspec, scred, &vcspec->ssp);
+                       if (error != 0)
+                               goto unlock;
+               }
+               error = 0;
+               break;
+unlock:
+               smb_vc_unlock(vcp, 0);
        }
        if (vcp) {
                smb_vc_ref(vcp);
@@ -454,38 +454,61 @@ smb_vc_create(struct smb_vcspec *vcspec,
        vcp->vc_grp = gid;
 
        smb_sl_init(&vcp->vc_stlock, "vcstlock");
-       error = 0;
-       itry {
+
+       do {
+               error = ENOMEM;
                vcp->vc_paddr = dup_sockaddr(vcspec->sap);
-               ierror(vcp->vc_paddr == NULL, ENOMEM);
+               if (vcp->vc_paddr == NULL)
+                       break;
 
                vcp->vc_laddr = dup_sockaddr(vcspec->lap);
-               ierror(vcp->vc_laddr == NULL, ENOMEM);
+               if (vcp->vc_laddr == NULL)
+                       break;
 
-               ierror((vcp->vc_pass = smb_strdup(vcspec->pass)) == NULL, ENOMEM);
+               vcp->vc_pass = smb_strdup(vcspec->pass);
+               if (vcp->vc_pass == NULL)
+                       break;
 
-               vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain : "NODOMAIN");
-               ierror(vcp->vc_domain == NULL, ENOMEM);
+               vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain
+                                                                 : "NODOMAIN");
+               if (vcp->vc_domain == NULL)
+                       break;
+
+               vcp->vc_srvname = smb_strdup(vcspec->srvname);
+               if (vcp->vc_srvname == NULL)
+                       break;
+               vcp->vc_username = smb_strdup(vcspec->username);
+               if (vcp->vc_username == NULL)
+                       break;
 
-               ierror((vcp->vc_srvname = smb_strdup(vcspec->srvname)) == NULL, ENOMEM);
-               ierror((vcp->vc_username = smb_strdup(vcspec->username)) == NULL, ENOMEM);
+               error = iconv_open("tolower", vcspec->localcs, &vcp->vc_tolower);
+               if (error != 0)
+                       break;
+               error = iconv_open("toupper", vcspec->localcs, &vcp->vc_toupper);
+               if (error != 0)
+                       break;
 
-               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));
+                       error = iconv_open(vcspec->servercs, vcspec->localcs,
+                           &vcp->vc_toserver);
+                       if (error != 0)
+                               break;
+                       error = iconv_open(vcspec->localcs, vcspec->servercs,
+                           &vcp->vc_tolocal);
+                       if (error != 0)
+                               break;
                }
 
-               ithrow(smb_iod_create(vcp));
+               error = smb_iod_create(vcp);
+               if (error != 0)
+                       break;
                *vcpp = vcp;
                smb_co_addchild(&smb_vclist, VCTOCP(vcp));
-       } icatch(error) {
+               error = 0;
+       } while (0);
+
+       if (error)
                smb_vc_put(vcp, scred);
-       } ifinally {
-       } iendtry;
        return error;
 }
 
index 9a16a1e..fba13b0 100644 (file)
@@ -146,29 +146,46 @@ smb_iod_connect(struct smbiod *iod)
                break;
        }
        vcp->vc_genid++;
-       error = 0;
-       itry {
-               ithrow(SMB_TRAN_CREATE(vcp, td));
+
+       do {
+               error = SMB_TRAN_CREATE(vcp, td);
+               if (error != 0)
+                       break;
                SMBIODEBUG("tcreate\n");
+
                if (vcp->vc_laddr) {
-                       ithrow(SMB_TRAN_BIND(vcp, vcp->vc_laddr, td));
+                       error = SMB_TRAN_BIND(vcp, vcp->vc_laddr, td);
+                       if (error != 0)
+                               break;
                }
                SMBIODEBUG("tbind\n");
-               ithrow(SMB_TRAN_CONNECT(vcp, vcp->vc_paddr, td));
+
+               error = SMB_TRAN_CONNECT(vcp, vcp->vc_paddr, td);
+               if (error != 0)
+                       break;
                SMB_TRAN_SETPARAM(vcp, SMBTP_SELECTID, &iod->iod_flags);
                iod->iod_state = SMBIOD_ST_TRANACTIVE;
                SMBIODEBUG("tconnect\n");
+
 /*             vcp->vc_mid = 0;*/
-               ithrow(smb_smb_negotiate(vcp, &iod->iod_scred));
+
+               error = smb_smb_negotiate(vcp, &iod->iod_scred);
+               if (error != 0)
+                       break;
                SMBIODEBUG("snegotiate\n");
-               ithrow(smb_smb_ssnsetup(vcp, &iod->iod_scred));
+
+               error = smb_smb_ssnsetup(vcp, &iod->iod_scred);
+               if (error != 0)
+                       break;
                iod->iod_state = SMBIOD_ST_VCACTIVE;
                SMBIODEBUG("completed\n");
+
                smb_iod_invrq(iod);
-       } icatch(error) {
+               error = 0;
+       } while (0);
+
+       if (error)
                smb_iod_dead(iod);
-       } ifinally {
-       } iendtry;
        return error;
 }
 
index 4067cf8..5f0cbc7 100644 (file)
@@ -89,41 +89,6 @@ void m_dumpm(struct mbuf *m);
 
 #define SMB_STRFREE(p) do { if (p) smb_strfree(p); } while(0)
 
-/*
- * The simple try/catch/finally interface.
- * With GCC it is possible to allow more than one try/finally block per
- * function, but we'll avoid it to maintain portability.
- */
-#define itry           {                                               \
-                               int _tval;                              \
-
-#define icatch(var)                                                    \
-                               goto _finlab;                           \
-                               (void)&&_catchlab;                      \
-                               _catchlab:                              \
-                               var = _tval;
-
-#define ifinally               (void)&&_finlab;                        \
-                               _finlab:                                
-#define iendtry                }
-
-#define inocatch                                                       \
-                               goto _finlab;                           \
-                               (void)&&_catchlab;                      \
-                               _catchlab:                              \
-
-#define ithrow(t)      do {                                            \
-                               if ((_tval = (int)(t)) != 0)            \
-                                       goto _catchlab;                 \
-                       } while (0)
-
-#define ierror(t,e)    do {                                            \
-                               if (t) {                                \
-                                       _tval = e;                      \
-                                       goto _catchlab;                 \
-                               }                                       \
-                       } while (0)
-
 typedef u_int16_t      smb_unichar;
 typedef        smb_unichar     *smb_uniptr;