All of lore.kernel.org
 help / color / mirror / Atom feed
* home directory
@ 2002-06-03  9:56 Кузнецова Нина
  2002-06-03 10:32 ` Nicolas Costes
  0 siblings, 1 reply; 14+ messages in thread
From: Кузнецова Нина @ 2002-06-03  9:56 UTC (permalink / raw)
  To: linux-admin

Hi all! I want another  home directory mask (for example 755).
How I can change this mask during adduser operation?
Thanks for advises. Nina.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: home directory
  2002-06-03  9:56 home directory Кузнецова Нина
@ 2002-06-03 10:32 ` Nicolas Costes
       [not found]   ` <3CFC76FF.F41AB199@ns.kinetics.nsc.ru>
  0 siblings, 1 reply; 14+ messages in thread
From: Nicolas Costes @ 2002-06-03 10:32 UTC (permalink / raw)
  To: Кузнецова Нина,
	linux-admin


Hellorghhh !!!

Le Lundi 3 Juin 2002 11:56, Кузнецова Нина a ?crit :
> Hi all! I want another  home directory mask (for example 755).
> How I can change this mask during adduser operation?
> Thanks for advises. Nina.
>

Well, er....
I'd try:

#umask
022                   // Oh!!! This is my default mask...
#umask 027       // set your new mask, for 750 on directories.
#adduser XXXXXXXXXXX   // now add users !!!
#adduser XXXXXXXXXXX
#adduser XXXXXXXXXXX
#......
#umask 022       // Back to your default mask

I looked for an option of adduser to do this, but it seems that there's no...

@++
-- 
 ( °> Nicolas Costes
 //\\  IUT de La Roche / Yon
/ \/ ) Nicolas.costes@iut-laroche.univ-nantes.fr
`-<<  http://luxregina.free.fr
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: home directory
       [not found]   ` <3CFC76FF.F41AB199@ns.kinetics.nsc.ru>
@ 2002-06-04  9:25     ` Nicolas Costes
  2002-06-04 12:16       ` Milan P. Stanic
  0 siblings, 1 reply; 14+ messages in thread
From: Nicolas Costes @ 2002-06-04  9:25 UTC (permalink / raw)
  To: nina; +Cc: linux-admin

Le Mardi 4 Juin 2002 10:14, nina a ?crit :

> Thanks for advise, I am knew about umask command,
> but how I can change home  mask  during adduser operation?
> Regards, Nina.
>

Hello, Nina .

Well, I think I didn't  understand your whole question :-(
You said you want to change the home mask during "adduser", does that mean 
that you want the home directories to be created with a specific mask ?
e.g., all those directories will have permissions set to '750' (for a umask 
set to '027'), while your usual mask is '022' .... I am right ???
If you want such a behaviour, well, the 'adduser' command doesn't seem to 
have an option to achieve that...
So, i can see 3 solutions:
- Use 'umask xxx' before and after 'adduser', like in my last mail.
- Use 'adduser -k TEMPLATE', where template is a skeleton of the users's 
future directory, with right permissions set... But I think this solution 
won't work, because permissions may be inherited from the upper directory 
during the copy... Have a try :-)
- Create your users, their home, and then use 'chmod' command recursively to 
change the directories permissions (Make a script).

If lost in the middle of the pinguin, try 'man umask', 'man adduser' (Already 
done it ? Sorry.)

I think I read that you are new to 'umask' (New to Linux ?)... If not, well, 
sorry !!! But don't mind to ask me more details, I'll help you. And don't 
mind too to give me more details :-)

@+++

-- 
 ( œ> Nicolas Costes
 //\\  IUT de La Roche / Yon
/ \/ ) Nicolas.costes@iut-laroche.univ-nantes.fr
`-<<  http://luxregina.free.fr
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: home directory
  2002-06-04  9:25     ` Nicolas Costes
@ 2002-06-04 12:16       ` Milan P. Stanic
  0 siblings, 0 replies; 14+ messages in thread
From: Milan P. Stanic @ 2002-06-04 12:16 UTC (permalink / raw)
  To: linux-admin

On Tue, Jun 04, 2002 at 11:25:53AM +0200, Nicolas Costes wrote:
[...]
It depends which version of adduser in use. If it is script it can be
easy modified according to admin wishes. 
In any case we have source for our loved Linux, so ....
My answer is based on Debian, but IIRC in most distributions adduser
is a script.
 
> - Use 'adduser -k TEMPLATE', where template is a skeleton of the users's 
> future directory, with right permissions set... But I think this solution 
> won't work, because permissions may be inherited from the upper directory 
> during the copy... Have a try :-)

I think it will not work because modes are hard-coded into adduser script.

Quick hack can be to change adduser script (it is Perl). Find chmod
function in the script and set mode as you wish. BTW, there are separate
modes for system-user and normal-user.
 
Proper solution is to make this configurable trough /etc/adduser.conf
but that is job for "adduser" author/maintainer.

Milan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* HOME directory
@ 2005-04-25 16:27 HIToC
       [not found] ` <426D1DC8.2080900@hq.ntsp.nec.co.jp>
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: HIToC @ 2005-04-25 16:27 UTC (permalink / raw)
  To: linux-c-programming

Hello all!
	I am writing a piece of code that makes files, open directories in my
HOME directory. All worked well until I changed the name of my HOME dir.
To make the code portable I tried with use of '~' character:

	const char*	filename = "~/file.txt";
	ofstream	 my_file(filename, ios::out);

but this solution does not work.
Have you any suggestion to find the path of the current home directory or
the current user name?

Thanks for any suggestion.
-- 
With regards,


					HIToC
					hitoc_mail@yahoo.it

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
       [not found] ` <426D1DC8.2080900@hq.ntsp.nec.co.jp>
@ 2005-04-25 16:42   ` Ron Michael Khu
  2005-04-25 16:46     ` Ron Michael Khu
  0 siblings, 1 reply; 14+ messages in thread
From: Ron Michael Khu @ 2005-04-25 16:42 UTC (permalink / raw)
  To: linux-c-programming

I dont know what specific system calls are used for retreiving the 
current user or home dir(if there are any).
But perhaps u can make use of the getenv() function to retrieve the 
value of $HOME and $USER
(it may not work on some shells, though, didnt test it)




HIToC wrote:

>> Hello all!
>>     I am writing a piece of code that makes files, open directories 
>> in my
>> HOME directory. All worked well until I changed the name of my HOME dir.
>> To make the code portable I tried with use of '~' character:
>>
>>     const char*    filename = "~/file.txt";
>>     ofstream     my_file(filename, ios::out);
>>
>> but this solution does not work.
>> Have you any suggestion to find the path of the current home 
>> directory or
>> the current user name?
>>
>> Thanks for any suggestion.
>>  
>>
>
>



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
  2005-04-25 16:27 HOME directory HIToC
       [not found] ` <426D1DC8.2080900@hq.ntsp.nec.co.jp>
@ 2005-04-25 16:43 ` Benjamin Machuletz
  2005-04-25 16:59 ` Richard Nairn
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Benjamin Machuletz @ 2005-04-25 16:43 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 685 bytes --]

hi,

if you rename your home-directory, you have to change your /etc/passwd to 
point your user entry to the new home-directory.

benjamin,


On Monday 25 April 2005 18:27, HIToC wrote:
> Hello all!
>  I am writing a piece of code that makes files, open directories in my
> HOME directory. All worked well until I changed the name of my HOME dir.
> To make the code portable I tried with use of '~' character:
>
>  const char* filename = "~/file.txt";
>  ofstream  my_file(filename, ios::out);
>
> but this solution does not work.
> Have you any suggestion to find the path of the current home directory or
> the current user name?
>
> Thanks for any suggestion.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
  2005-04-25 16:42   ` Ron Michael Khu
@ 2005-04-25 16:46     ` Ron Michael Khu
  0 siblings, 0 replies; 14+ messages in thread
From: Ron Michael Khu @ 2005-04-25 16:46 UTC (permalink / raw)
  To: linux-c-programming

Ooops... inapplicable solution...
scratch it...


Ron Michael Khu wrote:

> I dont know what specific system calls are used for retreiving the 
> current user or home dir(if there are any).
> But perhaps u can make use of the getenv() function to retrieve the 
> value of $HOME and $USER
> (it may not work on some shells, though, didnt test it)
>
>
>
>
> HIToC wrote:
>
>>> Hello all!
>>>     I am writing a piece of code that makes files, open directories 
>>> in my
>>> HOME directory. All worked well until I changed the name of my HOME 
>>> dir.
>>> To make the code portable I tried with use of '~' character:
>>>
>>>     const char*    filename = "~/file.txt";
>>>     ofstream     my_file(filename, ios::out);
>>>
>>> but this solution does not work.
>>> Have you any suggestion to find the path of the current home 
>>> directory or
>>> the current user name?
>>>
>>> Thanks for any suggestion.
>>>  
>>>
>>
>>
>
>



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
@ 2005-04-25 16:50 Luciano Moreira - ht
  0 siblings, 0 replies; 14+ messages in thread
From: Luciano Moreira - ht @ 2005-04-25 16:50 UTC (permalink / raw)
  To: linux-c-programming

Yeah ! You need to read the desired environment variable (like HOME), 
using a API like "|char *getenv(const char */name/);".

After read, you shall concatenate the 2 strings:

char *pHome;
char *pMyDir="mydir/mysubdir";
char sFullPath[_MAX_PATH];

pHome = getenv("HOME");
sprintf(sFullPath, "%s/%s", pHome, pMyDir);

WARNING: "sprintf()" isn't the faster way to build a concatenated 
string. If you'll need to repeat this in a long loop, try another way 
using only a single call to "strcat()".

Luciano
|

HIToC escreveu:

>Hello all!
>	I am writing a piece of code that makes files, open directories in my
>HOME directory. All worked well until I changed the name of my HOME dir.
>To make the code portable I tried with use of '~' character:
>
>	const char*	filename = "~/file.txt";
>	ofstream	 my_file(filename, ios::out);
>
>but this solution does not work.
>Have you any suggestion to find the path of the current home directory or
>the current user name?
>
>Thanks for any suggestion.
>  
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
  2005-04-25 16:27 HOME directory HIToC
       [not found] ` <426D1DC8.2080900@hq.ntsp.nec.co.jp>
  2005-04-25 16:43 ` Benjamin Machuletz
@ 2005-04-25 16:59 ` Richard Nairn
  2005-04-25 17:05 ` Steve Graegert
  2005-04-25 17:06 ` Glynn Clements
  4 siblings, 0 replies; 14+ messages in thread
From: Richard Nairn @ 2005-04-25 16:59 UTC (permalink / raw)
  To: HIToC, linux-c-programming

You can use the environment variables to determine what the home directory  
is. Look at the manpage for getenv(3) and environ(5)

On Mon, 25 Apr 2005 10:27:59 -0600, HIToC <hitoc_mail@yahoo.it> wrote:

> Hello all!
> 	I am writing a piece of code that makes files, open directories in my
> HOME directory. All worked well until I changed the name of my HOME dir.
> To make the code portable I tried with use of '~' character:
>
> 	const char*	filename = "~/file.txt";
> 	ofstream	 my_file(filename, ios::out);
>
> but this solution does not work.
> Have you any suggestion to find the path of the current home directory or
> the current user name?
>
> Thanks for any suggestion.



-- 
  |       Richard Nairn          Specializing in Linux
  |     Nairn Consulting         Web / Database Solutions
  |        Calgary, AB
  | Richard@NairnConsulting.ca

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
  2005-04-25 16:27 HOME directory HIToC
                   ` (2 preceding siblings ...)
  2005-04-25 16:59 ` Richard Nairn
@ 2005-04-25 17:05 ` Steve Graegert
       [not found]   ` <426D38D3.5060901@tlen.pl>
  2005-04-25 17:06 ` Glynn Clements
  4 siblings, 1 reply; 14+ messages in thread
From: Steve Graegert @ 2005-04-25 17:05 UTC (permalink / raw)
  To: HIToC; +Cc: linux-c-programming

On 4/25/05, HIToC <hitoc_mail@yahoo.it> wrote:
> Hello all!
>         I am writing a piece of code that makes files, open directories in my
> HOME directory. All worked well until I changed the name of my HOME dir.
> To make the code portable I tried with use of '~' character:
> 
>         const char*     filename = "~/file.txt";
>         ofstream         my_file(filename, ios::out);
> 
> but this solution does not work.
> Have you any suggestion to find the path of the current home directory or
> the current user name?

All SUSv2/3 compliant systems know the system call getpwnam() to
obtain information about a given user by querying the passwd database.
 The following (untested) code snippet  demonstrates its usage.  Hope
this is what you're lookin' for.

----- BEGIN -----

#include <stdio.h>
#include <errno.h>
#include <pwd.h>

int main(int argc, char **argv)
{
    char *login_name;
    struct passwd *p;

    if (argc == 1) {
        if ((login_name = getlogin()) == NULL) {
            perror("getlogin() failed.\n");
            exit(errno);
        }
    } else if (argc == 2) {
        login_name = argv[1];
    }

    if ((p = getpwnam(login_name)) == NULL) {
        perror("getpwnam() failed.\n");
        exit(errno);
    }

    printf("HOME dir for %s: %s\n", login_name, p->pw_dir);

    return (0);
}

----- END -----

If you have questions or suggestions, feel free to drop me a line.

Kind Regards

    \Steve

--

Steve Graegert <graegerts@gmail.com>
Independent Software Consultant {C/C++ && Java && .NET}
Mobile: +49 (176)  21 24 88 69
Office: +49 (9131) 71 26 40 9

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
  2005-04-25 16:27 HOME directory HIToC
                   ` (3 preceding siblings ...)
  2005-04-25 17:05 ` Steve Graegert
@ 2005-04-25 17:06 ` Glynn Clements
  4 siblings, 0 replies; 14+ messages in thread
From: Glynn Clements @ 2005-04-25 17:06 UTC (permalink / raw)
  To: HIToC; +Cc: linux-c-programming


HIToC wrote:

> 	I am writing a piece of code that makes files, open directories in my
> HOME directory. All worked well until I changed the name of my HOME dir.
> To make the code portable I tried with use of '~' character:
> 
> 	const char*	filename = "~/file.txt";
> 	ofstream	 my_file(filename, ios::out);
> 
> but this solution does not work.
> Have you any suggestion to find the path of the current home directory or
> the current user name?

The "~" syntax is part of the shell; library functions won't expand
it. In the shell, "~/..." is equivalent to "$HOME/...".

If you want to respect $HOME (which is usually the case), use e.g.:

	const char *home = getenv("HOME");
	const char *file = "file.txt";
	char *path = alloca(strlen(home) + strlen(file) + 2);

	sprintf(path, "%s/%s", home, file);

	ofstream my_file(filename, ios::out);

If you want to always use the user's home directory from /etc/passwd
instead of $HOME (e.g. for setuid programs), use getpwuid(), e.g.:

	struct passwd *pw = getpwuid(getuid());
	if (!pw)
		fatal_error("user not listed in /etc/passwd");
	const char *home = pw->pw_dir;

	...

Similarly, the ~user syntax for a specific user's home directory is
implemented using getpwnam().

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
       [not found]     ` <6a00c8d505042511529bd72c8@mail.gmail.com>
@ 2005-04-26 11:26       ` Adam Dyga
  0 siblings, 0 replies; 14+ messages in thread
From: Adam Dyga @ 2005-04-26 11:26 UTC (permalink / raw)
  To: linux-c-programming

Steve Graegert wrote:

>On 4/25/05, Adam Dyga <adeon@tlen.pl> wrote:
>  
>
>>>All SUSv2/3 compliant systems know the system call getpwnam() to
>>>obtain information about a given user by querying the passwd database.
>>>The following (untested) code snippet  demonstrates its usage.  Hope
>>>this is what you're lookin' for.
>>>
>>>      
>>>
>>Note that for security reasons this way much better.
>>    
>>
>Relying on the shell environment is
>usually a bad idea since it can be manipulated and tweaked in many
>different ways.
>
That's exactly what I meant ;)

Cheers
AD

PS: Sorry, my previous reply should have gone to the group....

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: HOME directory
@ 2005-04-28 12:28 HIToC
  0 siblings, 0 replies; 14+ messages in thread
From: HIToC @ 2005-04-28 12:28 UTC (permalink / raw)
  To: linux-c-programming

Thank you for every suggestion!





HIToC


		
___________________________________ 
Nuovo Yahoo! Messenger: E' molto più divertente: Audibles, Avatar, Webcam, Giochi, Rubrica… Scaricalo ora! 
http://it.messenger.yahoo.it
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-04-28 12:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-25 16:27 HOME directory HIToC
     [not found] ` <426D1DC8.2080900@hq.ntsp.nec.co.jp>
2005-04-25 16:42   ` Ron Michael Khu
2005-04-25 16:46     ` Ron Michael Khu
2005-04-25 16:43 ` Benjamin Machuletz
2005-04-25 16:59 ` Richard Nairn
2005-04-25 17:05 ` Steve Graegert
     [not found]   ` <426D38D3.5060901@tlen.pl>
     [not found]     ` <6a00c8d505042511529bd72c8@mail.gmail.com>
2005-04-26 11:26       ` Adam Dyga
2005-04-25 17:06 ` Glynn Clements
  -- strict thread matches above, loose matches on Subject: below --
2005-04-28 12:28 HIToC
2005-04-25 16:50 Luciano Moreira - ht
2002-06-03  9:56 home directory Кузнецова Нина
2002-06-03 10:32 ` Nicolas Costes
     [not found]   ` <3CFC76FF.F41AB199@ns.kinetics.nsc.ru>
2002-06-04  9:25     ` Nicolas Costes
2002-06-04 12:16       ` Milan P. Stanic

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.