clientutil.c: Don't core dump if no controlling terminal available for password.
authorJeremy Allison <jra@samba.org>
Mon, 1 Jun 1998 18:50:27 +0000 (18:50 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 1 Jun 1998 18:50:27 +0000 (18:50 +0000)
passdb.c:
lib/rpc/include/rpc_misc.h: First cut at automatic uid/gid to rid mapping.
We can change this at a later date to make more bits available if neccessary.
Jeremy.
(This used to be commit 34f40474aba97118e1e80fe6259c686e46dc16b4)

source3/client/clientutil.c
source3/include/proto.h
source3/include/rpc_misc.h
source3/passdb/passdb.c
source3/passdb/smbpass.c

index a09832a68b24cda8f41bbade6f3803abdfa00172..2da0fbb215e7faed6b8004ceb5601e462f59912e 100644 (file)
@@ -583,6 +583,9 @@ BOOL cli_send_login(char *inbuf,char *outbuf,BOOL start_session,BOOL use_setup,
   else
     pass = (char *)getpass("Password: ");
 
+  if(!pass)
+    pass = "";
+
   pstrcpy(smb_login_passwd, pass);
 
   /* use a blank username for the 2nd try with a blank password */
index 3086c6cd242e55969bb90219d428b7ba65d8adfc..ff44a5841f5223c6493c38700d95998aa1a3e2bb 100644 (file)
@@ -1611,6 +1611,7 @@ uid_t pdb_user_rid_to_uid(uint32 u_rid);
 gid_t pdb_group_rid_to_gid(uint32 g_rid);
 uint32 pdb_uid_to_user_rid(uid_t uid);
 uint32 pdb_gid_to_group_rid(gid_t gid);
+BOOL pdb_rid_is_well_known(uint32 rid);
 BOOL pdb_rid_is_user(uint32 rid);
 
 /*The following definitions come from  password.c  */
index 7406916cce93881d0c7fa75ead7f2d808d86678d..e8ffcd4a1625ceadf4e739a2e0384b36fa48ad3b 100644 (file)
 
 #define DOMAIN_ALIAS_RID_REPLICATOR    (0x00000228L)
 
+/*
+ * Masks for mappings between unix uid and gid types and
+ * NT RIDS.
+ */
+
+/* Take the 3 bottom bits. */
+#define RID_TYPE_MASK 7
+#define RID_MULTIPLIER 8
+
+/* The two common types for now. */
+#define USER_RID_TYPE 0
+#define GROUP_RID_TYPE 1
+
 /* ENUM_HND */
 typedef struct enum_hnd_info
 {
index 5bb20fce982709f0f0029252808811168341efca..2ba856e19be5d7877feb8e87a78acf469544d3af 100644 (file)
@@ -1058,7 +1058,7 @@ Error was %s\n", sid_file, strerror(errno) ));
 
 uid_t pdb_user_rid_to_uid(uint32 u_rid)
 {
-       return (uid_t)(u_rid - 1000);
+  return (uid_t)((u_rid / RID_MULTIPLIER) - 1000);
 }
 
 /*******************************************************************
@@ -1067,7 +1067,7 @@ uid_t pdb_user_rid_to_uid(uint32 u_rid)
 
 gid_t pdb_group_rid_to_gid(uint32 g_rid)
 {
-       return (gid_t)(g_rid - 1000);
+  return (gid_t)((g_rid / RID_MULTIPLIER) - 1000);
 }
 
 /*******************************************************************
@@ -1076,7 +1076,7 @@ gid_t pdb_group_rid_to_gid(uint32 g_rid)
 
 uint32 pdb_uid_to_user_rid(uid_t uid)
 {
-       return (uint32)(uid + 1000);
+       return (((((uint32)uid)*RID_MULTIPLIER) + 1000) | USER_RID_TYPE);
 }
 
 /*******************************************************************
@@ -1085,7 +1085,16 @@ uint32 pdb_uid_to_user_rid(uid_t uid)
 
 uint32 pdb_gid_to_group_rid(gid_t gid)
 {
-       return (uint32)(gid + 1000);
+  return (((((uint32)gid)*RID_MULTIPLIER) + 1000) | GROUP_RID_TYPE);
+}
+
+/*******************************************************************
+ Decides if a RID is a well known RID.
+ ********************************************************************/
+
+BOOL pdb_rid_is_well_known(uint32 rid)
+{
+  return (rid < 1000);
 }
 
 /*******************************************************************
@@ -1094,10 +1103,19 @@ uint32 pdb_gid_to_group_rid(gid_t gid)
   
 BOOL pdb_rid_is_user(uint32 rid)
 {
-  /* Punt for now - we need to look at the encoding here. JRA. */
   /* lkcl i understand that NT attaches an enumeration to a RID
    * such that it can be identified as either a user, group etc
    * type.  there are 5 such categories, and they are documented.
    */
-  return True;
+   if(pdb_rid_is_well_known(rid)) {
+      /*
+       * The only well known user RIDs are DOMAIN_USER_RID_ADMIN
+       * and DOMAIN_USER_RID_GUEST.
+       */
+     if(rid == DOMAIN_USER_RID_ADMIN || rid == DOMAIN_USER_RID_GUEST)
+       return True;
+   } else if((rid & RID_TYPE_MASK) == USER_RID_TYPE) {
+     return True;
+   }
+   return False;
 }
index abb037b95df0d565f6625c7f0d2c26c4efb0e908..003a1742e7397deb3ee26b9b5eb1e7a3863cc860 100644 (file)
@@ -433,9 +433,9 @@ static BOOL add_smbfilepwd_entry(struct smb_passwd *newpwd)
 
   int fd;
   int new_entry_length;
-  unsigned char *new_entry;
+  char *new_entry;
   long offpos;
-  unsigned char *p;
+  char *p;
 
   /* Open the smbpassword file - for update. */
   fp = startsmbfilepwent(True);