s3: Use asprintf where appropriate
authorVolker Lendecke <vl@samba.org>
Wed, 22 Sep 2010 12:10:03 +0000 (14:10 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 22 Sep 2010 22:42:28 +0000 (15:42 -0700)
source3/pam_smbpass/general.h
source3/pam_smbpass/pam_smb_passwd.c
source3/pam_smbpass/support.c

index 4607620c29b7adbc66bfc9360be1aa2d53116f86..f6b3e672aeeeccebd5f4802039f4695b6d9e4a2e 100644 (file)
@@ -118,7 +118,6 @@ static const SMB_Ctrls smb_args[SMB_CTRLS_] = {
  * to authenticate themself.
  */
 
-#define FAIL_PREFIX                    "-SMB-FAIL-"
 #define SMB_MAX_RETRIES                        3
 
 struct _pam_failed_auth {
index 473a55e0657c64b5af714d9e5c2ee270222392e1..8fc2cf3e14d003380e4054fe967ac95e3bb2cc81 100644 (file)
@@ -176,17 +176,12 @@ int pam_sm_chauthtok(pam_handle_t *pamh, int flags,
         if (getuid() != 0 && !(flags & PAM_CHANGE_EXPIRED_AUTHTOK)) {
 
             /* tell user what is happening */
-#define greeting "Changing password for "
-            Announce = SMB_MALLOC_ARRAY(char, sizeof(greeting)+strlen(user));
-            if (Announce == NULL) {
-                _log_err(pamh, LOG_CRIT, "password: out of memory");
-                TALLOC_FREE(sampass);
-                CatchSignal(SIGPIPE, oldsig_handler);
-                return PAM_BUF_ERR;
-            }
-            strncpy( Announce, greeting, sizeof(greeting) );
-            strncpy( Announce+sizeof(greeting)-1, user, strlen(user)+1 );
-#undef greeting
+               if (asprintf(&Announce, "Changing password for %s", user) == -1) {
+                       _log_err(pamh, LOG_CRIT, "password: out of memory");
+                       TALLOC_FREE(sampass);
+                       CatchSignal(SIGPIPE, oldsig_handler);
+                       return PAM_BUF_ERR;
+               }
 
             set( SMB__OLD_PASSWD, ctrl );
             retval = _smb_read_password( pamh, ctrl, Announce, "Current SMB password: ",
index 4215c72991e26eca1828f2bbe284b5e9c605192e..79f92a8758da8362cb448960a9d07b5ee574cc2f 100644 (file)
@@ -379,13 +379,10 @@ int _smb_verify_password( pam_handle_t * pamh, struct samu *sampass,
         }
     }
 
-    data_name = SMB_MALLOC_ARRAY(char, sizeof(FAIL_PREFIX) + strlen( name ));
-    if (data_name == NULL) {
+    if (asprintf(&data_name, "-SMB-FAIL- %s", name) == -1) {
         _log_err(pamh, LOG_CRIT, "no memory for data-name" );
         return PAM_AUTH_ERR;
     }
-    strncpy( data_name, FAIL_PREFIX, sizeof(FAIL_PREFIX) );
-    strncpy( data_name + sizeof(FAIL_PREFIX) - 1, name, strlen( name ) + 1 );
 
     /*
      * The password we were given wasn't an encrypted password, or it