[Cvsnt] default username for pserver

Anthony Williams anthwil at nortelnetworks.com
Tue Jun 11 16:14:14 BST 2002


Community technical support mailing list was retired 2010 and replaced with a professional technical support team. For assistance please contact: Pre-sales Technical support via email to sales@march-hare.com.


Whoops, wrong version of the diff. Correct version below.

Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optical Components Ltd
The opinions expressed in this message are not necessarily those of my
employer

"Anthony Williams" <anthwil at nortelnetworks.com> wrote in message
news:ae2kkt$uag$1 at sisko.nothing-on.tv...
> I was just playing with pserver, and it occurred to me that it might be
nice
> if pserver used the currently-logged-on user by default. At the end of
this
> mail, there is a diff for protocols/pserver.c to allow this on both
Windows
> and UNIX. It might not work where the client is Windows and the server is
> UNIX (I haven't tried it), as windows has a tendency to return uppercase
> usernames, and UNIX systems tend to use lowercase usernames.

*** sol7/cvsnt-1.11.1.3/protocols/pserver.c Wed Feb 27 16:23:28 2002
--- cvsnt-1.11.1.3/protocols/pserver.c Tue Jun 11 16:03:48 2002
***************
*** 15,22 ****
--- 15,25 ----
  #include <string.h>
  #ifdef _WIN32
  #include <winsock.h>
+ #include <lmcons.h>
  #else
  #include <netdb.h>
+ #include <pwd.h>
+ #include <unistd.h>
  #endif

  #ifndef MAX_PATH
***************
*** 79,91 ****
   free(protocol->auth_repository);
  }

! static int pserver_validate(const struct protocol_interface *protocol,
const cvsroot_t *newroot)
  {
!  if(!newroot->username)
   {
!   server_error(0,"Username required");
!   return CVSPROTO_BADPARMS;
   }
   if(!newroot->hostname)
   {
    server_error(0,"Hostname required");
--- 82,114 ----
   free(protocol->auth_repository);
  }

! static const char* get_pserver_username(const cvsroot_t* current_root)
  {
!     const char* username;
! #ifdef _WIN32
!     static char username_buffer[UNLEN+1];
!     DWORD buffer_length=UNLEN+1;
! #endif
!
!     username=current_root->username;
!     if(!username)
!     {
! #ifdef _WIN32
!  if(GetUserName(username_buffer,&buffer_length))
   {
!      username=username_buffer;
   }
+ #else
+  username = getpwuid(getuid())->pw_name;
+ #endif
+     }
+
+     return username;
+ }
+
+
+ static int pserver_validate(const struct protocol_interface *protocol,
const cvsroot_t *newroot)
+ {
   if(!newroot->hostname)
   {
    server_error(0,"Hostname required");
***************
*** 106,112 ****
   const char *begin_request = "BEGIN AUTH REQUEST";
   const char *end_request = "END AUTH REQUEST";

!  if(!current_server->current_root->username ||
!current_server->current_root->hostname ||
!current_server->current_root->directory)
    return CVSPROTO_BADPARMS;

   port=pserver_get_port(protocol);
--- 129,139 ----
   const char *begin_request = "BEGIN AUTH REQUEST";
   const char *end_request = "END AUTH REQUEST";

!  const char *username=NULL;
!
!  username=get_pserver_username(current_server->current_root);
!
!  if(!username || !current_server->current_root->hostname ||
!current_server->current_root->directory)
    return CVSPROTO_BADPARMS;

   port=pserver_get_port(protocol);
***************
*** 118,124 ****
   }
   else
   {
!
if(pserver_get_user_password(current_server->current_root->username,current_
server->current_root->hostname,current_server->current_root->port,current_se
rver->current_root->directory,crypt_password,sizeof(crypt_password)))
    {
     /* Using null password - trace something out here */
     server_error(0,"Empty password used - try 'cvs login' with a real
password\n");
--- 145,151 ----
   }
   else
   {
!
if(pserver_get_user_password(username,current_server->current_root->hostname
,current_server->current_root->port,current_server->current_root->directory,
crypt_password,sizeof(crypt_password)))
    {
     /* Using null password - trace something out here */
     server_error(0,"Empty password used - try 'cvs login' with a real
password\n");
***************
*** 132,138 ****
    end_request = "END VERIFICATION REQUEST";
   }

!
if(tcp_printf("%s\n%s\n%s\n%s\n%s\n",begin_request,current_server->current_r
oot->directory,current_server->current_root->username,crypt_password,end_req
uest)<0)
    return CVSPROTO_FAIL;
   return CVSPROTO_SUCCESS;
  }
--- 159,165 ----
    end_request = "END VERIFICATION REQUEST";
   }

!
if(tcp_printf("%s\n%s\n%s\n%s\n%s\n",begin_request,current_server->current_r
oot->directory,username,crypt_password,end_request)<0)
    return CVSPROTO_FAIL;
   return CVSPROTO_SUCCESS;
  }
***************
*** 147,155 ****
  int pserver_login(const struct protocol_interface *protocol, char
*password)
  {
   char crypt_password[64];
   /* Store username & encrypted password in password store */
   pserver_crypt_password(password,crypt_password,sizeof(crypt_password));
!
if(pserver_set_user_password(current_server->current_root->username,current_
server->current_root->hostname,current_server->current_root->port,current_se
rver->current_root->directory,crypt_password))
   {
    server_error(1,"Failed to store password");
   }
--- 174,188 ----
  int pserver_login(const struct protocol_interface *protocol, char
*password)
  {
   char crypt_password[64];
+  const char *username=NULL;
+
   /* Store username & encrypted password in password store */
   pserver_crypt_password(password,crypt_password,sizeof(crypt_password));
!
!
!  username=get_pserver_username(current_server->current_root);
!
!
if(pserver_set_user_password(username,current_server->current_root->hostname
,current_server->current_root->port,current_server->current_root->directory,
crypt_password))
   {
    server_error(1,"Failed to store password");
   }
***************
*** 159,165 ****

  int pserver_logout(const struct protocol_interface *protocol)
  {
!
if(pserver_set_user_password(current_server->current_root->username,current_
server->current_root->hostname,current_server->current_root->port,current_se
rver->current_root->directory,NULL))
   {
    server_error(1,"Failed to delete password");
   }
--- 192,202 ----

  int pserver_logout(const struct protocol_interface *protocol)
  {
!  const char *username=NULL;
!
!  username=get_pserver_username(current_server->current_root);
!
!
if(pserver_set_user_password(username,current_server->current_root->hostname
,current_server->current_root->port,current_server->current_root->directory,
NULL))
   {
    server_error(1,"Failed to delete password");
   }





_______________________________________________
Cvsnt mailing list
Cvsnt at cvsnt.org
http://www.cvsnt.org/cgi-bin/mailman/listinfo/cvsnt https://www.march-hare.com/cvspro/en.asp#downcvs




More information about the cvsnt mailing list
Download the latest CVSNT, TortosieCVS, WinCVS etc. for Windows 8 etc.
@CVSNT on Twitter   CVSNT on Facebook