summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1997-09-15 05:43:37 +0000
committerAndrew Tridgell <tridge@samba.org>1997-09-15 05:43:37 +0000
commit552818e60eff4a87ece94f98c33424c93354bf6c (patch)
treeb5be8d5d2efd9aa4eef8823ea5283a2178385f70
parentddb2ce9d8100bd2c0475032b99869624db36304c (diff)
downloadsamba-552818e60eff4a87ece94f98c33424c93354bf6c.tar.gz
samba-552818e60eff4a87ece94f98c33424c93354bf6c.tar.bz2
samba-552818e60eff4a87ece94f98c33424c93354bf6c.zip
- change a lot of occurances of errno to use strerror(errno). We can't
assume all our users are programmers :-) - automatically create the smbpasswd file if it doesn't exist when running smbpasswd. (This used to be commit 1d2361bd2dec35bce029699f54c6a61fa739fa4b)
-rw-r--r--source3/lib/util.c8
-rw-r--r--source3/locking/shmem.c30
-rw-r--r--source3/utils/smbpasswd.c16
3 files changed, 29 insertions, 25 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index b0213912d1..22c1c3e43d 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -1488,7 +1488,7 @@ char *GetWd(char *str)
if (!sys_getwd(s))
{
- DEBUG(0,("Getwd failed, errno %d\n",errno));
+ DEBUG(0,("Getwd failed, errno %s\n",strerror(errno)));
return (NULL);
}
@@ -1951,7 +1951,7 @@ int read_udp_socket(int fd,char *buf,int len)
bzero((char *)&lastip,sizeof(lastip));
ret = recvfrom(fd,buf,len,0,&sock,&socklen);
if (ret <= 0) {
- DEBUG(2,("read socket failed. ERRNO=%d\n",errno));
+ DEBUG(2,("read socket failed. ERRNO=%s\n",strerror(errno)));
return(0);
}
@@ -2408,8 +2408,8 @@ BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type)
ret = (sendto(out_fd,buf,len,0,(struct sockaddr *)&sock_out,sizeof(sock_out)) >= 0);
if (!ret)
- DEBUG(0,("Packet send to %s(%d) failed ERRNO=%d\n",
- inet_ntoa(ip),port,errno));
+ DEBUG(0,("Packet send to %s(%d) failed ERRNO=%s\n",
+ inet_ntoa(ip),port,strerror(errno)));
close(out_fd);
return(ret);
diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c
index fc8dfbb9f3..bbb11f215a 100644
--- a/source3/locking/shmem.c
+++ b/source3/locking/shmem.c
@@ -94,7 +94,7 @@ static BOOL smb_shm_global_lock(void)
/* Do an exclusive wait lock on the first byte of the file */
if (fcntl_lock(smb_shm_fd, F_SETLKW, 0, 1, F_WRLCK) == False)
{
- DEBUG(0,("ERROR smb_shm_global_lock : fcntl_lock failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_global_lock : fcntl_lock failed with code %s\n",strerror(errno)));
smb_shm_times_locked--;
return False;
}
@@ -128,7 +128,7 @@ static BOOL smb_shm_global_unlock(void)
/* Do a wait unlock on the first byte of the file */
if (fcntl_lock(smb_shm_fd, F_SETLKW, 0, 1, F_UNLCK) == False)
{
- DEBUG(0,("ERROR smb_shm_global_unlock : fcntl_lock failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_global_unlock : fcntl_lock failed with code %s\n",strerror(errno)));
smb_shm_times_locked++;
return False;
}
@@ -178,7 +178,7 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
#endif /* SECURE_SHARE_MODES */
if ( smb_shm_processes_fd < 0 )
{
- DEBUG(0,("ERROR smb_shm_register_process : processreg_file open failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_register_process : processreg_file open failed with code %s\n",strerror(errno)));
return False;
}
@@ -208,7 +208,7 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
}
if (nb_read < 0)
{
- DEBUG(0,("ERROR smb_shm_register_process : processreg_file read failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_register_process : processreg_file read failed with code %s\n",strerror(errno)));
close(smb_shm_processes_fd);
return False;
}
@@ -220,7 +220,7 @@ static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *oth
lseek(smb_shm_processes_fd, free_slot, SEEK_SET);
if(write(smb_shm_processes_fd, &pid, sizeof(pid)) < 0)
{
- DEBUG(0,("ERROR smb_shm_register_process : processreg_file write failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_register_process : processreg_file write failed with code %s\n",strerror(errno)));
close(smb_shm_processes_fd);
return False;
}
@@ -246,7 +246,7 @@ static BOOL smb_shm_unregister_process(char *processreg_file, pid_t pid)
umask(old_umask);
if ( smb_shm_processes_fd < 0 )
{
- DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file open failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file open failed with code %s\n",strerror(errno)));
return False;
}
@@ -262,7 +262,7 @@ static BOOL smb_shm_unregister_process(char *processreg_file, pid_t pid)
erased_slot = lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
if(write(smb_shm_processes_fd, &other_pid, sizeof(other_pid)) < 0)
{
- DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file write failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file write failed with code %s\n",strerror(errno)));
close(smb_shm_processes_fd);
return False;
}
@@ -273,7 +273,7 @@ static BOOL smb_shm_unregister_process(char *processreg_file, pid_t pid)
}
if (nb_read < 0)
{
- DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file read failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file read failed with code %s\n",strerror(errno)));
close(smb_shm_processes_fd);
return False;
}
@@ -399,7 +399,7 @@ BOOL smb_shm_open( char *file_name, int size)
umask(old_umask);
if ( smb_shm_fd < 0 )
{
- DEBUG(0,("ERROR smb_shm_open : open failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_open : open failed with code %s\n",strerror(errno)));
return False;
}
@@ -411,7 +411,7 @@ BOOL smb_shm_open( char *file_name, int size)
if( (filesize = lseek(smb_shm_fd, 0, SEEK_END)) < 0)
{
- DEBUG(0,("ERROR smb_shm_open : lseek failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_open : lseek failed with code %s\n",strerror(errno)));
smb_shm_global_unlock();
close(smb_shm_fd);
return False;
@@ -446,7 +446,7 @@ BOOL smb_shm_open( char *file_name, int size)
/* we just created a new one, or are the first opener, lets set it size */
if( ftruncate(smb_shm_fd, size) <0)
{
- DEBUG(0,("ERROR smb_shm_open : ftruncate failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_open : ftruncate failed with code %s\n",strerror(errno)));
smb_shm_unregister_process(smb_shm_processreg_name, getpid());
smb_shm_global_unlock();
close(smb_shm_fd);
@@ -471,7 +471,7 @@ BOOL smb_shm_open( char *file_name, int size)
/* WARNING, smb_shm_header_p can be different for different processes mapping the same file ! */
if (smb_shm_header_p == (struct SmbShmHeader *)(-1))
{
- DEBUG(0,("ERROR smb_shm_open : mmap failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_open : mmap failed with code %s\n",strerror(errno)));
smb_shm_unregister_process(smb_shm_processreg_name, getpid());
smb_shm_global_unlock();
close(smb_shm_fd);
@@ -514,7 +514,7 @@ BOOL smb_shm_close( void )
if ((smb_shm_header_p != NULL) &&
(munmap((caddr_t)smb_shm_header_p, smb_shm_header_p->total_size) < 0))
{
- DEBUG(0,("ERROR smb_shm_close : munmap failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_close : munmap failed with code %s\n",strerror(errno)));
}
smb_shm_global_lock();
@@ -778,7 +778,7 @@ BOOL smb_shm_lock_hash_entry( unsigned int entry)
/* Do an exclusive wait lock on the 4 byte region mapping into this entry */
if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(smb_shm_offset_t), F_WRLCK) == False)
{
- DEBUG(0,("ERROR smb_shm_lock_hash_entry : fcntl_lock failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_lock_hash_entry : fcntl_lock failed with code %s\n",strerror(errno)));
return False;
}
@@ -809,7 +809,7 @@ BOOL smb_shm_unlock_hash_entry( unsigned int entry )
/* Do a wait lock on the 4 byte region mapping into this entry */
if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(smb_shm_offset_t), F_UNLCK) == False)
{
- DEBUG(0,("ERROR smb_shm_unlock_hash_entry : fcntl_lock failed with code %d\n",errno));
+ DEBUG(0,("ERROR smb_shm_unlock_hash_entry : fcntl_lock failed with code %s\n",strerror(errno)));
return False;
}
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index bbcefa6b18..c781427474 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/utils/smbpasswd.c
@@ -375,7 +375,7 @@ static void usage(char *name)
* Open the smbpaswd file XXXX - we need to parse smb.conf to get the
* filename
*/
- if ((fp = fopen(pfile, "r+")) == NULL) {
+ if ((fp = fopen(pfile, "a+")) == NULL) {
err = errno;
fprintf(stderr, "%s: Failed to open password file %s.\n",
argv[0], pfile);
@@ -383,6 +383,10 @@ static void usage(char *name)
perror(argv[0]);
exit(err);
}
+
+ /* position at the start of the file */
+ fseek(fp, 0, SEEK_SET);
+
/* Set read buffer to 16k for effiecient reads */
setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf));
@@ -425,7 +429,7 @@ static void usage(char *name)
if((offpos = lseek(fd, 0, SEEK_END)) == -1) {
fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \
-Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
+Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno));
fclose(fp);
pw_file_unlock(lockfd);
exit(1);
@@ -437,7 +441,7 @@ Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
strlen(pwd->pw_shell) + 1;
if((new_entry = (char *)malloc( new_entry_length )) == 0) {
fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \
-Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
+Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno));
fclose(fp);
pw_file_unlock(lockfd);
exit(1);
@@ -457,12 +461,12 @@ Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
pwd->pw_dir, pwd->pw_shell);
if(write(fd, new_entry, strlen(new_entry)) != strlen(new_entry)) {
fprintf(stderr, "%s: Failed to add entry for user %s to file %s. \
-Error was %d\n", argv[0], pwd->pw_name, pfile, errno);
+Error was %s\n", argv[0], pwd->pw_name, pfile, strerror(errno));
/* Remove the entry we just wrote. */
if(ftruncate(fd, offpos) == -1) {
fprintf(stderr, "%s: ERROR failed to ftruncate file %s. \
-Error was %d. Password file may be corrupt ! Please examine by hand !\n",
- argv[0], pwd->pw_name, errno);
+Error was %s. Password file may be corrupt ! Please examine by hand !\n",
+ argv[0], pwd->pw_name, strerror(errno));
}
fclose(fp);
pw_file_unlock(lockfd);