* gss-client.c: change if (this) if (that) => if (this && that)
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 27 Feb 2004 05:04:59 +0000 (05:04 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 27 Feb 2004 05:04:59 +0000 (05:04 +0000)
ticket: new
target_version: next
tags: pullup

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16136 dc483132-0cff-0310-8789-dd5450dbe970

src/appl/gss-sample/ChangeLog
src/appl/gss-sample/gss-client.c

index fae96843211d71c330b9f12f0fc4fcc6129b3b2c..d3bf699826931e6e324e5adab2af541e26310625 100644 (file)
@@ -1,3 +1,7 @@
+2003-02-26  Jeffrey Altman <jaltman@mit.edu>
+
+    * gss-client.c: merge if (this) if (that) into if (this && that)
+
 2004-02-10  Jeffrey Altman <jaltman@mit.edu>
 
     * gss-client.c: Remove extraneous parameters from 
index 93b5eb35e0f3d45272d055378e4809a1468aa54c..f7b578a19052e68833bf20c8a4fb9b53f31abe86 100644 (file)
@@ -388,184 +388,182 @@ static int call_server(host, port, oid, service_name, gss_flags, auth_flag,
          return -1;
      }
 
-     if (auth_flag) {
-       if (verbose) {
-        /* display the flags */
-        display_ctx_flags(ret_flags);
-
-        /* Get context information */
-        maj_stat = gss_inquire_context(&min_stat, context,
-                                       &src_name, &targ_name, &lifetime,
-                                       &mechanism, &context_flags,
-                                       &is_local,
-                                       &is_open);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("inquiring context", maj_stat, min_stat);
-          return -1;
-        }
-
-        maj_stat = gss_display_name(&min_stat, src_name, &sname,
-                                    &name_type);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("displaying source name", maj_stat, min_stat);
-          return -1;
-        }
-        maj_stat = gss_display_name(&min_stat, targ_name, &tname,
-                                    (gss_OID *) NULL);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("displaying target name", maj_stat, min_stat);
-          return -1;
-        }
-        printf("\"%.*s\" to \"%.*s\", lifetime %d, flags %x, %s, %s\n",
-               (int) sname.length, (char *) sname.value,
-               (int) tname.length, (char *) tname.value, lifetime,
-               context_flags,
-               (is_local) ? "locally initiated" : "remotely initiated",
-               (is_open) ? "open" : "closed");
-
-        (void) gss_release_name(&min_stat, &src_name);
-        (void) gss_release_name(&min_stat, &targ_name);
-        (void) gss_release_buffer(&min_stat, &sname);
-        (void) gss_release_buffer(&min_stat, &tname);
-
-        maj_stat = gss_oid_to_str(&min_stat,
-                                  name_type,
-                                  &oid_name);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("converting oid->string", maj_stat, min_stat);
-          return -1;
-        }
-        printf("Name type of source name is %.*s.\n",
-               (int) oid_name.length, (char *) oid_name.value);
-        (void) gss_release_buffer(&min_stat, &oid_name);
-
-        /* Now get the names supported by the mechanism */
-        maj_stat = gss_inquire_names_for_mech(&min_stat,
-                                              mechanism,
-                                              &mech_names);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("inquiring mech names", maj_stat, min_stat);
-          return -1;
-        }
-
-        maj_stat = gss_oid_to_str(&min_stat,
-                                  mechanism,
-                                  &oid_name);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("converting oid->string", maj_stat, min_stat);
-          return -1;
-        }
-        printf("Mechanism %.*s supports %d names\n",
-               (int) oid_name.length, (char *) oid_name.value,
-               (int) mech_names->count);
-        (void) gss_release_buffer(&min_stat, &oid_name);
-
-        for (i=0; i<mech_names->count; i++) {
-          maj_stat = gss_oid_to_str(&min_stat,
-                                    &mech_names->elements[i],
-                                    &oid_name);
-          if (maj_stat != GSS_S_COMPLETE) {
-            display_status("converting oid->string", maj_stat, min_stat);
-            return -1;
-          }
-          printf("  %d: %.*s\n", (int) i,
-                 (int) oid_name.length, (char *) oid_name.value);
-
-          (void) gss_release_buffer(&min_stat, &oid_name);
-        }
-        (void) gss_release_oid_set(&min_stat, &mech_names);
-       }
-     }
-     
-     if (use_file) {
-        read_file(msg, &in_buf);
-     } else {
-        /* Seal the message */
-        in_buf.value = msg;
-        in_buf.length = strlen(msg);
+     if (auth_flag && verbose) {
+         /* display the flags */
+         display_ctx_flags(ret_flags);
+
+         /* Get context information */
+         maj_stat = gss_inquire_context( &min_stat, context,
+                                         &src_name, &targ_name, &lifetime,
+                                         &mechanism, &context_flags,
+                                         &is_local,
+                                         &is_open);
+         if (maj_stat != GSS_S_COMPLETE) {
+             display_status("inquiring context", maj_stat, min_stat);
+             return -1;
+         }
+
+         maj_stat = gss_display_name(&min_stat, src_name, &sname,
+                                      &name_type);
+         if (maj_stat != GSS_S_COMPLETE) {
+             display_status("displaying source name", maj_stat, min_stat);
+             return -1;
+         }
+         maj_stat = gss_display_name(&min_stat, targ_name, &tname,
+                                      (gss_OID *) NULL);
+         if (maj_stat != GSS_S_COMPLETE) {
+             display_status("displaying target name", maj_stat, min_stat);
+             return -1;
+         }
+         printf("\"%.*s\" to \"%.*s\", lifetime %d, flags %x, %s, %s\n",
+                 (int) sname.length, (char *) sname.value,
+                 (int) tname.length, (char *) tname.value, lifetime,
+                 context_flags,
+                 (is_local) ? "locally initiated" : "remotely initiated",
+                 (is_open) ? "open" : "closed");
+
+         (void) gss_release_name(&min_stat, &src_name);
+         (void) gss_release_name(&min_stat, &targ_name);
+         (void) gss_release_buffer(&min_stat, &sname);
+         (void) gss_release_buffer(&min_stat, &tname);
+
+         maj_stat = gss_oid_to_str(&min_stat,
+                                    name_type,
+                                    &oid_name);
+         if (maj_stat != GSS_S_COMPLETE) {
+             display_status("converting oid->string", maj_stat, min_stat);
+             return -1;
+         }
+         printf("Name type of source name is %.*s.\n",
+                 (int) oid_name.length, (char *) oid_name.value);
+         (void) gss_release_buffer(&min_stat, &oid_name);
+
+         /* Now get the names supported by the mechanism */
+         maj_stat = gss_inquire_names_for_mech(&min_stat,
+                                                mechanism,
+                                                &mech_names);
+         if (maj_stat != GSS_S_COMPLETE) {
+             display_status("inquiring mech names", maj_stat, min_stat);
+             return -1;
+         }
+
+         maj_stat = gss_oid_to_str(&min_stat,
+                                    mechanism,
+                                    &oid_name);
+         if (maj_stat != GSS_S_COMPLETE) {
+             display_status("converting oid->string", maj_stat, min_stat);
+             return -1;
+         }
+         printf("Mechanism %.*s supports %d names\n",
+                 (int) oid_name.length, (char *) oid_name.value,
+                 (int) mech_names->count);
+         (void) gss_release_buffer(&min_stat, &oid_name);
+
+         for (i=0; i<mech_names->count; i++) {
+             maj_stat = gss_oid_to_str(&min_stat,
+                                        &mech_names->elements[i],
+                                        &oid_name);
+             if (maj_stat != GSS_S_COMPLETE) {
+                 display_status("converting oid->string", maj_stat, min_stat);
+                 return -1;
+             }
+             printf("  %d: %.*s\n", (int) i,
+                     (int) oid_name.length, (char *) oid_name.value);
+
+             (void) gss_release_buffer(&min_stat, &oid_name);
+         }
+         (void) gss_release_oid_set(&min_stat, &mech_names);
      }
 
-     for (i = 0; i < mcount; i++) {
-       if (wrap_flag) {
-        maj_stat = gss_wrap(&min_stat, context, encrypt_flag, GSS_C_QOP_DEFAULT,
-                            &in_buf, &state, &out_buf);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("wrapping message", maj_stat, min_stat);
-          (void) close(s);
-          (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
-          return -1;
-        } else if (encrypt_flag && ! state) {
-          fprintf(stderr, "Warning!  Message not encrypted.\n");
-        }
-       }
-       else {
-        out_buf = in_buf;
-       }
-
-       /* Send to server */
-       if (send_token(s, (v1_format?0
-                         :(TOKEN_DATA |
-                         (wrap_flag ? TOKEN_WRAPPED : 0) |
-                         (encrypt_flag ? TOKEN_ENCRYPTED : 0) |
-                         (mic_flag ? TOKEN_SEND_MIC : 0))), &out_buf) < 0) {
-        (void) close(s);
-        (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
-        return -1;
-       }
-       if (out_buf.value != in_buf.value)
-        (void) gss_release_buffer(&min_stat, &out_buf);
-
-       /* Read signature block into out_buf */
-       if (recv_token(s, &token_flags, &out_buf) < 0) {
-        (void) close(s);
-        (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
-        return -1;
-       }
-
-       if (mic_flag) {
-        /* Verify signature block */
-        maj_stat = gss_verify_mic(&min_stat, context, &in_buf,
-                                  &out_buf, &qop_state);
-        if (maj_stat != GSS_S_COMPLETE) {
-          display_status("verifying signature", maj_stat, min_stat);
-          (void) close(s);
-          (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
-          return -1;
-        }
-
-        if (verbose)
-          printf("Signature verified.\n");
-       }
-       else {
-        if (verbose)
-          printf("Response received.\n");
-       }
+    if (use_file) {
+        read_file(msg, &in_buf);
+    } else {
+        /* Seal the message */
+        in_buf.value = msg;
+        in_buf.length = strlen(msg);
+    }
 
-       free (out_buf.value);
-     }
+    for (i = 0; i < mcount; i++) {
+        if (wrap_flag) {
+            maj_stat = gss_wrap(&min_stat, context, encrypt_flag, GSS_C_QOP_DEFAULT,
+                                 &in_buf, &state, &out_buf);
+            if (maj_stat != GSS_S_COMPLETE) {
+                display_status("wrapping message", maj_stat, min_stat);
+                (void) close(s);
+                (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
+                return -1;
+            } else if (encrypt_flag && ! state) {
+                fprintf(stderr, "Warning!  Message not encrypted.\n");
+            }
+        }
+        else {
+            out_buf = in_buf;
+        }
+
+        /* Send to server */
+        if (send_token(s, (v1_format?0
+                            :(TOKEN_DATA |
+                               (wrap_flag ? TOKEN_WRAPPED : 0) |
+                               (encrypt_flag ? TOKEN_ENCRYPTED : 0) |
+                               (mic_flag ? TOKEN_SEND_MIC : 0))), &out_buf) < 0) {
+            (void) close(s);
+            (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
+            return -1;
+        }
+        if (out_buf.value != in_buf.value)
+            (void) gss_release_buffer(&min_stat, &out_buf);
+
+        /* Read signature block into out_buf */
+        if (recv_token(s, &token_flags, &out_buf) < 0) {
+            (void) close(s);
+            (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
+            return -1;
+        }
+
+        if (mic_flag) {
+            /* Verify signature block */
+            maj_stat = gss_verify_mic(&min_stat, context, &in_buf,
+                                       &out_buf, &qop_state);
+            if (maj_stat != GSS_S_COMPLETE) {
+                display_status("verifying signature", maj_stat, min_stat);
+                (void) close(s);
+                (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
+                return -1;
+            }
+
+            if (verbose)
+                printf("Signature verified.\n");
+        }
+        else {
+            if (verbose)
+                printf("Response received.\n");
+        }
+
+        free (out_buf.value);
+    }
 
-     if (use_file)
-       free(in_buf.value);
+    if (use_file)
+        free(in_buf.value);
 
-     /* Send NOOP */
-     if (!v1_format)
-     (void) send_token(s, TOKEN_NOOP, empty_token);
+    /* Send NOOP */
+    if (!v1_format)
+        (void) send_token(s, TOKEN_NOOP, empty_token);
 
-     if (auth_flag) {
-       /* Delete context */
-       maj_stat = gss_delete_sec_context(&min_stat, &context, &out_buf);
-       if (maj_stat != GSS_S_COMPLETE) {
-        display_status("deleting context", maj_stat, min_stat);
-        (void) close(s);
-        (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
-        return -1;
-       }
+    if (auth_flag) {
+        /* Delete context */
+        maj_stat = gss_delete_sec_context(&min_stat, &context, &out_buf);
+        if (maj_stat != GSS_S_COMPLETE) {
+            display_status("deleting context", maj_stat, min_stat);
+            (void) close(s);
+            (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER);
+            return -1;
+        }
 
-       (void) gss_release_buffer(&min_stat, &out_buf);
-     }
+        (void) gss_release_buffer(&min_stat, &out_buf);
+    }
 
-     (void) close(s);
-     return 0;
+    (void) close(s);
+    return 0;
 }
 
 static void parse_oid(char *mechanism, gss_OID *oid)