Re: useradd with empty -k doesn't chown/chmod new home directory

2013-09-10 Thread Craig R. Skinner
ping

On 2013-09-05 Thu 14:48 PM |, Todd C. Miller wrote:
 I changed my mind and decided it is better to just move the chown
 and chmod out of copydotfiles() and add an explicit check for skeldir
 set to the empty string.  Much as I would like to prettify the
 user.c code it is a losing battle so here is a minimal diff.
 
  - todd
 
 Index: usr.sbin/user/user.c
 ===
 RCS file: /home/cvs/openbsd/src/usr.sbin/user/user.c,v
 retrieving revision 1.95
 diff -u -r1.95 user.c
 --- usr.sbin/user/user.c  2 Apr 2013 05:04:47 -   1.95
 +++ usr.sbin/user/user.c  5 Sep 2013 20:47:23 -
 @@ -290,6 +290,8 @@
   DIR *dirp;
   int n;
  
 + if (*skeldir != '\0')
 + return 0;
   if ((dirp = opendir(skeldir)) == NULL) {
   warn(can't open source . files dir `%s', skeldir);
   return 0;
 @@ -308,8 +310,6 @@
   (void) asystem(cd %s  %s -rw -pe %s . %s,
   skeldir, PAX, (verbose) ? -v : , dir);
   }
 - (void) asystem(%s -R -P %u:%u %s, CHOWN, uid, gid, dir);
 - (void) asystem(%s -R u+w %s, CHMOD, dir);
   return n;
  }
  
 @@ -1177,6 +1177,9 @@
   err(EXIT_FAILURE, can't mkdir `%s', home);
   }
   (void) copydotfiles(up-u_skeldir, up-u_uid, gid, 
 home);
 + (void) asystem(%s -R -P %u:%u %s, CHOWN, up-u_uid,
 + gid, home);
 + (void) asystem(%s -R u+w %s, CHMOD, home);
   }
   }
   if (strcmp(up-u_primgrp, =uid) == 0 

-- 
Craig Skinner | http://twitter.com/Craig_Skinner | http://linkd.in/yGqkv7



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-09-07 Thread Craig R. Skinner
Solved?

On 2013-09-05 Thu 14:48 PM |, Todd C. Miller wrote:
 I changed my mind and decided it is better to just move the chown
 and chmod out of copydotfiles() and add an explicit check for skeldir
 set to the empty string.  Much as I would like to prettify the
 user.c code it is a losing battle so here is a minimal diff.
 
  - todd
 
 Index: usr.sbin/user/user.c
 ===
 RCS file: /home/cvs/openbsd/src/usr.sbin/user/user.c,v
 retrieving revision 1.95
 diff -u -r1.95 user.c
 --- usr.sbin/user/user.c  2 Apr 2013 05:04:47 -   1.95
 +++ usr.sbin/user/user.c  5 Sep 2013 20:47:23 -
 @@ -290,6 +290,8 @@
   DIR *dirp;
   int n;
  
 + if (*skeldir != '\0')
 + return 0;
   if ((dirp = opendir(skeldir)) == NULL) {
   warn(can't open source . files dir `%s', skeldir);
   return 0;
 @@ -308,8 +310,6 @@
   (void) asystem(cd %s  %s -rw -pe %s . %s,
   skeldir, PAX, (verbose) ? -v : , dir);
   }
 - (void) asystem(%s -R -P %u:%u %s, CHOWN, uid, gid, dir);
 - (void) asystem(%s -R u+w %s, CHMOD, dir);
   return n;
  }
  
 @@ -1177,6 +1177,9 @@
   err(EXIT_FAILURE, can't mkdir `%s', home);
   }
   (void) copydotfiles(up-u_skeldir, up-u_uid, gid, 
 home);
 + (void) asystem(%s -R -P %u:%u %s, CHOWN, up-u_uid,
 + gid, home);
 + (void) asystem(%s -R u+w %s, CHMOD, home);
   }
   }
   if (strcmp(up-u_primgrp, =uid) == 0 



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-09-05 Thread Craig R. Skinner
On 2013-08-31 Sat 11:18 AM |, Kenneth R Westerback wrote:
 
 This makes sense to me. ok krw@
 
  Ken
 

ping?
-- 
Craig Skinner | http://twitter.com/Craig_Skinner | http://linkd.in/yGqkv7



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-09-05 Thread Todd C. Miller
I changed my mind and decided it is better to just move the chown
and chmod out of copydotfiles() and add an explicit check for skeldir
set to the empty string.  Much as I would like to prettify the
user.c code it is a losing battle so here is a minimal diff.

 - todd

Index: usr.sbin/user/user.c
===
RCS file: /home/cvs/openbsd/src/usr.sbin/user/user.c,v
retrieving revision 1.95
diff -u -r1.95 user.c
--- usr.sbin/user/user.c2 Apr 2013 05:04:47 -   1.95
+++ usr.sbin/user/user.c5 Sep 2013 20:47:23 -
@@ -290,6 +290,8 @@
DIR *dirp;
int n;
 
+   if (*skeldir != '\0')
+   return 0;
if ((dirp = opendir(skeldir)) == NULL) {
warn(can't open source . files dir `%s', skeldir);
return 0;
@@ -308,8 +310,6 @@
(void) asystem(cd %s  %s -rw -pe %s . %s,
skeldir, PAX, (verbose) ? -v : , dir);
}
-   (void) asystem(%s -R -P %u:%u %s, CHOWN, uid, gid, dir);
-   (void) asystem(%s -R u+w %s, CHMOD, dir);
return n;
 }
 
@@ -1177,6 +1177,9 @@
err(EXIT_FAILURE, can't mkdir `%s', home);
}
(void) copydotfiles(up-u_skeldir, up-u_uid, gid, 
home);
+   (void) asystem(%s -R -P %u:%u %s, CHOWN, up-u_uid,
+   gid, home);
+   (void) asystem(%s -R u+w %s, CHMOD, home);
}
}
if (strcmp(up-u_primgrp, =uid) == 0 



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-09-05 Thread Alexander Hall


Todd C. Miller todd.mil...@courtesan.com wrote:
I changed my mind and decided it is better to just move the chown
and chmod out of copydotfiles() and add an explicit check for skeldir
set to the empty string.  Much as I would like to prettify the
user.c code it is a losing battle so here is a minimal diff.

 - todd

Index: usr.sbin/user/user.c
===
RCS file: /home/cvs/openbsd/src/usr.sbin/user/user.c,v
retrieving revision 1.95
diff -u -r1.95 user.c
--- usr.sbin/user/user.c   2 Apr 2013 05:04:47 -   1.95
+++ usr.sbin/user/user.c   5 Sep 2013 20:47:23 -
@@ -290,6 +290,8 @@
   DIR *dirp;
   int n;
 
+  if (*skeldir != '\0')
+  return 0;

Woot?

/A

   if ((dirp = opendir(skeldir)) == NULL) {
   warn(can't open source . files dir `%s', skeldir);
   return 0;
@@ -308,8 +310,6 @@
   (void) asystem(cd %s  %s -rw -pe %s . %s,
   skeldir, PAX, (verbose) ? -v : , dir);
   }
-  (void) asystem(%s -R -P %u:%u %s, CHOWN, uid, gid, dir);
-  (void) asystem(%s -R u+w %s, CHMOD, dir);
   return n;
 }
 
@@ -1177,6 +1177,9 @@
   err(EXIT_FAILURE, can't mkdir `%s', home);
   }
   (void) copydotfiles(up-u_skeldir, up-u_uid, gid, 
 home);
+  (void) asystem(%s -R -P %u:%u %s, CHOWN, up-u_uid,
+  gid, home);
+  (void) asystem(%s -R u+w %s, CHMOD, home);
   }
   }
   if (strcmp(up-u_primgrp, =uid) == 0 



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-09-02 Thread Craig R. Skinner
On 2013-08-31 Sat 11:45 AM |, patrick keshishian wrote:
 On Sat, Aug 31, 2013 at 06:23:25AM -0600, Todd C. Miller wrote:
  Assuming we want to make this a non-fatal error the following should
  do.
 
 You meant non-existent skel dir, not empty. Unless you
 meant empty argument for -k option, i.e., -k 

Yes, that was my intention. i.e. don't copy the skel dir

 but is there a good use-case for that?


For example, if an organisation had a number of database administrators
and they were added to the group 'dbas'.

In /home/dba there could be files, scripts, passwords,... that only the
DBA team should have common access to.

Likewise for hostmasters, postmasters, webmasters, management,
marketing, sales,

http://article.gmane.org/gmane.os.openbsd.bugs/19980



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-08-31 Thread Todd C. Miller
Assuming we want to make this a non-fatal error the following should
do.

 - todd

Index: usr.sbin/user/user.c
===
RCS file: /home/cvs/openbsd/src/usr.sbin/user/user.c,v
retrieving revision 1.95
diff -u -r1.95 user.c
--- usr.sbin/user/user.c2 Apr 2013 05:04:47 -   1.95
+++ usr.sbin/user/user.c31 Aug 2013 12:20:40 -
@@ -288,20 +288,20 @@
 {
struct dirent   *dp;
DIR *dirp;
-   int n;
+   int n = 0;
 
if ((dirp = opendir(skeldir)) == NULL) {
warn(can't open source . files dir `%s', skeldir);
-   return 0;
-   }
-   for (n = 0; (dp = readdir(dirp)) != NULL  n == 0 ; ) {
-   if (strcmp(dp-d_name, .) == 0 ||
-   strcmp(dp-d_name, ..) == 0) {
-   continue;
+   } else {
+   while ((dp = readdir(dirp)) != NULL) {
+   if (strcmp(dp-d_name, .) != 0 
+   strcmp(dp-d_name, ..) != 0) {
+   n = 1;
+   break;
+   }
}
-   n = 1;
+   (void) closedir(dirp);
}
-   (void) closedir(dirp);
if (n == 0) {
warnx(No \dot\ initialisation files found);
} else {



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-08-31 Thread Kenneth R Westerback
On Sat, Aug 31, 2013 at 06:23:25AM -0600, Todd C. Miller wrote:
 Assuming we want to make this a non-fatal error the following should
 do.
 
  - todd
 
 Index: usr.sbin/user/user.c
 ===
 RCS file: /home/cvs/openbsd/src/usr.sbin/user/user.c,v
 retrieving revision 1.95
 diff -u -r1.95 user.c
 --- usr.sbin/user/user.c  2 Apr 2013 05:04:47 -   1.95
 +++ usr.sbin/user/user.c  31 Aug 2013 12:20:40 -
 @@ -288,20 +288,20 @@
  {
   struct dirent   *dp;
   DIR *dirp;
 - int n;
 + int n = 0;
  
   if ((dirp = opendir(skeldir)) == NULL) {
   warn(can't open source . files dir `%s', skeldir);
 - return 0;
 - }
 - for (n = 0; (dp = readdir(dirp)) != NULL  n == 0 ; ) {
 - if (strcmp(dp-d_name, .) == 0 ||
 - strcmp(dp-d_name, ..) == 0) {
 - continue;
 + } else {
 + while ((dp = readdir(dirp)) != NULL) {
 + if (strcmp(dp-d_name, .) != 0 
 + strcmp(dp-d_name, ..) != 0) {
 + n = 1;
 + break;
 + }
   }
 - n = 1;
 + (void) closedir(dirp);
   }
 - (void) closedir(dirp);
   if (n == 0) {
   warnx(No \dot\ initialisation files found);
   } else {
 

This makes sense to me. ok krw@

 Ken



Re: useradd with empty -k doesn't chown/chmod new home directory

2013-08-31 Thread patrick keshishian
On Sat, Aug 31, 2013 at 06:23:25AM -0600, Todd C. Miller wrote:
 Assuming we want to make this a non-fatal error the following should
 do.

You meant non-existent skel dir, not empty. Unless you
meant empty argument for -k option, i.e., -k , but is
there a good use-case for that?

Also, I recall recently reading (on this list I believe)
keeping declaration and initialization separate.

--patrick


  - todd
 
 Index: usr.sbin/user/user.c
 ===
 RCS file: /home/cvs/openbsd/src/usr.sbin/user/user.c,v
 retrieving revision 1.95
 diff -u -r1.95 user.c
 --- usr.sbin/user/user.c  2 Apr 2013 05:04:47 -   1.95
 +++ usr.sbin/user/user.c  31 Aug 2013 12:20:40 -
 @@ -288,20 +288,20 @@
  {
   struct dirent   *dp;
   DIR *dirp;
 - int n;
 + int n = 0;
  
   if ((dirp = opendir(skeldir)) == NULL) {
   warn(can't open source . files dir `%s', skeldir);
 - return 0;
 - }
 - for (n = 0; (dp = readdir(dirp)) != NULL  n == 0 ; ) {
 - if (strcmp(dp-d_name, .) == 0 ||
 - strcmp(dp-d_name, ..) == 0) {
 - continue;
 + } else {
 + while ((dp = readdir(dirp)) != NULL) {
 + if (strcmp(dp-d_name, .) != 0 
 + strcmp(dp-d_name, ..) != 0) {
 + n = 1;
 + break;
 + }
   }
 - n = 1;
 + (void) closedir(dirp);
   }
 - (void) closedir(dirp);
   if (n == 0) {
   warnx(No \dot\ initialisation files found);
   } else {