zsh-users
 help / color / mirror / code / Atom feed
* can't write zsh_history
@ 2006-10-12 17:35 Michael Hernandez
  2006-10-12 18:02 ` Peter Stephenson
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Hernandez @ 2006-10-12 17:35 UTC (permalink / raw)
  To: zsh-users

Hi all,

Every now and then I need to su on some servers that I work on  
(mostly old freebsd systems that don't have sudo installed and have  
no outbound net connections, i.e. installing sudo is not an option).  
The problem, which is really more of an annoyance than a problem, is  
that if I su to run some command and I don't cd first,  
my .zsh_history file becomes owned by root. After I exit from # and  
run a command as my regular user, zsh tells me that it can't write  
the history file, which of course it can't because it's now owned by  
root. Is there something I can do to alter the way zsh writes to my  
history file when I am root? Something like "if uid is 0 then write  
the history to root's history file and leave .zsh_history alone"?  It  
should be noted that on these machines root's shell is tcsh, except  
in one case where it's ksh (not my idea I promise!) so I'm not sure  
why .zsh_history is touched at all when I'm root. Another oddity is  
that if I chown the file to my user, the file becomes corrupt, which  
is even more frustrating. The version of zsh for each of these  
machines is 4.2.6.

As I said, this is a minor annoyance, but I figured I'd ask in case  
someone else has experienced this before and has a remedy.

Thanks!

Mike H


PS. I just tested this on an openbsd 3.9 firewall that I have, with  
zsh version 4.2.6, and where root's shell is ksh. Same thing happens.


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

* Re: can't write zsh_history
  2006-10-12 17:35 can't write zsh_history Michael Hernandez
@ 2006-10-12 18:02 ` Peter Stephenson
  2006-10-13 14:27   ` William Scott
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2006-10-12 18:02 UTC (permalink / raw)
  To: zsh-users

Michael Hernandez wrote:
> The problem, which is really more of an annoyance than a problem, is  
> that if I su to run some command and I don't cd first,  
> my .zsh_history file becomes owned by root. After I exit from # and  
> run a command as my regular user, zsh tells me that it can't write  
> the history file, which of course it can't because it's now owned by  
> root. Is there something I can do to alter the way zsh writes to my  
> history file when I am root?

if (( ! EUID )); then
  HISTFILE=~/.history_root
else
  HISTFILE=~/.history
fi

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

* Re: can't write zsh_history
  2006-10-12 18:02 ` Peter Stephenson
@ 2006-10-13 14:27   ` William Scott
  2006-10-13 14:30     ` William Scott
                       ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: William Scott @ 2006-10-13 14:27 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users

>> root. Is there something I can do to alter the way zsh writes to my
>> history file when I am root?
>
> if (( ! EUID )); then
>  HISTFILE=~/.history_root
> else
>  HISTFILE=~/.history
> fi

You got my hopes up with this, but unfortunately I can't get this
to work, using my favorite security hole:

luser-%  sudo zsh
root-#   (various nefarious evildoing)
root-#   exit
zsh: can't write history file /Users/luser/.zsh_history

(I call it .zsh_history, BTW).

Even "sudo zsh -l" doesn't help.  $HISTFILE never changes.
I thought about having it update dynamically like $PWD,
but it seems like a lot of overhead for an occasional
irritation.  In addition, in my case at least the
ownership of ~/.zsh_history remains with luser.



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

* Re: can't write zsh_history
  2006-10-13 14:27   ` William Scott
@ 2006-10-13 14:30     ` William Scott
  2006-10-13 14:42       ` Michael Hernandez
  2006-10-13 16:44       ` Roman Neuhauser
  2006-10-13 14:56     ` Stanislaw Halik
                       ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: William Scott @ 2006-10-13 14:30 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users



On Fri, 13 Oct 2006, William Scott wrote:

>>> root. Is there something I can do to alter the way zsh writes to my
>>> history file when I am root?
>> 
>> if (( ! EUID )); then
>>  HISTFILE=~/.history_root
>> else
>>  HISTFILE=~/.history
>> fi
>
> You got my hopes up with this, but unfortunately I can't get this
> to work, using my favorite security hole:
>
> luser-%  sudo zsh
> root-#   (various nefarious evildoing)
> root-#   exit
> zsh: can't write history file /Users/luser/.zsh_history
>
> (I call it .zsh_history, BTW).
>
> Even "sudo zsh -l" doesn't help.  $HISTFILE never changes.
> I thought about having it update dynamically like $PWD,
> but it seems like a lot of overhead for an occasional
> irritation.  In addition, in my case at least the
> ownership of ~/.zsh_history remains with luser.
>
>

I should never post before morning coffee.  sudo /bin/zsh -l
corrects the problem; I had a differently behaving zsh at
the head of the $PATH.

So a slightly different question:

is there a way to alias

"sudo zsh"  to "sudo /bin/zsh -l" ?



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

* Re: can't write zsh_history
  2006-10-13 14:30     ` William Scott
@ 2006-10-13 14:42       ` Michael Hernandez
  2006-10-13 16:44       ` Roman Neuhauser
  1 sibling, 0 replies; 10+ messages in thread
From: Michael Hernandez @ 2006-10-13 14:42 UTC (permalink / raw)
  To: William Scott; +Cc: zsh-users

On Oct 13, 2006, at 10:30 AM, William Scott wrote:

>
>
> On Fri, 13 Oct 2006, William Scott wrote:
>
>>>> root. Is there something I can do to alter the way zsh writes to my
>>>> history file when I am root?
>>> if (( ! EUID )); then
>>>  HISTFILE=~/.history_root
>>> else
>>>  HISTFILE=~/.history
>>> fi
>>
>> You got my hopes up with this, but unfortunately I can't get this
>> to work, using my favorite security hole:
>>
>> luser-%  sudo zsh
>> root-#   (various nefarious evildoing)
>> root-#   exit
>> zsh: can't write history file /Users/luser/.zsh_history
>>
>> (I call it .zsh_history, BTW).
>>
>> Even "sudo zsh -l" doesn't help.  $HISTFILE never changes.
>> I thought about having it update dynamically like $PWD,
>> but it seems like a lot of overhead for an occasional
>> irritation.  In addition, in my case at least the
>> ownership of ~/.zsh_history remains with luser.
>>
>>
>
> I should never post before morning coffee.  sudo /bin/zsh -l
> corrects the problem; I had a differently behaving zsh at
> the head of the $PATH.
>
> So a slightly different question:
>
> is there a way to alias
>
> "sudo zsh"  to "sudo /bin/zsh -l" ?
>
>

I'd like to mention that I decided to  "su -" and not just "su"f, and  
this way I can use root's startup files and not have to worry about  
my files being touched.  It works .... for now ;)

Mike


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

* Re: can't write zsh_history
  2006-10-13 14:27   ` William Scott
  2006-10-13 14:30     ` William Scott
@ 2006-10-13 14:56     ` Stanislaw Halik
  2006-10-13 16:58     ` Jeremy Hankins
  2006-10-14  1:49     ` Phil Pennock
  3 siblings, 0 replies; 10+ messages in thread
From: Stanislaw Halik @ 2006-10-13 14:56 UTC (permalink / raw)
  To: zsh-users

On Fri, Oct 13, 2006, William Scott wrote:
> luser-%  sudo zsh
> root-#   (various nefarious evildoing)
> root-#   exit
> zsh: can't write history file /Users/luser/.zsh_history

> (I call it .zsh_history, BTW).

> Even "sudo zsh -l" doesn't help.  $HISTFILE never changes.
> I thought about having it update dynamically like $PWD,
> but it seems like a lot of overhead for an occasional
> irritation.  In addition, in my case at least the
> ownership of ~/.zsh_history remains with luser.

If zsh is your root shell, `sudo -i' will do.


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

* Re: can't write zsh_history
  2006-10-13 14:30     ` William Scott
  2006-10-13 14:42       ` Michael Hernandez
@ 2006-10-13 16:44       ` Roman Neuhauser
  1 sibling, 0 replies; 10+ messages in thread
From: Roman Neuhauser @ 2006-10-13 16:44 UTC (permalink / raw)
  To: William Scott; +Cc: zsh-users

# wgscott@chemistry.ucsc.edu / 2006-10-13 07:30:52 -0700:
> is there a way to alias
> 
> "sudo zsh"  to "sudo /bin/zsh -l" ?

    sudo()
    {
      if [ $# -eq 1 -a "x$1" = "xzsh" ]; then
        command sudo /bin/zsh -l
      else
        command sudo "$@"
      fi
    }

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991


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

* Re: can't write zsh_history
  2006-10-13 14:27   ` William Scott
  2006-10-13 14:30     ` William Scott
  2006-10-13 14:56     ` Stanislaw Halik
@ 2006-10-13 16:58     ` Jeremy Hankins
  2006-10-14  1:49     ` Phil Pennock
  3 siblings, 0 replies; 10+ messages in thread
From: Jeremy Hankins @ 2006-10-13 16:58 UTC (permalink / raw)
  To: zsh-users

William Scott <wgscott@chemistry.ucsc.edu> writes:

>> if (( ! EUID )); then
>>  HISTFILE=~/.history_root
>> else
>>  HISTFILE=~/.history
>> fi
>
> You got my hopes up with this, but unfortunately I can't get this
> to work, using my favorite security hole:

Where'd you put it?  Without 'su -' or 'zsh -l' or whatever, it's not a
login shell, so dot-files are read appropriately.  Did you try zshrc?

-- 
Jeremy Hankins <nowan@nowan.org>
PGP fingerprint: 748F 4D16 538E 75D6 8333  9E10 D212 B5ED 37D0 0A03


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

* Re: can't write zsh_history
  2006-10-13 14:27   ` William Scott
                       ` (2 preceding siblings ...)
  2006-10-13 16:58     ` Jeremy Hankins
@ 2006-10-14  1:49     ` Phil Pennock
  2006-10-14 20:46       ` William Scott
  3 siblings, 1 reply; 10+ messages in thread
From: Phil Pennock @ 2006-10-14  1:49 UTC (permalink / raw)
  To: William Scott; +Cc: zsh-users

On 2006-10-13 at 07:27 -0700, William Scott wrote:
> luser-%  sudo zsh
> root-#   (various nefarious evildoing)
> root-#   exit
> zsh: can't write history file /Users/luser/.zsh_history
> 
> (I call it .zsh_history, BTW).
> 
> Even "sudo zsh -l" doesn't help.  $HISTFILE never changes.

I strongly suspect that somewhere in your zsh startup files, you're
exporting HISTFILE to the environment.  The variable is used by tcsh
too, so tcsh will then be seeing the value and writing data in its own
format.  zsh later does sanity checks when writing its history, so
complains.

HISTFILE should be set, but not exported, being an internal control
variable.

In zsh:
% env | grep '^HISTFILE='

Regards,
-Phil


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

* Re: can't write zsh_history
  2006-10-14  1:49     ` Phil Pennock
@ 2006-10-14 20:46       ` William Scott
  0 siblings, 0 replies; 10+ messages in thread
From: William Scott @ 2006-10-14 20:46 UTC (permalink / raw)
  To: Phil Pennock; +Cc: zsh-users

>
> I strongly suspect that somewhere in your zsh startup files, you're
> exporting HISTFILE to the environment.  The variable is used by tcsh

Yes, it turns out I was (naively) exporting the variable.

I still need a function along the lines of what Roman Neuhauser suggested 
(although mine uses [[]] ).

Thanks.



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

end of thread, other threads:[~2006-10-14 20:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-12 17:35 can't write zsh_history Michael Hernandez
2006-10-12 18:02 ` Peter Stephenson
2006-10-13 14:27   ` William Scott
2006-10-13 14:30     ` William Scott
2006-10-13 14:42       ` Michael Hernandez
2006-10-13 16:44       ` Roman Neuhauser
2006-10-13 14:56     ` Stanislaw Halik
2006-10-13 16:58     ` Jeremy Hankins
2006-10-14  1:49     ` Phil Pennock
2006-10-14 20:46       ` William Scott

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).