]> arthur.barton.de Git - netatalk.git/commitdiff
Untabify and reindent
authorFrank Lahm <franklahm@googlemail.com>
Mon, 21 Mar 2011 06:41:54 +0000 (07:41 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 21 Mar 2011 06:41:54 +0000 (07:41 +0100)
etc/uams/uams_dhx2_pam.c

index fde2df74549344320ed84db0b5288cb6bd49ef5a..ec26b8c6cc03949a1961d9dacad176acf8ecc746 100644 (file)
 #define PRIMEBITS 1024
 
 /* hash a number to a 16-bit quantity */
-#define dhxhash(a) ((((unsigned long) (a) >> 8) ^ \
+#define dhxhash(a) ((((unsigned long) (a) >> 8) ^   \
                      (unsigned long) (a)) & 0xffff)
 
 /* Some parameters need be maintained across calls */
-static gcry_mpi_t p, Ra;
+static gcry_mpi_t p, g, Ra;
 static gcry_mpi_t serverNonce;
 static char *K_MD5hash = NULL;
 static int K_hash_len;
@@ -64,7 +64,7 @@ static struct passwd *dhxpwd;
 /*********************************************************
  * Crypto helper func to generate p and g for use in DH.
  * libgcrypt doesn't provide one directly.
- * Algorithm taken from GNUTLS:gnutls_dh_primes.c 
+ * Algorithm taken from GNUTLS:gnutls_dh_primes.c
  *********************************************************/
 
 /**
@@ -91,53 +91,53 @@ dh_params_generate (gcry_mpi_t *ret_p, gcry_mpi_t *ret_g, unsigned int bits) {
     }
 
     if (bits < 256)
-       qbits = bits / 2;
+        qbits = bits / 2;
     else
-       qbits = (bits / 40) + 105;
+        qbits = (bits / 40) + 105;
 
     if (qbits & 1) /* better have an even number */
-       qbits++;
+        qbits++;
 
     /* find a prime number of size bits. */
     do {
-       if (times) {
-           gcry_mpi_release (prime);
-           gcry_prime_release_factors (factors);
-       }
-       err = gcry_prime_generate (&prime, bits, qbits, &factors, NULL, NULL,
-                                  GCRY_STRONG_RANDOM, GCRY_PRIME_FLAG_SPECIAL_FACTOR);
-       if (err != 0) {
-           result = AFPERR_MISC;
-           goto error;
-       }
-       err = gcry_prime_check (prime, 0);
-       times++;
+        if (times) {
+            gcry_mpi_release (prime);
+            gcry_prime_release_factors (factors);
+        }
+        err = gcry_prime_generate (&prime, bits, qbits, &factors, NULL, NULL,
+                                   GCRY_STRONG_RANDOM, GCRY_PRIME_FLAG_SPECIAL_FACTOR);
+        if (err != 0) {
+            result = AFPERR_MISC;
+            goto error;
+        }
+        err = gcry_prime_check (prime, 0);
+        times++;
     } while (err != 0 && times < 10);
-    
+
     if (err != 0) {
-       result = AFPERR_MISC;
-       goto error;
+        result = AFPERR_MISC;
+        goto error;
     }
 
     /* generate the group generator. */
     err = gcry_prime_group_generator (&g, prime, factors, NULL);
     if (err != 0) {
-       result = AFPERR_MISC;
-       goto error;
+        result = AFPERR_MISC;
+        goto error;
     }
-    
+
     gcry_prime_release_factors (factors);
     factors = NULL;
-    
+
     if (ret_g)
-       *ret_g = g;
+        *ret_g = g;
     else
-       gcry_mpi_release (g);
+        gcry_mpi_release (g);
     if (ret_p)
-       *ret_p = prime;
+        *ret_p = prime;
     else
-       gcry_mpi_release (prime);
-    
+        gcry_mpi_release (prime);
+
     return 0;
 
 error:
@@ -254,7 +254,7 @@ static struct pam_conv PAM_conversation = {
 
 
 static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
-                     char *rbuf, size_t *rbuflen)
+                      char *rbuf, size_t *rbuflen)
 {
     int ret;
     size_t nwritten;
@@ -271,16 +271,16 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     /* Generate p and g for DH */
     ret = dh_params_generate( &p, &g, PRIMEBITS);
     if (ret != 0) {
-       LOG(log_info, logtype_uams, "DHX2: Couldn't generate p and g");
-       ret = AFPERR_MISC;
-       goto error;
+        LOG(log_info, logtype_uams, "DHX2: Couldn't generate p and g");
+        ret = AFPERR_MISC;
+        goto error;
     }
 
     /* Generate our random number Ra. */
     Ra_binary = calloc(1, PRIMEBITS/8);
     if (Ra_binary == NULL) {
-       ret = AFPERR_MISC;
-       goto error;
+        ret = AFPERR_MISC;
+        goto error;
     }
     gcry_randomize(Ra_binary, PRIMEBITS/8, GCRY_STRONG_RANDOM);
     gcry_mpi_scan(&Ra, GCRYMPI_FMT_USG, Ra_binary, PRIMEBITS/8, NULL);
@@ -302,8 +302,8 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     /* g is next */
     gcry_mpi_print( GCRYMPI_FMT_USG, (unsigned char *)rbuf, 4, &nwritten, g);
     if (nwritten < 4) {
-       memmove( rbuf+4-nwritten, rbuf, nwritten);
-       memset( rbuf, 0, 4-nwritten);
+        memmove( rbuf+4-nwritten, rbuf, nwritten);
+        memset( rbuf, 0, 4-nwritten);
     }
     rbuf += 4;
     *rbuflen += 4;
@@ -321,15 +321,15 @@ static int dhx2_setup(void *obj, char *ibuf _U_, size_t ibuflen _U_,
     /* Ma */
     gcry_mpi_print( GCRYMPI_FMT_USG, (unsigned char *)rbuf, PRIMEBITS/8, &nwritten, Ma);
     if (nwritten < PRIMEBITS/8) {
-       memmove(rbuf + (PRIMEBITS/8) - nwritten, rbuf, nwritten);
-       memset(rbuf, 0, (PRIMEBITS/8) - nwritten);
+        memmove(rbuf + (PRIMEBITS/8) - nwritten, rbuf, nwritten);
+        memset(rbuf, 0, (PRIMEBITS/8) - nwritten);
     }
     rbuf += PRIMEBITS/8;
     *rbuflen += PRIMEBITS/8;
 
     ret = AFPERR_AUTHCONT;
 
-error:                         /* We exit here anyway */
+error:              /* We exit here anyway */
     /* We will only need p and Ra later, but mustn't forget to release it ! */
     gcry_mpi_release(g);
     gcry_mpi_release(Ma);
@@ -443,9 +443,9 @@ static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, siz
 
     /* Packet size should be: Session ID + Ma + Encrypted client nonce */
     if (ibuflen != 2 + PRIMEBITS/8 + 16) {
-       LOG(log_error, logtype_uams, "DHX2: Paket length not correct");
+        LOG(log_error, logtype_uams, "DHX2: Paket length not correct");
         ret = AFPERR_PARAM;
-       goto error_noctx;
+        goto error_noctx;
     }
 
     /* Skip session id */
@@ -461,20 +461,20 @@ static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, siz
     /* We need K in binary form in order to ... */
     K_bin = calloc(1, PRIMEBITS/8);
     if (K_bin == NULL) {
-       ret = AFPERR_MISC;
-       goto error_noctx;
+        ret = AFPERR_MISC;
+        goto error_noctx;
     }
     gcry_mpi_print(GCRYMPI_FMT_USG, K_bin, PRIMEBITS/8, &nwritten, K);
     if (nwritten < PRIMEBITS/8) {
-       memmove(K_bin + PRIMEBITS/8 - nwritten, K_bin, nwritten);
-       memset(K_bin, 0, PRIMEBITS/8 - nwritten);
+        memmove(K_bin + PRIMEBITS/8 - nwritten, K_bin, nwritten);
+        memset(K_bin, 0, PRIMEBITS/8 - nwritten);
     }
 
     /* ... generate the MD5 hash of K. K_MD5hash is what we actually use ! */
     K_MD5hash = calloc(1, K_hash_len = gcry_md_get_algo_dlen(GCRY_MD_MD5));
     if (K_MD5hash == NULL) {
-       ret = AFPERR_MISC;
-       goto error_noctx;
+        ret = AFPERR_MISC;
+        goto error_noctx;
     }
     gcry_md_hash_buffer(GCRY_MD_MD5, K_MD5hash, K_bin, PRIMEBITS/8);
     free(K_bin);
@@ -485,25 +485,25 @@ static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, siz
     /* Set up our encryption context. */
     ctxerror = gcry_cipher_open( &ctx, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC, 0);
     if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
-       ret = AFPERR_MISC;
+        ret = AFPERR_MISC;
         goto error_ctx;
     }
     /* Set key */
     ctxerror = gcry_cipher_setkey(ctx, K_MD5hash, K_hash_len);
     if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
-       ret = AFPERR_MISC;
+        ret = AFPERR_MISC;
         goto error_ctx;
     }
     /* Set the initialization vector for client->server transfer. */
     ctxerror = gcry_cipher_setiv(ctx, dhx_c2siv, sizeof(dhx_c2siv));
     if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
-       ret = AFPERR_MISC;
+        ret = AFPERR_MISC;
         goto error_ctx;
     }
     /* Finally: decrypt client's md5_K(client nonce, C2SIV) inplace */
     ctxerror = gcry_cipher_decrypt(ctx, ibuf, 16, NULL, 0);
     if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
-       ret = AFPERR_MISC;
+        ret = AFPERR_MISC;
         goto error_ctx;
     }
     /* Pull out clients nonce */
@@ -530,14 +530,14 @@ static int logincont1(void *obj _U_, char *ibuf, size_t ibuflen, char *rbuf, siz
     /* Set the initialization vector for server->client transfer. */
     ctxerror = gcry_cipher_setiv(ctx, dhx_s2civ, sizeof(dhx_s2civ));
     if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
-       ret = AFPERR_MISC;
+        ret = AFPERR_MISC;
         goto error_ctx;
     }
     /* Encrypt md5_K(clientNonce+1, serverNonce) inplace */
     ctxerror = gcry_cipher_encrypt(ctx, rbuf, 32, NULL, 0);
     if (gcry_err_code(ctxerror) != GPG_ERR_NO_ERROR) {
-       ret = AFPERR_MISC;
-       goto error_ctx;
+        ret = AFPERR_MISC;
+        goto error_ctx;
     }
     rbuf += 32;
     *rbuflen += 32;
@@ -561,8 +561,8 @@ exit:
 }
 
 static int logincont2(void *obj, struct passwd **uam_pwd,
-                     char *ibuf, size_t ibuflen,
-                     char *rbuf _U_, size_t *rbuflen)
+                      char *ibuf, size_t ibuflen,
+                      char *rbuf _U_, size_t *rbuflen)
 {
     int ret;
     int PAM_error;
@@ -617,7 +617,7 @@ static int logincont2(void *obj, struct passwd **uam_pwd,
     gcry_mpi_scan(&retServerNonce, GCRYMPI_FMT_USG, ibuf, 16, NULL);
     gcry_mpi_sub_ui(retServerNonce, retServerNonce, 1);
     if ( gcry_mpi_cmp( serverNonce, retServerNonce) != 0) {
-       /* We're hacked!  */
+        /* We're hacked!  */
         ret = AFPERR_NOTAUTH;
         goto error_ctx;
     }
@@ -631,9 +631,9 @@ static int logincont2(void *obj, struct passwd **uam_pwd,
     ret = AFPERR_NOTAUTH;
     PAM_error = pam_start("netatalk", PAM_username, &PAM_conversation, &pamh);
     if (PAM_error != PAM_SUCCESS) {
-       LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
-           pam_strerror(pamh,PAM_error));
-       goto error_ctx;
+        LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
+            pam_strerror(pamh,PAM_error));
+        goto error_ctx;
     }
 
     /* solaris craps out if PAM_TTY and PAM_RHOST aren't set. */
@@ -641,25 +641,25 @@ static int logincont2(void *obj, struct passwd **uam_pwd,
     pam_set_item(pamh, PAM_RHOST, hostname);
     PAM_error = pam_authenticate(pamh, 0);
     if (PAM_error != PAM_SUCCESS) {
-       if (PAM_error == PAM_MAXTRIES)
-           ret = AFPERR_PWDEXPR;
-       LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
-           pam_strerror(pamh, PAM_error));
-       goto error_ctx;
+        if (PAM_error == PAM_MAXTRIES)
+            ret = AFPERR_PWDEXPR;
+        LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
+            pam_strerror(pamh, PAM_error));
+        goto error_ctx;
     }
 
     PAM_error = pam_acct_mgmt(pamh, 0);
     if (PAM_error != PAM_SUCCESS ) {
-       LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
-           pam_strerror(pamh, PAM_error));
-       if (PAM_error == PAM_NEW_AUTHTOK_REQD)    /* password expired */
-           ret = AFPERR_PWDEXPR;
+        LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
+            pam_strerror(pamh, PAM_error));
+        if (PAM_error == PAM_NEW_AUTHTOK_REQD)    /* password expired */
+            ret = AFPERR_PWDEXPR;
 #ifdef PAM_AUTHTOKEN_REQD
-       else if (PAM_error == PAM_AUTHTOKEN_REQD)
-           ret = AFPERR_PWDCHNG;
+        else if (PAM_error == PAM_AUTHTOKEN_REQD)
+            ret = AFPERR_PWDCHNG;
 #endif
-       else
-           goto error_ctx;
+        else
+            goto error_ctx;
     }
 
 #ifndef PAM_CRED_ESTABLISH
@@ -667,16 +667,16 @@ static int logincont2(void *obj, struct passwd **uam_pwd,
 #endif
     PAM_error = pam_setcred(pamh, PAM_CRED_ESTABLISH);
     if (PAM_error != PAM_SUCCESS) {
-       LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
-           pam_strerror(pamh, PAM_error));
-       goto error_ctx;
+        LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
+            pam_strerror(pamh, PAM_error));
+        goto error_ctx;
     }
 
     PAM_error = pam_open_session(pamh, 0);
     if (PAM_error != PAM_SUCCESS) {
-       LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
-           pam_strerror(pamh, PAM_error));
-       goto error_ctx;
+        LOG(log_info, logtype_uams, "DHX2: PAM_Error: %s",
+            pam_strerror(pamh, PAM_error));
+        goto error_ctx;
     }
 
     memset(ibuf, 0, 256); /* zero out the password */
@@ -692,7 +692,7 @@ error_noctx:
     free(K_MD5hash);
     K_MD5hash=NULL;
     gcry_mpi_release(serverNonce);
-    gcry_mpi_release(retServerNonce);    
+    gcry_mpi_release(retServerNonce);
     return ret;
 }
 
@@ -728,7 +728,7 @@ static void pam_logout(void) {
  * --- Change pwd stuff --- */
 
 static int changepw_1(void *obj, char *uname,
-                     char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
+                      char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
 {
     *rbuflen = 0;
 
@@ -737,15 +737,15 @@ static int changepw_1(void *obj, char *uname,
     return( dhx2_setup(obj, ibuf, ibuflen, rbuf, rbuflen) );
 }
 
-static int changepw_2(void *obj, 
-                     char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
+static int changepw_2(void *obj,
+                      char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
 {
     return( logincont1(obj, ibuf, ibuflen, rbuf, rbuflen) );
 }
 
 static int changepw_3(void *obj _U_,
-                     char *ibuf, size_t ibuflen _U_, 
-                     char *rbuf _U_, size_t *rbuflen _U_)
+                      char *ibuf, size_t ibuflen _U_,
+                      char *rbuf _U_, size_t *rbuflen _U_)
 {
     int ret;
     int PAM_error;
@@ -812,14 +812,14 @@ static int changepw_3(void *obj _U_,
     ibuf += 16;
 
     /* ---- Start pwd changing with PAM --- */
-    ibuf[255] = '\0';          /* For safety */
+    ibuf[255] = '\0';       /* For safety */
     ibuf[511] = '\0';
 
     /* check if new and old password are equal */
     if (memcmp(ibuf, ibuf + 256, 255) == 0) {
-       LOG(log_info, logtype_uams, "DHX2 Chgpwd: new and old password are equal");
+        LOG(log_info, logtype_uams, "DHX2 Chgpwd: new and old password are equal");
         ret = AFPERR_PWDSAME;
-       goto error_ctx;
+        goto error_ctx;
     }
 
     /* Set these things up for the conv function. PAM_username was set in changepw_1 */
@@ -827,7 +827,7 @@ static int changepw_3(void *obj _U_,
     PAM_error = pam_start("netatalk", PAM_username, &PAM_conversation, &lpamh);
     if (PAM_error != PAM_SUCCESS) {
         LOG(log_info, logtype_uams, "DHX2 Chgpwd: PAM error in pam_start");
-       ret = AFPERR_PARAM;
+        ret = AFPERR_PARAM;
         goto error_ctx;
     }
     pam_set_item(lpamh, PAM_TTY, "afpd");
@@ -837,21 +837,21 @@ static int changepw_3(void *obj _U_,
     seteuid(0);
     PAM_error = pam_authenticate(lpamh,0);
     if (PAM_error != PAM_SUCCESS) {
-       LOG(log_info, logtype_uams, "DHX2 Chgpwd: error authenticating with PAM");
-       seteuid(uid);
-       pam_end(lpamh, PAM_error);
-       ret = AFPERR_NOTAUTH;
-       goto error_ctx;
+        LOG(log_info, logtype_uams, "DHX2 Chgpwd: error authenticating with PAM");
+        seteuid(uid);
+        pam_end(lpamh, PAM_error);
+        ret = AFPERR_NOTAUTH;
+        goto error_ctx;
     }
     PAM_password = ibuf;
     PAM_error = pam_chauthtok(lpamh, 0);
     seteuid(uid); /* un-root ourselves. */
     memset(ibuf, 0, 512);
     if (PAM_error != PAM_SUCCESS) {
-       LOG(log_info, logtype_uams, "DHX2 Chgpwd: error changing pw with PAM");
-       pam_end(lpamh, PAM_error);
-       ret = AFPERR_ACCESS;
-       goto error_ctx;
+        LOG(log_info, logtype_uams, "DHX2 Chgpwd: error changing pw with PAM");
+        pam_end(lpamh, PAM_error);
+        ret = AFPERR_ACCESS;
+        goto error_ctx;
     }
     pam_end(lpamh, 0);
     ret = AFP_OK;
@@ -867,8 +867,8 @@ error_noctx:
 }
 
 static int dhx2_changepw(void *obj _U_, char *uname,
-                        struct passwd *pwd _U_, char *ibuf, size_t ibuflen _U_,
-                        char *rbuf _U_, size_t *rbuflen _U_)
+                         struct passwd *pwd _U_, char *ibuf, size_t ibuflen _U_,
+                         char *rbuf _U_, size_t *rbuflen _U_)
 {
     /* We use this to serialize the three incoming FPChangePassword calls */
     static int dhx2_changepw_status = 1;
@@ -877,22 +877,22 @@ static int dhx2_changepw(void *obj _U_, char *uname,
 
     switch (dhx2_changepw_status) {
     case 1:
-       ret = changepw_1( obj, uname, ibuf, ibuflen, rbuf, rbuflen);
-       if ( ret == AFPERR_AUTHCONT)
-           dhx2_changepw_status = 2;
-       break;
+        ret = changepw_1( obj, uname, ibuf, ibuflen, rbuf, rbuflen);
+        if ( ret == AFPERR_AUTHCONT)
+            dhx2_changepw_status = 2;
+        break;
     case 2:
-       ret = changepw_2( obj, ibuf, ibuflen, rbuf, rbuflen);
+        ret = changepw_2( obj, ibuf, ibuflen, rbuf, rbuflen);
         if ( ret == AFPERR_AUTHCONT)
             dhx2_changepw_status = 3;
-       else
-           dhx2_changepw_status = 1;
-       break;
+        else
+            dhx2_changepw_status = 1;
+        break;
     case 3:
-       ret = changepw_3( obj, ibuf, ibuflen, rbuf, rbuflen);
-       dhx2_changepw_status = 1; /* Whether is was succesfull or not: we
-                                    restart anyway !*/
-       break;
+        ret = changepw_3( obj, ibuf, ibuflen, rbuf, rbuflen);
+        dhx2_changepw_status = 1; /* Whether is was succesfull or not: we
+                                     restart anyway !*/
+        break;
     }
     return ret;
 }