| 1 |
/* |
| 2 |
* Copyright (C) 2008 Red Hat, Inc. |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General |
| 15 |
* Public License along with this library; if not, write to the |
| 16 |
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 17 |
* Boston, MA 02111-1307, USA. |
| 18 |
* |
| 19 |
* Author: David Zeuthen <[email protected]> |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
#include "polkitimplicitauthorization.h" |
| 25 |
#include "polkitprivate.h" |
| 26 |
|
| 27 |
gboolean |
| 28 |
polkit_implicit_authorization_from_string (const gchar *string, |
| 29 |
PolkitImplicitAuthorization *out_implicit_authorization) |
| 30 |
{ |
| 31 |
PolkitImplicitAuthorization result; |
| 32 |
gboolean ret; |
| 33 |
|
| 34 |
ret = TRUE; |
| 35 |
result = POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED; |
| 36 |
|
| 37 |
if (strcmp (string, "no") == 0) |
| 38 |
{ |
| 39 |
result = POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED; |
| 40 |
} |
| 41 |
else if (strcmp (string, "auth_self") == 0) |
| 42 |
{ |
| 43 |
result = POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED; |
| 44 |
} |
| 45 |
else if (strcmp (string, "auth_admin") == 0) |
| 46 |
{ |
| 47 |
result = POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED; |
| 48 |
} |
| 49 |
else if (strcmp (string, "auth_self_keep") == 0) |
| 50 |
{ |
| 51 |
result = POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED_RETAINED; |
| 52 |
} |
| 53 |
else if (strcmp (string, "auth_admin_keep") == 0) |
| 54 |
{ |
| 55 |
result = POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED_RETAINED; |
| 56 |
} |
| 57 |
else if (strcmp (string, "yes") == 0) |
| 58 |
{ |
| 59 |
result = POLKIT_IMPLICIT_AUTHORIZATION_AUTHORIZED; |
| 60 |
} |
| 61 |
else |
| 62 |
{ |
| 63 |
g_warning ("Unknown PolkitImplicitAuthorization string '%s'", string); |
| 64 |
ret = FALSE; |
| 65 |
result = POLKIT_IMPLICIT_AUTHORIZATION_UNKNOWN; |
| 66 |
} |
| 67 |
|
| 68 |
if (out_implicit_authorization != NULL) |
| 69 |
*out_implicit_authorization = result; |
| 70 |
|
| 71 |
return ret; |
| 72 |
} |
| 73 |
|
| 74 |
const gchar * |
| 75 |
polkit_implicit_authorization_to_string (PolkitImplicitAuthorization implicit_authorization) |
| 76 |
{ |
| 77 |
const gchar *s; |
| 78 |
|
| 79 |
s = "(unknown)"; |
| 80 |
|
| 81 |
switch (implicit_authorization) |
| 82 |
{ |
| 83 |
case POLKIT_IMPLICIT_AUTHORIZATION_UNKNOWN: |
| 84 |
s = "unknown"; |
| 85 |
break; |
| 86 |
|
| 87 |
case POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED: |
| 88 |
s = "no"; |
| 89 |
break; |
| 90 |
|
| 91 |
case POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED: |
| 92 |
s = "auth_self"; |
| 93 |
break; |
| 94 |
|
| 95 |
case POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED: |
| 96 |
s = "auth_admin"; |
| 97 |
break; |
| 98 |
|
| 99 |
case POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED_RETAINED: |
| 100 |
s = "auth_self_keep"; |
| 101 |
break; |
| 102 |
|
| 103 |
case POLKIT_IMPLICIT_AUTHORIZATION_ADMINISTRATOR_AUTHENTICATION_REQUIRED_RETAINED: |
| 104 |
s = "auth_admin_keep"; |
| 105 |
break; |
| 106 |
|
| 107 |
case POLKIT_IMPLICIT_AUTHORIZATION_AUTHORIZED: |
| 108 |
s = "yes"; |
| 109 |
break; |
| 110 |
} |
| 111 |
|
| 112 |
return s; |
| 113 |
} |