Patch from Oswald Buddenhagen <ossi@kde.org>
- move prompt for password to imap_open() - don't ask for global password in PREAUTH state - use socketpair() to create one full-duplex fd in tunnel mode instead of two half-duplex pipes - don't set lck.l_pid in fcntl() call (its read-only) - use F_SETLK instead of F_SETLKW to avoid infinite waiting - use "$@" in autogen.sh to get proper word expansion
This commit is contained in:
		
							parent
							
								
									1a1d2af012
								
							
						
					
					
						commit
						eb5f92821c
					
				
					 5 changed files with 47 additions and 61 deletions
				
			
		|  | @ -12,4 +12,4 @@ autoconf | |||
| if test $? -ne 0; then | ||||
| 	exit | ||||
| fi | ||||
| ./configure $@ | ||||
| ./configure "$@" | ||||
|  |  | |||
							
								
								
									
										14
									
								
								dotlock.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								dotlock.c
									
										
									
									
									
								
							|  | @ -31,19 +31,13 @@ | |||
| 
 | ||||
| static struct flock lck = { 0, SEEK_SET, 0, 0, 0 }; | ||||
| 
 | ||||
| static void make_lock (int type) | ||||
| { | ||||
|   lck.l_type = type; | ||||
|   lck.l_pid = getpid (); | ||||
| } | ||||
| 
 | ||||
| int dotlock_lock (const char *path, int *fd) | ||||
| { | ||||
|   *fd = open (path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); | ||||
|   if (*fd == -1) | ||||
|     return -1; | ||||
|   make_lock (F_WRLCK); | ||||
|   if (fcntl (*fd, F_SETLKW, &lck)) | ||||
|   lck.l_type = F_WRLCK; | ||||
|   if (fcntl (*fd, F_SETLK, &lck)) | ||||
|   { | ||||
|     close (*fd); | ||||
|     *fd = -1; | ||||
|  | @ -58,7 +52,7 @@ int dotlock_unlock (int *fd) | |||
| 
 | ||||
|   if (*fd != -1) | ||||
|   { | ||||
|     make_lock (F_UNLCK); | ||||
|     lck.l_type = F_UNLCK; | ||||
|     if (fcntl (*fd, F_SETLKW, &lck)) | ||||
|       r = -1; | ||||
|     close (*fd); | ||||
|  | @ -81,7 +75,7 @@ int main (void) | |||
|   sleep(5); | ||||
|   if (dotlock_unlock (&fd)) | ||||
|   { | ||||
|     perror ("dotlock_lock"); | ||||
|     perror ("dotlock_unlock"); | ||||
|   } | ||||
| done: | ||||
|   exit (0); | ||||
|  |  | |||
							
								
								
									
										68
									
								
								imap.c
									
										
									
									
									
								
							
							
						
						
									
										68
									
								
								imap.c
									
										
									
									
									
								
							|  | @ -179,7 +179,7 @@ socket_read (Socket_t * sock, char *buf, size_t len) | |||
|     if (sock->use_ssl) | ||||
| 	return SSL_read (sock->ssl, buf, len); | ||||
| #endif | ||||
|     return read (sock->rdfd, buf, len); | ||||
|     return read (sock->fd, buf, len); | ||||
| } | ||||
| 
 | ||||
| static int | ||||
|  | @ -189,7 +189,7 @@ socket_write (Socket_t * sock, char *buf, size_t len) | |||
|     if (sock->use_ssl) | ||||
| 	return SSL_write (sock->ssl, buf, len); | ||||
| #endif | ||||
|     return write (sock->wrfd, buf, len); | ||||
|     return write (sock->fd, buf, len); | ||||
| } | ||||
| 
 | ||||
| static void | ||||
|  | @ -224,9 +224,11 @@ socket_perror (const char *func, Socket_t *sock, int ret) | |||
|     } | ||||
| #else | ||||
|     (void) sock; | ||||
|     (void) ret; | ||||
| #endif | ||||
|     perror (func); | ||||
|     if (ret) | ||||
|       perror (func); | ||||
|     else | ||||
|       fprintf (stderr, "%s: unexpected EOF\n", func); | ||||
| } | ||||
| 
 | ||||
| /* simple line buffering */ | ||||
|  | @ -605,6 +607,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | |||
|     imap->sock = calloc (1, sizeof (Socket_t)); | ||||
|     imap->buf = calloc (1, sizeof (buffer_t)); | ||||
|     imap->buf->sock = imap->sock; | ||||
|     imap->sock->fd = -1; | ||||
|   } | ||||
| 
 | ||||
|   imap->box = box; | ||||
|  | @ -613,44 +616,35 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | |||
| 
 | ||||
|   if (!reuse) | ||||
|   { | ||||
|     int a[2]; | ||||
| 
 | ||||
|     /* open connection to IMAP server */ | ||||
| 
 | ||||
|     if (box->tunnel) | ||||
|     { | ||||
|       int a[2]; | ||||
|       int b[2]; | ||||
| 
 | ||||
|       printf ("Executing: %s...", box->tunnel); | ||||
|       printf ("Starting tunnel '%s'...", box->tunnel); | ||||
|       fflush (stdout); | ||||
| 
 | ||||
|       if (pipe (a)) | ||||
|       { | ||||
|       } | ||||
|       if (pipe (b)) | ||||
|       if (socketpair (PF_UNIX, SOCK_STREAM, 0, a)) | ||||
|       { | ||||
| 	perror ("socketpair"); | ||||
| 	exit (1); | ||||
|       } | ||||
| 
 | ||||
|       if (fork () == 0) | ||||
|       { | ||||
| 	if (dup2 (a[0],0)) | ||||
| 	if (dup2 (a[0],0) || dup2 (a[0], 1)) | ||||
| 	{ | ||||
| 	  _exit(127); | ||||
| 	} | ||||
| 	close (a[1]); | ||||
| 	if (dup2 (b[1],1)) | ||||
| 	{ | ||||
| 	  _exit (127); | ||||
| 	} | ||||
| 	close (b[0]); | ||||
| 	execl ("/bin/sh","sh","-c", box->tunnel); | ||||
| 	execl ("/bin/sh", "sh", "-c", box->tunnel); | ||||
| 	_exit (127); | ||||
|       } | ||||
| 
 | ||||
|       close (a[0]); | ||||
|       close (b[1]); | ||||
| 
 | ||||
|       imap->sock->rdfd = b[0]; | ||||
|       imap->sock->wrfd = a[1]; | ||||
|       imap->sock->fd = a[1]; | ||||
| 
 | ||||
|       puts ("ok"); | ||||
|     } | ||||
|  | @ -684,8 +678,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | |||
|       } | ||||
|       puts ("ok"); | ||||
| 
 | ||||
|       imap->sock->rdfd = s; | ||||
|       imap->sock->wrfd = s; | ||||
|       imap->sock->fd = s; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | @ -750,7 +743,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | |||
| 	  ret = -1; | ||||
| 	  break; | ||||
| 	} | ||||
| 	else | ||||
| 	else if (box->use_sslv2 || box->use_sslv3 || box->use_tlsv1) | ||||
| 	  puts ("Warning, SSL support not available"); | ||||
|       } | ||||
|       else | ||||
|  | @ -763,7 +756,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | |||
| 	} | ||||
| 
 | ||||
| 	imap->sock->ssl = SSL_new (SSLContext); | ||||
| 	SSL_set_fd (imap->sock->ssl, imap->sock->rdfd); | ||||
| 	SSL_set_fd (imap->sock->ssl, imap->sock->fd); | ||||
| 	ret = SSL_connect (imap->sock->ssl); | ||||
| 	if (ret <= 0) | ||||
| 	{ | ||||
|  | @ -796,6 +789,25 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | |||
|       if (!preauth) | ||||
|       { | ||||
| 	puts ("Logging in..."); | ||||
| 
 | ||||
| 	if (!box->pass) | ||||
| 	{ | ||||
| 	  /*
 | ||||
| 	   * if we don't have a global password set, prompt the user for | ||||
| 	   * it now. | ||||
| 	   */ | ||||
| 	  if (!global.pass) | ||||
| 	  { | ||||
| 	    global.pass = getpass ("Password:"); | ||||
| 	    if (!global.pass) | ||||
| 	    { | ||||
| 	      fprintf (stderr, "Skipping %s, no password", box->path); | ||||
| 	      break; | ||||
| 	    } | ||||
| 	  } | ||||
| 	  box->pass = strdup (global.pass); | ||||
| 	} | ||||
| 
 | ||||
| #if HAVE_LIBSSL | ||||
| 	if (imap->have_cram) | ||||
| 	{ | ||||
|  | @ -877,9 +889,7 @@ imap_close (imap_t * imap) | |||
|   if (imap) | ||||
|   { | ||||
|     imap_exec (imap, "LOGOUT"); | ||||
|     close (imap->sock->rdfd); | ||||
|     if (imap->sock->rdfd != imap->sock->wrfd) | ||||
|       close (imap->sock->wrfd); | ||||
|     close (imap->sock->fd); | ||||
|     free (imap->sock); | ||||
|     free (imap->buf); | ||||
|     free_message (imap->msgs); | ||||
|  |  | |||
							
								
								
									
										7
									
								
								isync.h
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								isync.h
									
										
									
									
									
								
							|  | @ -34,11 +34,10 @@ | |||
| 
 | ||||
| typedef struct | ||||
| { | ||||
|     int rdfd;	/* read filedes */ | ||||
|     int wrfd;	/* write filedes */ | ||||
|   int fd; | ||||
| #if HAVE_LIBSSL | ||||
|     SSL *ssl; | ||||
|     unsigned int use_ssl:1; | ||||
|   SSL *ssl; | ||||
|   unsigned int use_ssl:1; | ||||
| #endif | ||||
| } Socket_t; | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										17
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								main.c
									
										
									
									
									
								
							|  | @ -261,23 +261,6 @@ main (int argc, char **argv) | |||
| 	} | ||||
| 
 | ||||
| 	do { | ||||
| 	    if (!box->pass) | ||||
| 	    { | ||||
| 		/* if we don't have a global password set, prompt the user for
 | ||||
| 		 * it now. | ||||
| 		 */ | ||||
| 		if (!global.pass) | ||||
| 		{ | ||||
| 		    global.pass = getpass ("Password:"); | ||||
| 		    if (!global.pass) | ||||
| 		    { | ||||
| 			fprintf (stderr, "Skipping %s, no password", box->path); | ||||
| 			break; | ||||
| 		    } | ||||
| 		} | ||||
| 		box->pass = strdup (global.pass); | ||||
| 	    } | ||||
| 
 | ||||
| 	    if (!quiet) | ||||
| 		printf ("Reading %s\n", box->path); | ||||
| 	    i = 0; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue