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 | if test $? -ne 0; then | ||||||
| 	exit | 	exit | ||||||
| fi | fi | ||||||
| ./configure $@ | ./configure "$@" | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								dotlock.c
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								dotlock.c
									
										
									
									
									
								
							|  | @ -31,19 +31,13 @@ | ||||||
| 
 | 
 | ||||||
| static struct flock lck = { 0, SEEK_SET, 0, 0, 0 }; | 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) | int dotlock_lock (const char *path, int *fd) | ||||||
| { | { | ||||||
|   *fd = open (path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |   *fd = open (path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); | ||||||
|   if (*fd == -1) |   if (*fd == -1) | ||||||
|     return -1; |     return -1; | ||||||
|   make_lock (F_WRLCK); |   lck.l_type = F_WRLCK; | ||||||
|   if (fcntl (*fd, F_SETLKW, &lck)) |   if (fcntl (*fd, F_SETLK, &lck)) | ||||||
|   { |   { | ||||||
|     close (*fd); |     close (*fd); | ||||||
|     *fd = -1; |     *fd = -1; | ||||||
|  | @ -58,7 +52,7 @@ int dotlock_unlock (int *fd) | ||||||
| 
 | 
 | ||||||
|   if (*fd != -1) |   if (*fd != -1) | ||||||
|   { |   { | ||||||
|     make_lock (F_UNLCK); |     lck.l_type = F_UNLCK; | ||||||
|     if (fcntl (*fd, F_SETLKW, &lck)) |     if (fcntl (*fd, F_SETLKW, &lck)) | ||||||
|       r = -1; |       r = -1; | ||||||
|     close (*fd); |     close (*fd); | ||||||
|  | @ -81,7 +75,7 @@ int main (void) | ||||||
|   sleep(5); |   sleep(5); | ||||||
|   if (dotlock_unlock (&fd)) |   if (dotlock_unlock (&fd)) | ||||||
|   { |   { | ||||||
|     perror ("dotlock_lock"); |     perror ("dotlock_unlock"); | ||||||
|   } |   } | ||||||
| done: | done: | ||||||
|   exit (0); |   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) |     if (sock->use_ssl) | ||||||
| 	return SSL_read (sock->ssl, buf, len); | 	return SSL_read (sock->ssl, buf, len); | ||||||
| #endif | #endif | ||||||
|     return read (sock->rdfd, buf, len); |     return read (sock->fd, buf, len); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static int | static int | ||||||
|  | @ -189,7 +189,7 @@ socket_write (Socket_t * sock, char *buf, size_t len) | ||||||
|     if (sock->use_ssl) |     if (sock->use_ssl) | ||||||
| 	return SSL_write (sock->ssl, buf, len); | 	return SSL_write (sock->ssl, buf, len); | ||||||
| #endif | #endif | ||||||
|     return write (sock->wrfd, buf, len); |     return write (sock->fd, buf, len); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
|  | @ -224,9 +224,11 @@ socket_perror (const char *func, Socket_t *sock, int ret) | ||||||
|     } |     } | ||||||
| #else | #else | ||||||
|     (void) sock; |     (void) sock; | ||||||
|     (void) ret; |  | ||||||
| #endif | #endif | ||||||
|     perror (func); |     if (ret) | ||||||
|  |       perror (func); | ||||||
|  |     else | ||||||
|  |       fprintf (stderr, "%s: unexpected EOF\n", func); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* simple line buffering */ | /* 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->sock = calloc (1, sizeof (Socket_t)); | ||||||
|     imap->buf = calloc (1, sizeof (buffer_t)); |     imap->buf = calloc (1, sizeof (buffer_t)); | ||||||
|     imap->buf->sock = imap->sock; |     imap->buf->sock = imap->sock; | ||||||
|  |     imap->sock->fd = -1; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   imap->box = box; |   imap->box = box; | ||||||
|  | @ -613,44 +616,35 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | ||||||
| 
 | 
 | ||||||
|   if (!reuse) |   if (!reuse) | ||||||
|   { |   { | ||||||
|  |     int a[2]; | ||||||
|  | 
 | ||||||
|     /* open connection to IMAP server */ |     /* open connection to IMAP server */ | ||||||
| 
 | 
 | ||||||
|     if (box->tunnel) |     if (box->tunnel) | ||||||
|     { |     { | ||||||
|       int a[2]; |       printf ("Starting tunnel '%s'...", box->tunnel); | ||||||
|       int b[2]; |  | ||||||
| 
 |  | ||||||
|       printf ("Executing: %s...", box->tunnel); |  | ||||||
|       fflush (stdout); |       fflush (stdout); | ||||||
| 
 | 
 | ||||||
|       if (pipe (a)) |       if (socketpair (PF_UNIX, SOCK_STREAM, 0, a)) | ||||||
|       { |  | ||||||
|       } |  | ||||||
|       if (pipe (b)) |  | ||||||
|       { |       { | ||||||
|  | 	perror ("socketpair"); | ||||||
|  | 	exit (1); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (fork () == 0) |       if (fork () == 0) | ||||||
|       { |       { | ||||||
| 	if (dup2 (a[0],0)) | 	if (dup2 (a[0],0) || dup2 (a[0], 1)) | ||||||
| 	{ | 	{ | ||||||
| 	  _exit(127); | 	  _exit(127); | ||||||
| 	} | 	} | ||||||
| 	close (a[1]); | 	close (a[1]); | ||||||
| 	if (dup2 (b[1],1)) | 	execl ("/bin/sh", "sh", "-c", box->tunnel); | ||||||
| 	{ |  | ||||||
| 	  _exit (127); |  | ||||||
| 	} |  | ||||||
| 	close (b[0]); |  | ||||||
| 	execl ("/bin/sh","sh","-c", box->tunnel); |  | ||||||
| 	_exit (127); | 	_exit (127); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       close (a[0]); |       close (a[0]); | ||||||
|       close (b[1]); |  | ||||||
| 
 | 
 | ||||||
|       imap->sock->rdfd = b[0]; |       imap->sock->fd = a[1]; | ||||||
|       imap->sock->wrfd = a[1]; |  | ||||||
| 
 | 
 | ||||||
|       puts ("ok"); |       puts ("ok"); | ||||||
|     } |     } | ||||||
|  | @ -684,8 +678,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | ||||||
|       } |       } | ||||||
|       puts ("ok"); |       puts ("ok"); | ||||||
| 
 | 
 | ||||||
|       imap->sock->rdfd = s; |       imap->sock->fd = s; | ||||||
|       imap->sock->wrfd = s; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -750,7 +743,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | ||||||
| 	  ret = -1; | 	  ret = -1; | ||||||
| 	  break; | 	  break; | ||||||
| 	} | 	} | ||||||
| 	else | 	else if (box->use_sslv2 || box->use_sslv3 || box->use_tlsv1) | ||||||
| 	  puts ("Warning, SSL support not available"); | 	  puts ("Warning, SSL support not available"); | ||||||
|       } |       } | ||||||
|       else |       else | ||||||
|  | @ -763,7 +756,7 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	imap->sock->ssl = SSL_new (SSLContext); | 	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); | 	ret = SSL_connect (imap->sock->ssl); | ||||||
| 	if (ret <= 0) | 	if (ret <= 0) | ||||||
| 	{ | 	{ | ||||||
|  | @ -796,6 +789,25 @@ imap_open (config_t * box, unsigned int minuid, imap_t * imap, int flags) | ||||||
|       if (!preauth) |       if (!preauth) | ||||||
|       { |       { | ||||||
| 	puts ("Logging in..."); | 	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 HAVE_LIBSSL | ||||||
| 	if (imap->have_cram) | 	if (imap->have_cram) | ||||||
| 	{ | 	{ | ||||||
|  | @ -877,9 +889,7 @@ imap_close (imap_t * imap) | ||||||
|   if (imap) |   if (imap) | ||||||
|   { |   { | ||||||
|     imap_exec (imap, "LOGOUT"); |     imap_exec (imap, "LOGOUT"); | ||||||
|     close (imap->sock->rdfd); |     close (imap->sock->fd); | ||||||
|     if (imap->sock->rdfd != imap->sock->wrfd) |  | ||||||
|       close (imap->sock->wrfd); |  | ||||||
|     free (imap->sock); |     free (imap->sock); | ||||||
|     free (imap->buf); |     free (imap->buf); | ||||||
|     free_message (imap->msgs); |     free_message (imap->msgs); | ||||||
|  |  | ||||||
							
								
								
									
										7
									
								
								isync.h
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								isync.h
									
										
									
									
									
								
							|  | @ -34,11 +34,10 @@ | ||||||
| 
 | 
 | ||||||
| typedef struct | typedef struct | ||||||
| { | { | ||||||
|     int rdfd;	/* read filedes */ |   int fd; | ||||||
|     int wrfd;	/* write filedes */ |  | ||||||
| #if HAVE_LIBSSL | #if HAVE_LIBSSL | ||||||
|     SSL *ssl; |   SSL *ssl; | ||||||
|     unsigned int use_ssl:1; |   unsigned int use_ssl:1; | ||||||
| #endif | #endif | ||||||
| } Socket_t; | } Socket_t; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								main.c
									
										
									
									
									
								
							|  | @ -261,23 +261,6 @@ main (int argc, char **argv) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	do { | 	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) | 	    if (!quiet) | ||||||
| 		printf ("Reading %s\n", box->path); | 		printf ("Reading %s\n", box->path); | ||||||
| 	    i = 0; | 	    i = 0; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue