[libvirt] [PATCH 02/11] storage: Support "username" for "chap" type "auth"

John Ferlan jferlan at redhat.com
Thu Jun 6 14:26:32 UTC 2013


On 05/28/2013 02:39 AM, Osier Yang wrote:
> To be consistent with what we use in disk auth, and "ceph" type
> storage "auth", this supports "username". "login" is still supported
> for back-compat reason.
> ---
>  docs/schemas/storagepool.rng                       | 12 +++++++---
>  src/conf/storage_conf.c                            | 27 ++++++++++++++++++----
>  .../storagepoolxml2xmlin/pool-iscsi-auth-login.xml | 17 ++++++++++++++
>  .../pool-iscsi-auth-username.xml                   | 17 ++++++++++++++
>  tests/storagepoolxml2xmlin/pool-iscsi-auth.xml     | 17 --------------
>  .../pool-iscsi-auth-login.xml                      | 20 ++++++++++++++++
>  .../pool-iscsi-auth-username.xml                   | 20 ++++++++++++++++
>  tests/storagepoolxml2xmlout/pool-iscsi-auth.xml    | 20 ----------------
>  .../pool-iscsi-vendor-product.xml                  |  2 +-
>  tests/storagepoolxml2xmltest.c                     |  3 ++-
>  10 files changed, 109 insertions(+), 46 deletions(-)
>  create mode 100644 tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml
>  create mode 100644 tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml
>  delete mode 100644 tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
>  create mode 100644 tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml
>  create mode 100644 tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml
>  delete mode 100644 tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
> 
> diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
> index 2595e37..ba6c741 100644
> --- a/docs/schemas/storagepool.rng
> +++ b/docs/schemas/storagepool.rng
> @@ -286,9 +286,15 @@
>              <value>chap</value>
>            </attribute>
>            <interleave>
> -            <attribute name='login'>
> -              <text/>
> -            </attribute>
> +            <choice>
> +              <!-- Legacy, but still supported to keep back-compat -->
> +              <attribute name='login'>
> +                <text/>
> +              </attribute>
> +              <attribute name='username'>
> +                <text/>
> +              </attribute>
> +            </choice>
>              <attribute name='passwd'>
>                <text/>
>              </attribute>
> diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
> index ed9effd..c0bf084 100644
> --- a/src/conf/storage_conf.c
> +++ b/src/conf/storage_conf.c
> @@ -444,13 +444,32 @@ static int
>  virStoragePoolDefParseAuthChap(xmlXPathContextPtr ctxt,
>                                 virStoragePoolAuthChapPtr auth)
>  {
> -    auth->login = virXPathString("string(./auth/@login)", ctxt);
> -    if (auth->login == NULL) {
> +    char *login = NULL;
> +    char *username = NULL;
> +
> +    login = virXPathString("string(./auth/@login)", ctxt);
> +    username = virXPathString("string(./auth/@username)", ctxt);
> +
> +    if (!login && !username) {
>          virReportError(VIR_ERR_XML_ERROR, "%s",
> -                       _("missing auth login attribute"));
> +                       _("missing auth login or username attribute"));
>          return -1;
>      }
>  
> +    if (login && username) {
> +        virReportError(VIR_ERR_XML_ERROR, "%s",
> +                       _("'login' is legacy name of 'username', they "
> +                         "are exclusive"));

Consider:

s/are exclusive/cannot both be supplied/

> +        VIR_FREE(login);
> +        VIR_FREE(username);
> +        return -1;
> +    }
> +
> +    if (login)
> +        auth->login = login;
> +    else if (username)
> +        auth->login = username;
> +
auth->login = username ? username : login;

Both cannot be NULL and both cannot be supplied.

>      auth->passwd = virXPathString("string(./auth/@passwd)", ctxt);
>      if (auth->passwd == NULL) {
>          virReportError(VIR_ERR_XML_ERROR, "%s",

hrmph... my question in 1/11 now seems negated since it seems passwd was
required after all.


ACK - just cleanup grammar in commit message and

John
> @@ -1101,7 +1120,7 @@ virStoragePoolSourceFormat(virBufferPtr buf,
>      }
>  
>      if (src->authType == VIR_STORAGE_POOL_AUTH_CHAP)
> -        virBufferAsprintf(buf,"    <auth type='chap' login='%s' passwd='%s'/>\n",
> +        virBufferAsprintf(buf,"    <auth type='chap' username='%s' passwd='%s'/>\n",
>                            src->auth.chap.login,
>                            src->auth.chap.passwd);
>  
> diff --git a/tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml b/tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml
> new file mode 100644
> index 0000000..f7d4d52
> --- /dev/null
> +++ b/tests/storagepoolxml2xmlin/pool-iscsi-auth-login.xml
> @@ -0,0 +1,17 @@
> +<pool type='iscsi'>
> +  <name>virtimages</name>
> +  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
> +  <source>
> +    <host name="iscsi.example.com"/>
> +    <device path="demo-target"/>
> +    <auth type='chap' login='foobar' passwd='frobbar'/>
> +  </source>
> +  <target>
> +    <path>/dev/disk/by-path</path>
> +    <permissions>
> +      <mode>0700</mode>
> +      <owner>0</owner>
> +      <group>0</group>
> +    </permissions>
> +  </target>
> +</pool>
> diff --git a/tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml b/tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml
> new file mode 100644
> index 0000000..b8e4d37
> --- /dev/null
> +++ b/tests/storagepoolxml2xmlin/pool-iscsi-auth-username.xml
> @@ -0,0 +1,17 @@
> +<pool type='iscsi'>
> +  <name>virtimages</name>
> +  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
> +  <source>
> +    <host name="iscsi.example.com"/>
> +    <device path="demo-target"/>
> +    <auth type='chap' username='foobar' passwd='frobbar'/>
> +  </source>
> +  <target>
> +    <path>/dev/disk/by-path</path>
> +    <permissions>
> +      <mode>0700</mode>
> +      <owner>0</owner>
> +      <group>0</group>
> +    </permissions>
> +  </target>
> +</pool>
> diff --git a/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml b/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
> deleted file mode 100644
> index f7d4d52..0000000
> --- a/tests/storagepoolxml2xmlin/pool-iscsi-auth.xml
> +++ /dev/null
> @@ -1,17 +0,0 @@
> -<pool type='iscsi'>
> -  <name>virtimages</name>
> -  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
> -  <source>
> -    <host name="iscsi.example.com"/>
> -    <device path="demo-target"/>
> -    <auth type='chap' login='foobar' passwd='frobbar'/>
> -  </source>
> -  <target>
> -    <path>/dev/disk/by-path</path>
> -    <permissions>
> -      <mode>0700</mode>
> -      <owner>0</owner>
> -      <group>0</group>
> -    </permissions>
> -  </target>
> -</pool>
> diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml b/tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml
> new file mode 100644
> index 0000000..5e3e8a2
> --- /dev/null
> +++ b/tests/storagepoolxml2xmlout/pool-iscsi-auth-login.xml
> @@ -0,0 +1,20 @@
> +<pool type='iscsi'>
> +  <name>virtimages</name>
> +  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
> +  <capacity unit='bytes'>0</capacity>
> +  <allocation unit='bytes'>0</allocation>
> +  <available unit='bytes'>0</available>
> +  <source>
> +    <host name='iscsi.example.com'/>
> +    <device path='demo-target'/>
> +    <auth type='chap' username='foobar' passwd='frobbar'/>
> +  </source>
> +  <target>
> +    <path>/dev/disk/by-path</path>
> +    <permissions>
> +      <mode>0700</mode>
> +      <owner>0</owner>
> +      <group>0</group>
> +    </permissions>
> +  </target>
> +</pool>
> diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml b/tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml
> new file mode 100644
> index 0000000..5e3e8a2
> --- /dev/null
> +++ b/tests/storagepoolxml2xmlout/pool-iscsi-auth-username.xml
> @@ -0,0 +1,20 @@
> +<pool type='iscsi'>
> +  <name>virtimages</name>
> +  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
> +  <capacity unit='bytes'>0</capacity>
> +  <allocation unit='bytes'>0</allocation>
> +  <available unit='bytes'>0</available>
> +  <source>
> +    <host name='iscsi.example.com'/>
> +    <device path='demo-target'/>
> +    <auth type='chap' username='foobar' passwd='frobbar'/>
> +  </source>
> +  <target>
> +    <path>/dev/disk/by-path</path>
> +    <permissions>
> +      <mode>0700</mode>
> +      <owner>0</owner>
> +      <group>0</group>
> +    </permissions>
> +  </target>
> +</pool>
> diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml b/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
> deleted file mode 100644
> index 4fa8f64..0000000
> --- a/tests/storagepoolxml2xmlout/pool-iscsi-auth.xml
> +++ /dev/null
> @@ -1,20 +0,0 @@
> -<pool type='iscsi'>
> -  <name>virtimages</name>
> -  <uuid>e9392370-2917-565e-692b-d057f46512d6</uuid>
> -  <capacity unit='bytes'>0</capacity>
> -  <allocation unit='bytes'>0</allocation>
> -  <available unit='bytes'>0</available>
> -  <source>
> -    <host name='iscsi.example.com'/>
> -    <device path='demo-target'/>
> -    <auth type='chap' login='foobar' passwd='frobbar'/>
> -  </source>
> -  <target>
> -    <path>/dev/disk/by-path</path>
> -    <permissions>
> -      <mode>0700</mode>
> -      <owner>0</owner>
> -      <group>0</group>
> -    </permissions>
> -  </target>
> -</pool>
> diff --git a/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml b/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml
> index 6ae1c39..9558e59 100644
> --- a/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml
> +++ b/tests/storagepoolxml2xmlout/pool-iscsi-vendor-product.xml
> @@ -7,7 +7,7 @@
>    <source>
>      <host name='iscsi.example.com'/>
>      <device path='demo-target'/>
> -    <auth type='chap' login='foobar' passwd='frobbar'/>
> +    <auth type='chap' username='foobar' passwd='frobbar'/>
>      <vendor name='test-vendor'/>
>      <product name='test-product'/>
>    </source>
> diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
> index 0376e63..b8935ee 100644
> --- a/tests/storagepoolxml2xmltest.c
> +++ b/tests/storagepoolxml2xmltest.c
> @@ -88,7 +88,8 @@ mymain(void)
>      DO_TEST("pool-logical-create");
>      DO_TEST("pool-disk");
>      DO_TEST("pool-iscsi");
> -    DO_TEST("pool-iscsi-auth");
> +    DO_TEST("pool-iscsi-auth-login");
> +    DO_TEST("pool-iscsi-auth-username");
>      DO_TEST("pool-netfs");
>      DO_TEST("pool-scsi");
>      DO_TEST("pool-scsi-type-scsi-host");
> 




More information about the libvir-list mailing list