sync'ing up for 3.0alpha20 release
[jra/samba/.git] / source3 / passdb / pdb_get_set.c
index 372b332a4517617f71e55209db4027e411f161ef..0c338f317ecd665c2c01d41f174668f6b63a9449 100644 (file)
@@ -5,6 +5,7 @@
    Copyright (C) Luke Kenneth Casson Leighton  1996-1998
    Copyright (C) Gerald (Jerry) Carter         2000-2001
    Copyright (C) Andrew Bartlett               2001-2002
+   Copyright (C) Stefan (metze) Metzmacher     2002
       
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -23,6 +24,9 @@
 
 #include "includes.h"
 
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_PASSDB
+
 /**
  * @todo Redefine this to NULL, but this changes the API becouse
  *       much of samba assumes that the pdb_get...() funtions 
@@ -147,27 +151,26 @@ const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *sampass)
 const char* pdb_get_plaintext_passwd (const SAM_ACCOUNT *sampass)
 {
        if (sampass) {
-               return ((char*)sampass->private.plaintext_pw.data);
+               return (sampass->private.plaintext_pw);
        }
        else
                return (NULL);
 }
-
-uint32 pdb_get_user_rid (const SAM_ACCOUNT *sampass)
+const DOM_SID *pdb_get_user_sid(const SAM_ACCOUNT *sampass)
 {
-       if (sampass)
-               return (sampass->private.user_rid);
+       if (sampass) 
+               return &sampass->private.user_sid;
        else
-               return (-1);
+               return (NULL);
 }
 
-uint32 pdb_get_group_rid (const SAM_ACCOUNT *sampass)
+const DOM_SID *pdb_get_group_sid(const SAM_ACCOUNT *sampass)
 {
        if (sampass)
-               return (sampass->private.group_rid);
-       else
-               return (-1);
-}
+               return &sampass->private.group_sid;
+       else    
+               return (NULL);
+}      
 
 /**
  * Get flags showing what is initalised in the SAM_ACCOUNT
@@ -247,7 +250,7 @@ const char* pdb_get_unix_homedir (const SAM_ACCOUNT *sampass)
                return (NULL);
 }
 
-const char* pdb_get_dirdrive (const SAM_ACCOUNT *sampass)
+const char* pdb_get_dir_drive (const SAM_ACCOUNT *sampass)
 {
        if (sampass)
                return (sampass->private.dir_drive);
@@ -484,27 +487,72 @@ BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t gid)
 
 }
 
-BOOL pdb_set_user_rid (SAM_ACCOUNT *sampass, uint32 rid)
+BOOL pdb_set_user_sid (SAM_ACCOUNT *sampass, DOM_SID *u_sid)
 {
-       if (!sampass)
+       if (!sampass || !u_sid)
                return False;
+       
+       sid_copy(&sampass->private.user_sid, u_sid);
 
-       DEBUG(10, ("pdb_set_rid: setting user rid %d, was %d\n", 
-                  rid, sampass->private.user_rid));
-       sampass->private.user_rid = rid;
+       DEBUG(10, ("pdb_set_user_sid: setting user sid %s\n", 
+                   sid_string_static(&sampass->private.user_sid)));
+       
        return True;
 }
 
-BOOL pdb_set_group_rid (SAM_ACCOUNT *sampass, uint32 grid)
+BOOL pdb_set_user_sid_from_string (SAM_ACCOUNT *sampass, fstring u_sid)
 {
-       if (!sampass)
+       DOM_SID new_sid;
+       if (!sampass || !u_sid)
                return False;
 
-       DEBUG(10, ("pdb_set_group_rid: setting group rid %d, was %d\n", 
-                  grid, sampass->private.group_rid));
-       sampass->private.group_rid = grid;
+       DEBUG(10, ("pdb_set_user_sid_from_string: setting user sid %s\n",
+                  u_sid));
+
+       if (!string_to_sid(&new_sid, u_sid)) { 
+               DEBUG(1, ("pdb_set_user_sid_from_string: %s isn't a valid SID!\n", u_sid));
+               return False;
+       }
+        
+       if (!pdb_set_user_sid(sampass, &new_sid)) {
+               DEBUG(1, ("pdb_set_user_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", u_sid));
+               return False;
+       }
+
+       return True;
+}
+
+BOOL pdb_set_group_sid (SAM_ACCOUNT *sampass, DOM_SID *g_sid)
+{
+       if (!sampass || !g_sid)
+               return False;
+
+       sid_copy(&sampass->private.group_sid, g_sid);
+
+       DEBUG(10, ("pdb_set_group_sid: setting group sid %s\n", 
+                   sid_string_static(&sampass->private.group_sid)));
+
+       return True;
+}
+
+BOOL pdb_set_group_sid_from_string (SAM_ACCOUNT *sampass, fstring g_sid)
+{
+       DOM_SID new_sid;
+       if (!sampass || !g_sid)
+               return False;
+
+       DEBUG(10, ("pdb_set_group_sid_from_string: setting group sid %s\n",
+                  g_sid));
+
+       if (!string_to_sid(&new_sid, g_sid)) { 
+               DEBUG(1, ("pdb_set_group_sid_from_string: %s isn't a valid SID!\n", g_sid));
+               return False;
+       }
+        
+       if (!pdb_set_group_sid(sampass, &new_sid)) {
+               DEBUG(1, ("pdb_set_group_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", g_sid));
+               return False;
+       }
        return True;
 }
 
@@ -737,7 +785,7 @@ BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, BOOL store)
        }
 
        if (store) {
-               DEBUG(10, ("pdb_set_homedir: setting home dir sam flag!"));
+               DEBUG(10, ("pdb_set_homedir: setting home dir sam flag!\n"));
                pdb_set_init_flag(sampass, FLAG_SAM_SMBHOME);
        }
 
@@ -754,7 +802,7 @@ BOOL pdb_set_unix_homedir (SAM_ACCOUNT *sampass, const char *unix_home_dir)
                return False;
 
        if (unix_home_dir) { 
-               DEBUG(10, ("pdb_set_homedir: setting home dir %s, was %s\n", unix_home_dir,
+               DEBUG(10, ("pdb_set_unix_homedir: setting home dir %s, was %s\n", unix_home_dir,
                        (sampass->private.unix_home_dir)?(sampass->private.unix_home_dir):"NULL"));
  
                sampass->private.unix_home_dir = talloc_strdup(sampass->mem_ctx, 
@@ -908,14 +956,24 @@ BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 pwd[16])
  below)
  ********************************************************************/
 
-BOOL pdb_set_plaintext_pw_only (SAM_ACCOUNT *sampass, const uint8 *password, size_t len)
+BOOL pdb_set_plaintext_pw_only (SAM_ACCOUNT *sampass, const char *password)
 {
        if (!sampass)
                return False;
 
-       data_blob_clear_free(&sampass->private.plaintext_pw);
-       
-       sampass->private.plaintext_pw = data_blob(password, len);
+       if (password) { 
+               if (sampass->private.plaintext_pw!=NULL) 
+                       memset(sampass->private.plaintext_pw,'\0',strlen(sampass->private.plaintext_pw)+1);
+               sampass->private.plaintext_pw = talloc_strdup(sampass->mem_ctx, password);
+               
+               if (!sampass->private.plaintext_pw) {
+                       DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
+                       return False;
+               }
+
+       } else {
+               sampass->private.plaintext_pw = NULL;
+       }
 
        return True;
 }
@@ -980,15 +1038,14 @@ BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
        if (!pdb_set_pass_last_set_time (sampass, time(NULL)))
                return False;
 
-       account_policy_get(AP_MAX_PASSWORD_AGE, &expire);
-
-       if (expire==(uint32)-1) {
+       if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire) 
+           || (expire==(uint32)-1)) {
                if (!pdb_set_pass_must_change_time (sampass, get_time_t_max(), False))
                        return False;
        } else {
                if (!pdb_set_pass_must_change_time (sampass, 
-                                           pdb_get_pass_last_set_time(sampass)
-                                           + expire, True))
+                                                   pdb_get_pass_last_set_time(sampass)
+                                                   + expire, True))
                        return False;
        }
        
@@ -1015,7 +1072,10 @@ BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
 
        if (!pdb_set_lanman_passwd (sampass, new_lanman_p16)) 
                return False;
-       
+
+       if (!pdb_set_plaintext_pw_only (sampass, plaintext)) 
+               return False;
+
        if (!pdb_set_pass_changed_now (sampass))
                return False;