Browse code

- Applied Jakob Schlyter's Rpid patch.

Jan Janak authored on 15/09/2003 19:47:02
Showing 5 changed files
... ...
@@ -83,10 +83,12 @@ int (*sl_reply)(struct sip_msg* _msg, char* _str1, char* _str2);
83 83
 char* db_url           = DEFAULT_RODB_URL;
84 84
 char* user_column      = "username";
85 85
 char* domain_column    = "domain";
86
+char* rpid_column      = "rpid";
86 87
 char* pass_column      = "ha1";
87 88
 char* pass_column_2    = "ha1b";
88 89
 int   calc_ha1         = 0;
89 90
 int   use_domain       = 1;    /* Use also domain when looking up a table row */
91
+int   use_rpid         = 0;    /* Fetch Remote-Party-ID */
90 92
 
91 93
 db_con_t* db_handle;   /* Database connection handle */
92 94
 
... ...
@@ -108,10 +110,12 @@ static param_export_t params[] = {
108 110
 	{"db_url",            STR_PARAM, &db_url       },
109 111
 	{"user_column",       STR_PARAM, &user_column  },
110 112
 	{"domain_column",     STR_PARAM, &domain_column},
113
+	{"rpid_column",       STR_PARAM, &rpid_column  },
111 114
 	{"password_column",   STR_PARAM, &pass_column  },
112 115
 	{"password_column_2", STR_PARAM, &pass_column_2},
113 116
 	{"calculate_ha1",     INT_PARAM, &calc_ha1     },
114 117
 	{"use_domain",        INT_PARAM, &use_domain   },
118
+	{"use_rpid",          INT_PARAM, &use_rpid     },
115 119
 	{0, 0, 0}
116 120
 };
117 121
 
... ...
@@ -43,6 +43,7 @@
43 43
 extern char* db_url;          /* Database URL */
44 44
 extern char* user_column;     /* 'username' column name */
45 45
 extern char* domain_column;   /* 'domain' column name */
46
+extern char* rpid_column;     /* 'rpid' column name */
46 47
 extern char* pass_column;     /* 'password' column name */
47 48
 extern char* pass_column_2;   /* Column containg HA1 string constructed
48 49
 			       * of user@domain username
... ...
@@ -50,6 +51,7 @@ extern char* pass_column_2;   /* Column containg HA1 string constructed
50 51
 
51 52
 extern int calc_ha1;          /* if set to 1, ha1 is calculated by the server */
52 53
 extern int use_domain;        /* If set to 1 then the domain will be used when selecting a row */
54
+extern int use_rpid;          /* If set to 1 then rpid will be fetched from rpid_column */
53 55
 extern db_con_t* db_handle;   /* Database connection handle */
54 56
 
55 57
 extern pre_auth_f pre_auth_func;
... ...
@@ -47,17 +47,19 @@
47 47
 #define MESSAGE_500 "Server Internal Error"
48 48
 
49 49
 
50
-static inline int get_ha1(struct username* _username, str* _domain, char* _table, char* _ha1)
50
+static inline int get_ha1(struct username* _username, str* _domain, char* _table, char* _ha1, char* _rpid)
51 51
 {
52 52
 	db_key_t keys[2];
53 53
 	db_val_t vals[2];
54
-	db_key_t col[1];
54
+	db_key_t col[2];
55 55
 	db_res_t* res;
56 56
 	str result;
57
+	int n, nc;
57 58
 
58 59
 	keys[0] = user_column;
59 60
 	keys[1] = domain_column;
60 61
 	col[0] = (_username->domain.len && !calc_ha1) ? (pass_column_2) : (pass_column);	
62
+	col[1] = rpid_column;
61 63
 
62 64
 	VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR;
63 65
 	VAL_NULL(vals) = VAL_NULL(vals + 1) = 0;
... ...
@@ -68,8 +70,10 @@ static inline int get_ha1(struct username* _username, str* _domain, char* _table
68 70
 	VAL_STR(vals + 1).s = _domain->s;
69 71
 	VAL_STR(vals + 1).len = _domain->len;
70 72
 
73
+	n = (use_domain ? 2 : 1);
74
+	nc = (use_rpid ? 2 : 1);
71 75
 	db_use_table(db_handle, _table);
72
-	if (db_query(db_handle, keys, 0, vals, col, (use_domain ? 2 : 1), 1, 0, &res) < 0) {
76
+	if (db_query(db_handle, keys, 0, vals, col, n, nc, 0, &res) < 0) {
73 77
 		LOG(L_ERR, "get_ha1(): Error while querying database\n");
74 78
 		return -1;
75 79
 	}
... ...
@@ -94,11 +98,18 @@ static inline int get_ha1(struct username* _username, str* _domain, char* _table
94 98
 		_ha1[result.len] = '\0';
95 99
 	}
96 100
 
101
+	if (use_rpid && VAL_NULL(&(res->rows[0].values[1])) != 1) {
102
+		result.s = (char*)VAL_STRING(&(res->rows[0].values[1]));
103
+		result.len = strlen(result.s);
104
+		memcpy(_rpid, result.s, result.len);
105
+		_rpid[result.len] = '\0';
106
+		DBG("RPID: %s\n", _rpid);
107
+	}
108
+
97 109
 	db_free_query(db_handle, res);
98 110
 	return 0;
99 111
 }
100 112
 
101
-
102 113
 /*
103 114
  * Calculate the response and compare with the given response string
104 115
  * Authorization is successfull if this two strings are same
... ...
@@ -147,6 +158,7 @@ static inline int check_response(dig_cred_t* _cred, str* _method, char* _ha1)
147 158
 static inline int authorize(struct sip_msg* _m, str* _realm, char* _table, int _hftype)
148 159
 {
149 160
 	char ha1[256];
161
+	char rpid_buffer[MAX_RPID_LEN];
150 162
 	int res;
151 163
 	struct hdr_field* h;
152 164
 	auth_body_t* cred;
... ...
@@ -166,7 +178,7 @@ static inline int authorize(struct sip_msg* _m, str* _realm, char* _table, int _
166 178
 
167 179
 	cred = (auth_body_t*)h->parsed;
168 180
 
169
-	res = get_ha1(&cred->digest.username, &domain, _table, ha1);
181
+	res = get_ha1(&cred->digest.username, &domain, _table, ha1, rpid_buffer);
170 182
         if (res < 0) {
171 183
 		     /* Error while accessing the database */
172 184
 		if (sl_reply(_m, (char*)500, MESSAGE_500) == -1) {
... ...
@@ -178,12 +190,16 @@ static inline int authorize(struct sip_msg* _m, str* _realm, char* _table, int _
178 190
 		return -1;
179 191
 	}
180 192
 
181
-	     /* Recalculate response, it must be same to authorize sucessfully */
182
-        if (!check_response(&(cred->digest), &_m->first_line.u.request.method, ha1)) {
183
-		     /* Not supported yet */
184
-		rpid.s = 0;
193
+	if (use_rpid) {
194
+		rpid.s = rpid_buffer;
195
+		rpid.len = strlen(rpid_buffer);
196
+	} else {
197
+		rpid.s = NULL;
185 198
 		rpid.len = 0;
199
+	}
186 200
 
201
+	     /* Recalculate response, it must be same to authorize sucessfully */
202
+        if (!check_response(&(cred->digest), &_m->first_line.u.request.method, ha1)) {
187 203
 		ret = post_auth_func(_m, h, &rpid);
188 204
 		switch(ret) {
189 205
 		case ERROR:          return 0;
... ...
@@ -17,6 +17,11 @@
17 17
 		<affiliation><orgname>FhG Fokus</orgname></affiliation>
18 18
 		<email>jan@iptel.org</email>
19 19
 	    </author>
20
+	    <author>
21
+		<firstname>Jakob</firstname>
22
+		<surname>Schlyter</surname>
23
+		<email>jakob@schlyter.se</email>
24
+	    </author>
20 25
 	    <editor>
21 26
 		<firstname>Jan</firstname>
22 27
 		<surname>Janak</surname>
... ...
@@ -104,6 +104,22 @@ modparam("auth_db", "domain_column", "domain")
104 104
 		<title><varname>password_column</varname> usage</title>
105 105
 		<programlisting format="linespecific">
106 106
 modparam("auth_db", "password_column", "password")
107
+</programlisting>
108
+	    </example>
109
+	</section>
110
+	<section>
111
+	    <title><varname>rpid_column</varname> (string)</title>
112
+	    <para>
113
+		This is the name of the column holding information for the Remote-Party-ID header field. Default value is fine for most
114
+		people. Use the parameter if you really need to change it.
115
+	    </para>
116
+	    <para>
117
+		Default value is <quote>rpid</quote>.
118
+	    </para>
119
+	    <example>
120
+		<title><varname>rpid_column</varname> usage</title>
121
+		<programlisting format="linespecific">
122
+modparam("auth_db", "rpid_column", "remote_party_id")
107 123
 </programlisting>
108 124
 	    </example>
109 125
 	</section>
... ...
@@ -154,6 +170,24 @@ modparam("auth_db", "calculate_ha1", 1)
154 170
 		<title><varname>password_column_2</varname> usage</title>
155 171
 		<programlisting format="linespecific">
156 172
 modparam("auth_db", "password_column_2", "ha1_2")
173
+</programlisting>
174
+	    </example>
175
+	</section>
176
+	<section>
177
+	    <title><varname>use_rpid</varname> (integer)</title>
178
+	    <para>
179
+		This parameter specifies  whether the server should fetch a value for the Remote-Party-ID header field from the database.
180
+	    </para>
181
+	    <para>
182
+		If the parameter is set to 1 the server expects to find a value for this header in the column specified by the <varname>rpid_column</varname> parameter.
183
+	    </para>
184
+	    <para>
185
+		Default value of this parameter is 0.
186
+	    </para>
187
+	    <example>
188
+		<title><varname>use_rpid</varname>usage</title>
189
+		<programlisting format="linespecific">
190
+modparam("auth_db", "use_rpid", 1)
157 191
 </programlisting>
158 192
 	    </example>
159 193
 	</section>