Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
520dcc1c
Commit
520dcc1c
authored
Jan 08, 2013
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move credential helpers to their own (optional) header
parent
ffb02b16
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
50 deletions
+91
-50
include/git2/cred_helpers.h
+50
-0
include/git2/transport.h
+1
-20
src/transports/cred.c
+1
-20
src/transports/cred_helpers.c
+28
-0
tests-clar/network/cred.c
+8
-8
tests-clar/online/clone.c
+3
-2
No files found.
include/git2/cred_helpers.h
0 → 100644
View file @
520dcc1c
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_cred_helpers_h__
#define INCLUDE_git_cred_helpers_h__
#include "git2/transport.h"
/**
* @file git2/cred_helpers.h
* @brief Utility functions for credential management
* @defgroup git_cred_helpers credential management helpers
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Payload for git_cred_stock_userpass_plaintext.
*/
typedef
struct
git_cred_userpass_payload
{
char
*
username
;
char
*
password
;
}
git_cred_userpass_payload
;
/**
* Stock callback usable as a git_cred_acquire_cb. This calls
* git_cred_userpass_plaintext_new unless the protocol has not specified
* GIT_CREDTYPE_USERPASS_PLAINTEXT as an allowed type.
*
* @param cred The newly created credential object.
* @param url The resource for which we are demanding a credential.
* @param allowed_types A bitmask stating which cred types are OK to return.
* @param payload The payload provided when specifying this callback. (This is
* interpreted as a `git_cred_userpass_payload*`.)
*/
GIT_EXTERN
(
int
)
git_cred_userpass
(
git_cred
**
cred
,
const
char
*
url
,
unsigned
int
allowed_types
,
void
*
payload
);
/** @} */
GIT_END_DECL
#endif
include/git2/transport.h
View file @
520dcc1c
...
...
@@ -61,6 +61,7 @@ GIT_EXTERN(int) git_cred_userpass_plaintext_new(
* @param cred The newly created credential object.
* @param url The resource for which we are demanding a credential.
* @param allowed_types A bitmask stating which cred types are OK to return.
* @param payload The payload provided when specifying this callback.
*/
typedef
int
(
*
git_cred_acquire_cb
)(
git_cred
**
cred
,
...
...
@@ -68,26 +69,6 @@ typedef int (*git_cred_acquire_cb)(
unsigned
int
allowed_types
,
void
*
payload
);
/**
* Payload for git_cred_stock_userpass_plaintext.
*/
typedef
struct
git_cred_stock_userpass_plaintext_payload
{
char
*
username
;
char
*
password
;
}
git_cred_stock_userpass_plaintext_payload
;
/**
* Stock callback usable as a git_cred_acquire_cb. This calls
* git_cred_userpass_plaintext_new unless the protocol has not specified
* GIT_CREDTYPE_USERPASS_PLAINTEXT as an allowed type.
*/
GIT_EXTERN
(
int
)
git_cred_stock_userpass_plaintext
(
git_cred
**
cred
,
const
char
*
url
,
unsigned
int
allowed_types
,
void
*
payload
);
/*
*** End interface for credentials acquisition ***
*** Begin base transport interface ***
...
...
src/transports/cred.c
View file @
520dcc1c
...
...
@@ -7,6 +7,7 @@
#include "git2.h"
#include "smart.h"
#include "git2/cred_helpers.h"
static
void
plaintext_free
(
struct
git_cred
*
cred
)
{
...
...
@@ -57,23 +58,3 @@ int git_cred_userpass_plaintext_new(
*
cred
=
&
c
->
parent
;
return
0
;
}
int
git_cred_stock_userpass_plaintext
(
git_cred
**
cred
,
const
char
*
url
,
unsigned
int
allowed_types
,
void
*
payload
)
{
git_cred_stock_userpass_plaintext_payload
*
userpass
=
(
git_cred_stock_userpass_plaintext_payload
*
)
payload
;
GIT_UNUSED
(
url
);
if
(
!
userpass
||
!
userpass
->
username
||
!
userpass
->
password
)
return
-
1
;
if
((
GIT_CREDTYPE_USERPASS_PLAINTEXT
&
allowed_types
)
==
0
||
git_cred_userpass_plaintext_new
(
cred
,
userpass
->
username
,
userpass
->
password
)
<
0
)
return
-
1
;
return
0
;
}
src/transports/cred_helpers.c
0 → 100644
View file @
520dcc1c
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
#include "git2/cred_helpers.h"
int
git_cred_userpass
(
git_cred
**
cred
,
const
char
*
url
,
unsigned
int
allowed_types
,
void
*
payload
)
{
git_cred_userpass_payload
*
userpass
=
(
git_cred_userpass_payload
*
)
payload
;
GIT_UNUSED
(
url
);
if
(
!
userpass
||
!
userpass
->
username
||
!
userpass
->
password
)
return
-
1
;
if
((
GIT_CREDTYPE_USERPASS_PLAINTEXT
&
allowed_types
)
==
0
||
git_cred_userpass_plaintext_new
(
cred
,
userpass
->
username
,
userpass
->
password
)
<
0
)
return
-
1
;
return
0
;
}
tests-clar/network/cred.c
View file @
520dcc1c
#include "clar_libgit2.h"
#include "git2/
transport
.h"
#include "git2/
cred_helpers
.h"
void
test_network_cred__stock_userpass_validates_args
(
void
)
{
git_cred_
stock_userpass_plaintext
_payload
payload
=
{
0
};
git_cred_
userpass
_payload
payload
=
{
0
};
cl_git_fail
(
git_cred_
stock_userpass_plaintext
(
NULL
,
NULL
,
0
,
NULL
));
cl_git_fail
(
git_cred_
userpass
(
NULL
,
NULL
,
0
,
NULL
));
payload
.
username
=
"user"
;
cl_git_fail
(
git_cred_
stock_userpass_plaintext
(
NULL
,
NULL
,
0
,
&
payload
));
cl_git_fail
(
git_cred_
userpass
(
NULL
,
NULL
,
0
,
&
payload
));
payload
.
username
=
NULL
;
payload
.
username
=
"pass"
;
cl_git_fail
(
git_cred_
stock_userpass_plaintext
(
NULL
,
NULL
,
0
,
&
payload
));
cl_git_fail
(
git_cred_
userpass
(
NULL
,
NULL
,
0
,
&
payload
));
}
void
test_network_cred__stock_userpass_validates_that_method_is_allowed
(
void
)
{
git_cred
*
cred
;
git_cred_
stock_userpass_plaintext
_payload
payload
=
{
"user"
,
"pass"
};
git_cred_
userpass
_payload
payload
=
{
"user"
,
"pass"
};
cl_git_fail
(
git_cred_
stock_userpass_plaintext
(
&
cred
,
NULL
,
0
,
&
payload
));
cl_git_pass
(
git_cred_
stock_userpass_plaintext
(
&
cred
,
NULL
,
GIT_CREDTYPE_USERPASS_PLAINTEXT
,
&
payload
));
cl_git_fail
(
git_cred_
userpass
(
&
cred
,
NULL
,
0
,
&
payload
));
cl_git_pass
(
git_cred_
userpass
(
&
cred
,
NULL
,
GIT_CREDTYPE_USERPASS_PLAINTEXT
,
&
payload
));
git__free
(
cred
);
}
tests-clar/online/clone.c
View file @
520dcc1c
#include "clar_libgit2.h"
#include "git2/clone.h"
#include "git2/cred_helpers.h"
#include "repository.h"
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
...
...
@@ -138,14 +139,14 @@ void test_online_clone__credentials(void)
{
/* Remote URL environment variable must be set. User and password are optional. */
const
char
*
remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
git_cred_
stock_userpass_plaintext
_payload
user_pass
=
{
git_cred_
userpass
_payload
user_pass
=
{
cl_getenv
(
"GITTEST_REMOTE_USER"
),
cl_getenv
(
"GITTEST_REMOTE_PASS"
)
};
if
(
!
remote_url
)
return
;
g_options
.
cred_acquire_cb
=
git_cred_
stock_userpass_plaintext
;
g_options
.
cred_acquire_cb
=
git_cred_
userpass
;
g_options
.
cred_acquire_payload
=
&
user_pass
;
cl_git_pass
(
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment